8079344: Allow custom or platform specific java source to automatically override shared source
Reviewed-by: ihse
--- a/make/CompileJavaModules.gmk Wed May 06 10:47:21 2015 +0200
+++ b/make/CompileJavaModules.gmk Wed May 06 11:15:27 2015 +0200
@@ -53,17 +53,7 @@
java.base_EXCLUDE_FILES += sun/text/resources/BreakIteratorRules.java
ifeq ($(OPENJDK_TARGET_OS), macosx)
- JAVA_BASE_UNIX_DIR := $(JDK_TOPDIR)/src/java.base/unix/classes
- # TODO: make JavaCompilation handle overrides automatically instead of excluding here
- # These files are overridden in macosx
- java.base_EXCLUDE_FILES += \
- $(JAVA_BASE_UNIX_DIR)/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java \
- $(JAVA_BASE_UNIX_DIR)/java/net/DefaultInterface.java \
- $(JAVA_BASE_UNIX_DIR)/java/lang/ClassLoaderHelper.java \
- $(JAVA_BASE_UNIX_DIR)/sun/nio/ch/DefaultSelectorProvider.java \
- #
- # This is just skipped on macosx
- java.base_EXCLUDE_FILES += $(JAVA_BASE_UNIX_DIR)/sun/nio/fs/GnomeFileTypeDetector.java
+ java.base_EXCLUDE_FILES += sun/nio/fs/GnomeFileTypeDetector.java
endif
ifneq ($(OPENJDK_TARGET_OS), solaris)
@@ -247,13 +237,6 @@
javax/swing/plaf/nimbus/TabbedPanePainter.java \
#
-ifeq ($(OPENJDK_TARGET_OS), macosx)
- # These files are duplicated in MACOSX_SRC_DIRS
- java.desktop_EXCLUDE_FILES += \
- $(JDK_TOPDIR)/src/java.desktop/unix/classes/sun/java2d/BackBufferCapsProvider.java \
- #
-endif
-
################################################################################
java.scripting_ADD_JAVAC_FLAGS := -Xdoclint:all/protected '-Xdoclint/package:java.*,javax.*'
@@ -418,7 +401,6 @@
endif
ifeq ($(OPENJDK_TARGET_OS),aix)
- # These files are duplicated in AIX_SRC_DIRS
jdk.sctp_EXCLUDE_FILES += $(SCTP_IMPL_CLASSES)
endif
--- a/make/common/JavaCompilation.gmk Wed May 06 10:47:21 2015 +0200
+++ b/make/common/JavaCompilation.gmk Wed May 06 11:15:27 2015 +0200
@@ -276,7 +276,7 @@
$$($1_GREP_EXCLUDE_OUTPUT)
# If the vardeps file is part of the newer prereq list, it means that
# either the jar file does not exist, or we need to recreate it from
- # from scratch anyway since a simple update will not catch all the
+ # from scratch anyway since a simple update will not catch all the
# potential changes.
$$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
$$(if $$($1_MANIFEST), \
@@ -321,8 +321,8 @@
$$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
# To allow for automatic overrides, do not create a rule for a target file that
# already has one
- ifeq ($$(findstring $$($2_TARGET), $$($1_COPY_LIST)), )
- $1_COPY_LIST += $$($2_TARGET)
+ ifneq ($$($1_COPY_$$($2_TARGET)), 1)
+ $1_COPY_$$($2_TARGET) := 1
# Now we can setup the depency that will trigger the copying.
$$($1_BIN)$$($2_TARGET) : $2
$(MKDIR) -p $$(@D)
@@ -365,7 +365,11 @@
# Remove the source prefix.
$$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
# Now we can setup the depency that will trigger the copying.
- $$($1_BIN)$$($2_TARGET) : $2
+ # To allow for automatic overrides, do not create a rule for a target file that
+ # already has one
+ ifneq ($$($1_CLEAN_$$($2_TARGET)), 1)
+ $1_CLEAN_$$($2_TARGET) := 1
+ $$($1_BIN)$$($1_MODULE_SUBDIR)$$($2_TARGET) : $2
$(MKDIR) -p $$(@D)
export LC_ALL=C ; ( $(CAT) $$< && $(ECHO) "" ) \
| $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
@@ -378,8 +382,9 @@
| $(SORT) > $$@
$(CHMOD) -f ug+w $$@
- # And do not forget this target
- $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
+ # And do not forget this target
+ $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
+ endif
endef
define remove_string
@@ -396,7 +401,8 @@
# SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
# JVM:=path to ..bin/java
# ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
-# SRC:=one or more directories to search for sources
+# SRC:=one or more directories to search for sources. The order of the source roots
+# is significant. The first found file of a certain name has priority.
# BIN:=store classes here
# INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
# EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
@@ -432,7 +438,7 @@
# Handle addons and overrides.
$1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
# Make sure the dirs exist.
- $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
+ $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory >$$d<)))
$$(call MakeDir,$$($1_BIN))
# Add all source roots to the find cache since we are likely going to run find
# on these more than once. The cache will only be updated if necessary.
@@ -450,15 +456,6 @@
$1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
endif
- # Now we have a list of all java files to compile: $$($1_SRCS)
-
- # Create the corresponding smart javac wrapper command line.
- $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \
- $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \
- $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \
- $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
- -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
-
# Prepend the source/bin path to the filter expressions.
ifneq ($$($1_INCLUDES),)
$1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
@@ -469,6 +466,25 @@
$1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
endif
+ # Remove duplicate source files by keeping the first found of each duplicate.
+ # This allows for automatic overrides with custom or platform specific versions
+ # source files.
+ #
+ # For the smart javac wrapper case, add each removed file to an extra exclude
+ # file list to prevent sjavac from finding duplicate sources.
+ $1_SRCS := $$(strip $$(foreach s, $$($1_SRCS), \
+ $$(eval relative_src := $$(call remove-prefixes, $$($1_SRC), $$(s))) \
+ $$(if $$($1_$$(relative_src)), \
+ $$(eval $1_SJAVAC_EXCLUDE_FILES += $$(s)), \
+ $$(eval $1_$$(relative_src) := 1) $$(s))))
+
+ # Create the corresponding smart javac wrapper command line.
+ $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \
+ $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \
+ $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES) $$($1_SJAVAC_EXCLUDE_FILES))) \
+ $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
+ -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
+
# All files below META-INF are always copied.
$1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
# Find all files to be copied from source to bin.
--- a/make/common/MakeBase.gmk Wed May 06 10:47:21 2015 +0200
+++ b/make/common/MakeBase.gmk Wed May 06 11:15:27 2015 +0200
@@ -45,6 +45,11 @@
# Functions
##############################
+### Debug functions
+
+# Prints the name and value of a variable
+PrintVar = \
+ $(info $(strip $1) >$($(strip $1))<)
### Functions for timers
@@ -558,6 +563,13 @@
$(and $(findstring $(strip $1),$(strip $2)),\
$(findstring $(strip $2),$(strip $1)))
+# Remove a whole list of prefixes
+# $1 - List of prefixes
+# $2 - List of elements to process
+remove-prefixes = \
+ $(strip $(if $1,$(patsubst $(firstword $1)%,%,\
+ $(call remove-prefixes,$(filter-out $(firstword $1),$1),$2)),$2))
+
################################################################################
ifneq ($(DISABLE_CACHE_FIND), true)
--- a/make/common/Modules.gmk Wed May 06 10:47:21 2015 +0200
+++ b/make/common/Modules.gmk Wed May 06 11:15:27 2015 +0200
@@ -43,7 +43,7 @@
# Find all modules with java sources by looking in the source dirs
define FindJavaModules
- $(filter-out $(JAVA_MODULES_FILTER), $(sort $(notdir \
+ $(filter-out $(MODULES_FILTER), $(sort $(notdir \
$(patsubst %/,%, $(dir $(patsubst %/,%, $(dir $(patsubst %/,%, $(dir \
$(wildcard $(patsubst %,%/*/share/classes/*, $(ALL_TOP_SRC_DIRS)) \
$(patsubst %,%/*/$(OPENJDK_TARGET_OS)/classes/*, $(ALL_TOP_SRC_DIRS)) \
@@ -52,7 +52,8 @@
# Find all modules with source for the target platform.
define FindAllModules
- $(sort $(filter-out closed demo sample, $(notdir $(patsubst %/,%, $(dir \
+ $(sort $(filter-out $(MODULES_FILTER) closed demo sample, \
+ $(notdir $(patsubst %/,%, $(dir \
$(wildcard $(patsubst %, %/*/share, $(ALL_TOP_SRC_DIRS)) \
$(patsubst %, %/*/$(OPENJDK_TARGET_OS), $(ALL_TOP_SRC_DIRS)) \
$(patsubst %, %/*/$(OPENJDK_TARGET_OS_TYPE), $(ALL_TOP_SRC_DIRS))))))))
--- a/test/make/TestJavaCompilation.gmk Wed May 06 10:47:21 2015 +0200
+++ b/test/make/TestJavaCompilation.gmk Wed May 06 11:15:27 2015 +0200
@@ -231,6 +231,117 @@
.PHONY: clean-jar3 create-jar3 update-jar3
################################################################################
+# Test SetupJavaCompilation overrides of java files
+
+$(eval $(call SetupJavaCompiler,BOOT_JAVAC, \
+ JAVAC := $(JAVAC), \
+))
+
+JAVA_SRC_ROOT1 := $(OUTPUT_DIR)/javaroot1
+JAVA_SRC_ROOT2 := $(OUTPUT_DIR)/javaroot2
+
+# Since this makefile calls itself a number of times, protect this macro from
+# being executed more than once.
+# Param 1 - File name
+# Param 2 - Package name
+# Param 3 - Class name
+# Param 4 - Message
+CreateJavaSrc = \
+ $(if $(wildcard $1),,$(shell \
+ $(MKDIR) -p $(dir $1); \
+ $(ECHO) "package $2;" > $1; \
+ $(ECHO) "public class $3 {" >> $1; \
+ $(ECHO) " public static void main(String[] args) {" >> $1; \
+ $(ECHO) " System.out.print(\"$4\");" >> $1; \
+ $(ECHO) " }" >> $1; \
+ $(ECHO) "}" >> $1; \
+ ))
+
+# Since this makefile calls itself a number of times, protect this macro from
+# being executed more than once.
+# Param 1 - File name
+# Param 2 - Message
+CreateTextFile = \
+ $(if $(wildcard $1),,$(shell \
+ $(MKDIR) -p $(dir $1); \
+ $(PRINTF) '$2' > $1; \
+ ))
+
+$(call CreateJavaSrc,$(JAVA_SRC_ROOT1)/a/A.java,a,A,javaroot1)
+$(call CreateJavaSrc,$(JAVA_SRC_ROOT2)/a/A.java,a,A,javaroot2)
+$(call CreateTextFile,$(JAVA_SRC_ROOT1)/a/b.txt,javaroot1\n)
+$(call CreateTextFile,$(JAVA_SRC_ROOT2)/a/b.txt,javaroot2\n)
+$(call CreateTextFile,$(JAVA_SRC_ROOT1)/a/c.properties,#javaroot1\nname=value1\n)
+$(call CreateTextFile,$(JAVA_SRC_ROOT2)/a/c.properties,#javaroot2\nname=value2\n)
+
+# Due to a bug in gnu make 3.81, need to add the src roots with trailing slash,
+# otherwise $(wildcard ) will not find the directories and the sanity check in
+# SetupJavaCompilation will fail.
+$(eval $(call SetupJavaCompilation, BUILD_ROOT1_FIRST, \
+ SETUP := BOOT_JAVAC, \
+ SRC := $(JAVA_SRC_ROOT1)/ $(JAVA_SRC_ROOT2)/, \
+ COPY := .txt .java, \
+ CLEAN := .properties, \
+ BIN := $(OUTPUT_DIR)/root1first/, \
+))
+
+$(BUILD_ROOT1_FIRST):
+
+verify-root1-first: $(BUILD_ROOT1_FIRST)
+ $(JAVA_SMALL) -cp $(OUTPUT_DIR)/root1first a.A > $(OUTPUT_DIR)/root1first.output
+ if [ "`$(CAT) $(OUTPUT_DIR)/root1first.output`" != "javaroot1" ]; then \
+ $(ECHO) "The wrong class was compiled. Expected >javaroot1<"; \
+ $(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root1first.output`<"; \
+ false; \
+ fi
+ if [ "`$(CAT) $(OUTPUT_DIR)/root1first/a/b.txt`" != "javaroot1" ]; then \
+ $(ECHO) "The wrong file was copied. Expected >javaroot1<"; \
+ $(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root1first/a/b.txt`<"; \
+ false; \
+ fi
+ if [ ! -e "$(OUTPUT_DIR)/root1first/a/A.java" ]; then \
+ $(ECHO) "Missed copying $(OUTPUT_DIR)/root1first/a/A.java"; \
+ false; \
+ fi
+ if [ "`$(CAT) $(OUTPUT_DIR)/root1first/a/c.properties`" != "name=value1" ]; then \
+ $(ECHO) "The wrong file was cleaned. Expected >name=value1<"; \
+ $(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root1first/a/c.properties`<"; \
+ false; \
+ fi
+
+$(eval $(call SetupJavaCompilation, BUILD_ROOT2_FIRST, \
+ SETUP := BOOT_JAVAC, \
+ SRC := $(JAVA_SRC_ROOT2)/ $(JAVA_SRC_ROOT1)/, \
+ COPY := .txt, \
+ CLEAN := .properties, \
+ BIN := $(OUTPUT_DIR)/root2first/, \
+))
+
+$(BUILD_ROOT2_FIRST):
+
+verify-root2-first: $(BUILD_ROOT2_FIRST)
+ $(JAVA_SMALL) -cp $(OUTPUT_DIR)/root2first a.A > $(OUTPUT_DIR)/root2first.output
+ if [ "`$(CAT) $(OUTPUT_DIR)/root2first.output`" != "javaroot2" ]; then \
+ $(ECHO) "The wrong class was compiled. Expected >javaroot2<"; \
+ $(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root2first.output`<"; \
+ false; \
+ fi
+ if [ "`$(CAT) $(OUTPUT_DIR)/root2first/a/b.txt`" != "javaroot2" ]; then \
+ $(ECHO) "The wrong file was cleaned. Expected >javaroot2<"; \
+ $(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root2first/a/b.txt`<"; \
+ false; \
+ fi
+ if [ "`$(CAT) $(OUTPUT_DIR)/root2first/a/c.properties`" != "name=value2" ]; then \
+ $(ECHO) "The wrong file was cleaned. Expected >name=value2<"; \
+ $(ECHO) "Got >`$(CAT) $(OUTPUT_DIR)/root2first/a/c.properties`<"; \
+ false; \
+ fi
+
+TEST_TARGETS += verify-root1-first verify-root2-first
+
+.PHONY: verify-root1-first verify-root2-first
+
+################################################################################
all: $(TEST_TARGETS)
--- a/test/make/TestMakeBase.gmk Wed May 06 10:47:21 2015 +0200
+++ b/test/make/TestMakeBase.gmk Wed May 06 11:15:27 2015 +0200
@@ -33,6 +33,16 @@
$(SRC_ROOT)/make/common/MakeBase.gmk \
#
+# Assert two strings are equal
+# 1 - Tested value
+# 2 - Exepected value
+# 3 - Error message
+define assert-equals
+ ifneq ($$(strip $1),$$(strip $2))
+ $$(error $3 - Expected >$$(strip $2)< - Got >$$(strip $1)<)
+ endif
+endef
+
# On macosx, file system timestamps only have 1 second resultion so must add
# sleeps to properly test dependencies.
ifeq ($(OPENJDK_BUILD_OS), macosx)
@@ -77,6 +87,17 @@
endif
################################################################################
+# Test remove-prefixes
+
+$(eval $(call assert-equals, \
+ $(call remove-prefixes, pre, prefix postfix), fix postfix, \
+ Prefixes not properly removed))
+
+$(eval $(call assert-equals, \
+ $(call remove-prefixes, pre post, prefix postfix), fix fix, \
+ Prefixes not properly removed))
+
+################################################################################
# Test ShellQuote
SHELL_QUOTE_VALUE := foo '""' "''" bar