# HG changeset patch # User erikj # Date 1422264533 -3600 # Node ID 09dd1740f176e89574b55ef62efe87b355767386 # Parent b2f9702efbe95527ea3a991474fda23987ff1c5c 8069261: Create make dependencies on make variable values Reviewed-by: ihse diff -r b2f9702efbe9 -r 09dd1740f176 common/autoconf/spec.gmk.in --- a/common/autoconf/spec.gmk.in Wed Jul 05 20:16:23 2017 +0200 +++ b/common/autoconf/spec.gmk.in Mon Jan 26 10:28:53 2015 +0100 @@ -243,7 +243,7 @@ HOTSPOT_OUTPUTDIR=$(BUILD_OUTPUT)/hotspot JDK_OUTPUTDIR=$(BUILD_OUTPUT)/jdk IMAGES_OUTPUTDIR=$(BUILD_OUTPUT)/images -TESTMAKE_OUTPUTDIR=$(BUILD_OUTPUT)/testmake +TESTMAKE_OUTPUTDIR=$(BUILD_OUTPUT)/test-make MAKESUPPORT_OUTPUTDIR=$(BUILD_OUTPUT)/make-support HOTSPOT_DIST=@HOTSPOT_DIST@ diff -r b2f9702efbe9 -r 09dd1740f176 make/Images.gmk --- a/make/Images.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/Images.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -111,14 +111,16 @@ # Use this file inside the image as target for make rule JIMAGE_TARGET_FILE := bin/java$(EXE_SUFFIX) -$(JDK_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) +$(JDK_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) \ + $(call DependOnVariable, JDK_MODULES_LIST) $(ECHO) Creating jdk jimage $(RM) -r $(JDK_IMAGE_DIR) $(JDK_SORTED_MODULES) $(JIMAGE_TOOL) --mods $(JDK_MODULES_LIST) --output $(JDK_IMAGE_DIR) \ $(MODULES_XML) > $(JDK_SORTED_MODULES) $(TOUCH) $@ -$(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) +$(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) \ + $(call DependOnVariable, JRE_MODULES_LIST) $(ECHO) Creating jre jimage $(RM) -r $(JRE_IMAGE_DIR) $(JRE_SORTED_MODULES) $(JIMAGE_TOOL) --mods $(JRE_MODULES_LIST) --output $(JRE_IMAGE_DIR) \ @@ -131,7 +133,8 @@ COMPACT_EXTRA_MODULES := jdk.localedata jdk.crypto.pkcs11 jdk.crypto.ec -$(JRE_COMPACT1_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) +$(JRE_COMPACT1_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) \ + $(call DependOnVariable, JRE_COMPACT1_MODULES_LIST) $(ECHO) Creating jre compact1 jimage $(RM) -r $(JRE_COMPACT1_IMAGE_DIR) $(JRE_COMPACT1_SORTED_MODULES) $(JIMAGE_TOOL) \ @@ -140,7 +143,8 @@ $(MODULES_XML) > $(JRE_COMPACT1_SORTED_MODULES) $(TOUCH) $@ -$(JRE_COMPACT2_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) +$(JRE_COMPACT2_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) \ + $(call DependOnVariable, JRE_COMPACT2_MODULES_LIST) $(ECHO) Creating jre compact2 jimage $(RM) -r $(JRE_COMPACT2_IMAGE_DIR) $(JRE_COMPACT2_SORTED_MODULES) $(JIMAGE_TOOL) \ @@ -149,7 +153,8 @@ $(MODULES_XML) > $(JRE_COMPACT2_SORTED_MODULES) $(TOUCH) $@ -$(JRE_COMPACT3_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) +$(JRE_COMPACT3_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(DEPENDENCIES) \ + $(call DependOnVariable, JRE_COMPACT3_MODULES_LIST) $(ECHO) Creating jre compact3 jimage $(RM) -r $(JRE_COMPACT3_IMAGE_DIR) $(JRE_COMPACT3_SORTED_MODULES) $(JIMAGE_TOOL) \ @@ -368,45 +373,59 @@ # Common way to emit a line into the release or info file define info-file-item # name value - $(PRINTF) '%s="%s"\n' $1 $2 >> $@ + $(PRINTF) '%s="%s"\n' $1 $2 >> $@ endef # Param 1 - The file containing the MODULES list define create-info-file - $(ECHO) $(LOG_INFO) Generating $(patsubst $(OUTPUT_ROOT)/%,%,$@) - $(MKDIR) -p $(@D) - $(RM) $@ - $(call info-file-item, "JAVA_VERSION", "$(JDK_VERSION)") - $(call info-file-item, "OS_NAME", "$(REQUIRED_OS_NAME)") - $(call info-file-item, "OS_VERSION", "$(REQUIRED_OS_VERSION)") - $(call info-file-item, "OS_ARCH", "$(OPENJDK_TARGET_CPU_LEGACY)") - $(if $(JDK_ARCH_ABI_PROP_NAME), \ - $(call info-file-item, "SUN_ARCH_ABI", "$(JDK_ARCH_ABI_PROP_NAME)")) - $(call info-file-item, "SOURCE", "$(ALL_SOURCE_TIPS)") - $(call info-file-item, "MODULES", "`$(CAT) $1`") + $(call info-file-item, "JAVA_VERSION", "$(JDK_VERSION)") + $(call info-file-item, "OS_NAME", "$(REQUIRED_OS_NAME)") + $(call info-file-item, "OS_VERSION", "$(REQUIRED_OS_VERSION)") + $(call info-file-item, "OS_ARCH", "$(OPENJDK_TARGET_CPU_LEGACY)") + $(if $(JDK_ARCH_ABI_PROP_NAME), \ + $(call info-file-item, "SUN_ARCH_ABI", "$(JDK_ARCH_ABI_PROP_NAME)")) + $(call info-file-item, "SOURCE", "$(ALL_SOURCE_TIPS)") + $(call info-file-item, "MODULES", "`$(CAT) $1`") endef +# Param 1 - The file containing the MODULES list +define prepare-info-file + $(ECHO) $(LOG_INFO) Generating $(patsubst $(OUTPUT_ROOT)/%,%,$@) + $(MKDIR) -p $(@D) + $(RM) $@ +endef + +define info-file + $(call prepare-info-file, $1) + $(call create-info-file, $1) +endef + +# Create a variable dependency file common for all release info files. The +# sorted module list will only change if the image is regenerated, which will +# trigger a rebuild of these files anyway. +INFO_FILE_VARDEPS := $(call DependOnVariable, create-info-file) + ALL_SOURCE_TIPS = $(shell \ if [ -f $(SUPPORT_OUTPUTDIR)/source_tips ] ; then \ $(CAT) $(SUPPORT_OUTPUTDIR)/source_tips ; \ fi) -$(JRE_INFO_FILE): $(OUTPUT_ROOT)/spec.gmk $(SUPPORT_OUTPUTDIR)/source_tips - $(call create-info-file, $(JRE_SORTED_MODULES)) +$(JRE_INFO_FILE): $(INFO_FILE_VARDEPS) $(SUPPORT_OUTPUTDIR)/source_tips + $(call info-file, $(JRE_SORTED_MODULES)) -$(JDK_INFO_FILE): $(OUTPUT_ROOT)/spec.gmk $(SUPPORT_OUTPUTDIR)/source_tips - $(call create-info-file, $(JDK_SORTED_MODULES)) +$(JDK_INFO_FILE): $(INFO_FILE_VARDEPS) $(SUPPORT_OUTPUTDIR)/source_tips + $(call info-file, $(JDK_SORTED_MODULES)) -$(JRE_COMPACT1_INFO_FILE): $(OUTPUT_ROOT)/spec.gmk $(SUPPORT_OUTPUTDIR)/source_tips - $(call create-info-file, $(JRE_COMPACT1_SORTED_MODULES)) +$(JRE_COMPACT1_INFO_FILE): $(INFO_FILE_VARDEPS) $(SUPPORT_OUTPUTDIR)/source_tips + $(call info-file, $(JRE_COMPACT1_SORTED_MODULES)) $(call info-file-item, "JAVA_PROFILE", "compact1") -$(JRE_COMPACT2_INFO_FILE): $(OUTPUT_ROOT)/spec.gmk $(SUPPORT_OUTPUTDIR)/source_tips - $(call create-info-file, $(JRE_COMPACT2_SORTED_MODULES)) +$(JRE_COMPACT2_INFO_FILE): $(INFO_FILE_VARDEPS) $(SUPPORT_OUTPUTDIR)/source_tips + $(call info-file, $(JRE_COMPACT2_SORTED_MODULES)) $(call info-file-item, "JAVA_PROFILE", "compact2") -$(JRE_COMPACT3_INFO_FILE): $(OUTPUT_ROOT)/spec.gmk $(SUPPORT_OUTPUTDIR)/source_tips - $(call create-info-file, $(JRE_COMPACT3_SORTED_MODULES)) +$(JRE_COMPACT3_INFO_FILE): $(INFO_FILE_VARDEPS) $(SUPPORT_OUTPUTDIR)/source_tips + $(call info-file, $(JRE_COMPACT3_SORTED_MODULES)) $(call info-file-item, "JAVA_PROFILE", "compact3") JRE_TARGETS += $(JRE_INFO_FILE) diff -r b2f9702efbe9 -r 09dd1740f176 make/Main.gmk --- a/make/Main.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/Main.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -402,6 +402,8 @@ verify-modules: exploded-image + test-make: clean-test-make + endif ################################################################################ @@ -477,7 +479,7 @@ # file. CLEAN_DIRS += hotspot jdk bootcycle-build test buildtools support \ - images make-support + images make-support test-make CLEAN_DIR_TARGETS := $(addprefix clean-, $(CLEAN_DIRS)) CLEAN_PHASES := gensrc java native include CLEAN_PHASE_TARGETS := $(addprefix clean-, $(CLEAN_PHASES)) diff -r b2f9702efbe9 -r 09dd1740f176 make/ZipSource.gmk --- a/make/ZipSource.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/ZipSource.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -71,7 +71,7 @@ $(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_API_DIR)/native/libjli/java_md*))) # This dir needs to exist before macro is evaluated to avoid warning from find. -$(eval $(call MakeDir, $(SUPPORT_OUTPUTDIR)/src)) +$(call MakeDir, $(SUPPORT_OUTPUTDIR)/src) $(eval $(call SetupZipArchive,BUILD_SRC_ZIP, \ SRC := $(SRC_ZIP_SRCS) $(SUPPORT_OUTPUTDIR)/src, \ INCLUDES := $(SRC_ZIP_INCLUDES) launcher, \ diff -r b2f9702efbe9 -r 09dd1740f176 make/common/IdlCompilation.gmk --- a/make/common/IdlCompilation.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/common/IdlCompilation.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -99,7 +99,7 @@ $(if $(16),$(error Internal makefile error: Too many arguments to SetupIdlCompilation, please update IdlCompilation.gmk)) # Find all existing java files and existing class files. - $$(eval $$(call MakeDir,$$($1_BIN))) + $$(call MakeDir,$$($1_BIN)) $1_SRCS := $$(shell find $$($1_SRC) -name "*.idl") $1_BINS := $$(shell find $$($1_BIN) -name "*.java") # Prepend the source/bin path to the filter expressions. diff -r b2f9702efbe9 -r 09dd1740f176 make/common/JavaCompilation.gmk --- a/make/common/JavaCompilation.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/common/JavaCompilation.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -270,19 +270,37 @@ $1_JAR_UPDATE_OPTIONS := uf endif + # Include all variables of significance in the vardeps file + $1_VARDEPS := $(JAR) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) $(RELEASE) $(COMPANY_NAME) \ + $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR) + $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps) + # Here is the rule that creates/updates the jar file. - $$($1_JAR) : $$($1_DEPS) + $$($1_JAR) : $$($1_DEPS) $$($1_MANIFEST) $$($1_VARDEPS_FILE) $(MKDIR) -p $$($1_BIN) $$($1_GREP_INCLUDE_OUTPUT) $$($1_GREP_EXCLUDE_OUTPUT) - $$(if $$($1_MANIFEST), \ - $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ - -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \ + # 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 + # potential changes. + $$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \ + $$(if $$($1_MANIFEST), \ + $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ + -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) $$(NEWLINE) \ + , \ + $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \ + $$(if $$($1_JARMAIN), \ + $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \ + $$(if $$($1_EXTRA_MANIFEST_ATTR), \ + $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \ + $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \ + $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ + $$($1_SCAPTURE_CONTENTS) \ + $$($1_SCAPTURE_METAINF) \ + $$($1_SUPDATE_CONTENTS) \ + $$($1_JARINDEX) && true \ , \ - $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE)) - $$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE)) - $$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE)) - $$(if $$(wildcard $$@), \ $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \ $$($1_CAPTURE_CONTENTS) \ $$($1_CAPTURE_METAINF) \ @@ -294,12 +312,6 @@ $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ fi $$(NEWLINE) \ $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \ - $$($1_JARINDEX) && true \ - , \ - $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ - $$($1_SCAPTURE_CONTENTS) \ - $$($1_SCAPTURE_METAINF) \ - $$($1_SUPDATE_CONTENTS) \ $$($1_JARINDEX) && true ) # Add jar to target list @@ -431,7 +443,7 @@ $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))) - $$(eval $$(call MakeDir,$$($1_BIN))) + $$(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. $$(eval $$(call FillCacheFind,$$($1_SRC))) @@ -535,9 +547,14 @@ $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC)) # Set the $1_REMOTE to spawn a background javac server. - $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC)))) + $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst \ + $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC)))) - $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) + $1_VARDEPS := $$($1_JVM) $$($1_SJAVAC) $$($1_SJAVAC_ARGS) $$($1_FLAGS) \ + $$($1_HEADERS_ARG) $$($1_BIN) + $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps) + + $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE) $(MKDIR) -p $$(@D) $$(dir $$($1_SJAVAC_PORTFILE)) # As a workaround for sjavac not tracking api changed from the classpath, force full # recompile if an external dependency, which is something other than a source @@ -592,8 +609,11 @@ $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers endif + $1_VARDEPS := $$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) $$($1_BIN) $$($1_HEADERS_ARG) + $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps) + # When not using sjavac, pass along all sources to javac using an @file. - $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) + $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE) $(MKDIR) -p $$(@D) $(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp) @@ -659,4 +679,5 @@ $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \ $(strip $2)/_the.$(strip $1)_batch) endef -endif + +endif # _JAVA_COMPILATION_GMK diff -r b2f9702efbe9 -r 09dd1740f176 make/common/MakeBase.gmk --- a/make/common/MakeBase.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/common/MakeBase.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -392,11 +392,9 @@ endef # Make directory without forking mkdir if not needed -define MakeDir - ifneq ($$(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),$$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)) - $$(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9) - endif -endef +MakeDir = \ + $(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\ + $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9))) ifeq ($(OPENJDK_TARGET_OS),solaris) # On Solaris, if the target is a symlink and exists, cp won't overwrite. @@ -446,6 +444,9 @@ # Filter out duplicate sub strings while preserving order. Keeps the first occurance. uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) +# String equals +equals = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))) + ifneq ($(DISABLE_CACHE_FIND), true) ################################################################################ # In Cygwin, finds are very costly, both because of expensive forks and because @@ -543,6 +544,80 @@ endef ################################################################################ +# ShellQuote +# +# Quotes a string with single quotes and replaces single quotes with '\'' so +# that the contents survives being given to the shell. + +ShellQuote = \ + $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE) + +################################################################################ +# Write to and read from file + +# Param 1 - File to read +ReadFile = \ + $(shell $(CAT) $1) + +# Param 1 - Text to write +# Param 2 - File to write to +# Use printf to get consistent behavior on all platforms. +WriteFile = \ + $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2) + +################################################################################ +# DependOnVariable +# +# This macro takes a variable name and puts the value in a file only if the +# value has changed since last. The name of the file is returned. This can be +# used to create rule dependencies on make variable values. The following +# example would get rebuilt if the value of SOME_VAR was changed: +# +# path/to/some-file: $(call DependOnVariable, SOME_VAR) +# echo $(SOME_VAR) > $@ +# +# Note that leading and trailing white space in the value is ignored. +# + +# Defines the sub directory structure to store variable value file in +DependOnVariableDirName = \ + $(strip $(subst $(SRC_ROOT)/,,\ + $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \ + $(firstword $(MAKEFILE_LIST)), \ + $(CURDIR)/$(firstword $(MAKEFILE_LIST))))) + +# Defines the name of the file to store variable value in. Generates a name +# unless parameter 2 is given. +# Param 1 - Name of variable +# Param 2 - (optional) name of file to store value in +DependOnVariableFileName = \ + $(strip $(if $(strip $2), $2, \ + $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps)) + +# Does the actual work with parameters stripped. +# If the file exists AND the contents is the same as the variable, do nothing +# else print a new file. +# Always returns the name of the file where the value was printed. +# Param 1 - Name of variable +# Param 2 - (optional) name of file to store value in +DependOnVariableHelper = \ + $(strip $(if $(and $(wildcard $(call DependOnVariableFileName, $1, $2)),\ + $(call equals, $(strip $($1)), \ + $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))),,\ + $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \ + $(if $(findstring $(LOG_LEVEL), trace), \ + $(info Variable $1: $(strip $($1))) \ + $(info File: $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))) \ + $(call WriteFile, $($1), $(call DependOnVariableFileName, $1, $2))) \ + $(call DependOnVariableFileName, $1, $2)) + +# Main macro +# Param 1 - Name of variable +# Param 2 - (optional) name of file to store value in +DependOnVariable = \ + $(call DependOnVariableHelper,$(strip $1),$(strip $2)) + +################################################################################ # Hook to include the corresponding custom file, if present. $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk)) diff -r b2f9702efbe9 -r 09dd1740f176 make/common/NativeCompilation.gmk --- a/make/common/NativeCompilation.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/common/NativeCompilation.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -114,7 +114,7 @@ endif endif - $$($1_$2_OBJ) : $2 | $$($1_BUILD_INFO) + $$($1_$2_OBJ) : $2 $$($1_COMPILE_VARDEPS_FILE) | $$($1_BUILD_INFO) $(ECHO) $(LOG_INFO) "Compiling $$(notdir $2) (for $$(notdir $$($1_TARGET)))" ifneq ($(TOOLCHAIN_TYPE), microsoft) # The Solaris studio compiler doesn't output the full path to the object file in the @@ -306,7 +306,7 @@ endif # Make sure the dirs exist. - $$(eval $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR))) + $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)) $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d))) # Find all files in the source trees. Sort to remove duplicates. @@ -426,15 +426,16 @@ $1_BUILD_INFO := $$($1_OBJECT_DIR)/_build-info.marker - # Setup rule for printing progress info when compiling source files. - # This is a rough heuristic and may not always print accurate information. - $$($1_BUILD_INFO): $$($1_SRCS) - ifeq ($$(wildcard $$($1_TARGET)),) - $(ECHO) 'Creating $$($1_BASENAME) from $$(words $$?) file(s)' - else - $(ECHO) 'Updating $$($1_BASENAME) from $$(words $$?) file(s)' - endif - $(TOUCH) $$@ + # Track variable changes for all variables that affect the compilation command + # lines for all object files in this setup. This includes at least all the + # variables used in the call to add_native_source below. + $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $(SYSROOT_CFLAGS) \ + $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) \ + $$($1_CC) $$($1_CXX) $$($1_OBJC) $$($1_ASFLAGS) \ + $$(foreach s, $$($1_SRCS), \ + $$($1_$$(notdir $$s)_CFLAGS) $$($1_$$(notdir $$s)_CXXFLAGS)) + $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \ + $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps) # Now call add_native_source for each source file we are going to compile. $$(foreach p,$$($1_SRCS), \ @@ -444,13 +445,28 @@ $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $(SYSROOT_CFLAGS), \ $$($1_CXX),$$($1_OBJC),$$($1_ASFLAGS)))) + # Setup rule for printing progress info when compiling source files. + # This is a rough heuristic and may not always print accurate information. + $$($1_BUILD_INFO): $$($1_SRCS) $$($1_COMPILE_VARDEPS_FILE) + ifeq ($$(wildcard $$($1_TARGET)),) + $(ECHO) 'Creating $$($1_BASENAME) from $$(words $$(filter-out %.vardeps, $$?)) file(s)' + else + $(ECHO) 'Updating $$($1_BASENAME) from $$(words $$(filter-out %.vardeps, $$?)) file(s)' + endif + $(TOUCH) $$@ + # On windows we need to create a resource file ifeq ($(OPENJDK_TARGET_OS), windows) ifneq (,$$($1_VERSIONINFO_RESOURCE)) $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res $1_RES_DEP:=$$($1_RES).d -include $$($1_RES_DEP) - $$($1_RES): $$($1_VERSIONINFO_RESOURCE) + + $1_RES_VARDEPS := $(RC) $$($1_RC_FLAGS) + $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \ + $$($1_RES).vardeps) + + $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE) $(ECHO) $(LOG_INFO) "Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET)))" $(RC) $$($1_RC_FLAGS) $(CC_OUT_OPTION)$$@ $$($1_VERSIONINFO_RESOURCE) # Windows RC compiler does not support -showIncludes, so we mis-use CL for this. @@ -462,7 +478,9 @@ ifneq (,$$($1_MANIFEST)) $1_GEN_MANIFEST:=$$($1_OBJECT_DIR)/$$($1_PROGRAM).manifest IMVERSIONVALUE:=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VERSION).$(COOKED_BUILD_NUMBER) - $$($1_GEN_MANIFEST): $$($1_MANIFEST) + $1_MANIFEST_VARDEPS_FILE := $$(call DependOnVariable, IMVERSIONVALUE, \ + $$($1_GEN_MANIFEST).vardeps) + $$($1_GEN_MANIFEST): $$($1_MANIFEST) $$($1_MANIFEST_VARDEPS_FILE) $(SED) 's%IMVERSION%$$(IMVERSIONVALUE)%g;s%PROGRAM%$$($1_PROGRAM)%g' $$< > $$@ endif endif @@ -575,8 +593,13 @@ $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX) + $1_VARDEPS := $$($1_LD) $(SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \ + $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) + $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ + $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) + $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) \ - $$($1_DEBUGINFO_EXTRA_DEPS) + $$($1_DEBUGINFO_EXTRA_DEPS) $$($1_VARDEPS_FILE) $(ECHO) $(LOG_INFO) "Linking $$($1_BASENAME)" $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(SYSROOT_LDFLAGS) \ $(LD_OUT_OPTION)$$@ \ @@ -592,8 +615,12 @@ endif ifneq (,$$($1_STATIC_LIBRARY)) + $1_VARDEPS := $(AR) $$($1_ARFLAGS) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) + $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ + $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) + # Generating a static library, ie object file archive. - $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) + $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $(ECHO) $(LOG_INFO) "Archiving $$($1_STATIC_LIBRARY)" $(AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \ $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) @@ -603,8 +630,13 @@ # A executable binary has been specified, setup the target for it. $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX) + $1_VARDEPS := $$($1_LDEXE) $(SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \ + $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) + $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ + $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) + $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_GEN_MANIFEST) \ - $$($1_DEBUGINFO_EXTRA_DEPS) + $$($1_DEBUGINFO_EXTRA_DEPS) $$($1_VARDEPS_FILE) $(ECHO) $(LOG_INFO) "Linking executable $$($1_BASENAME)" $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(SYSROOT_LDFLAGS) \ $(EXE_OUT_OPTION)$$($1_TARGET) \ diff -r b2f9702efbe9 -r 09dd1740f176 make/common/TextFileProcessing.gmk --- a/make/common/TextFileProcessing.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/make/common/TextFileProcessing.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -34,7 +34,7 @@ # param 3 = the target base directory # param 4 = the target file name (possibly with a partial path) define SetupSingleTextFileForProcessing - $(strip $3)/$(strip $4): $2 + $(strip $3)/$(strip $4): $2 $$($1_VARDEPS_FILE) $(ECHO) $(LOG_INFO) "Processing $(strip $4)" $(MKDIR) -p '$$(@D)' $(RM) '$$@' '$$@.includes.tmp' '$$@.replacements.tmp' @@ -193,6 +193,9 @@ $1_INCLUDES_COMMAND_LINE := $(CAT) endif + $1_VARDEPS := $$($1_INCLUDES_COMMAND_LINE) $$($1_REPLACEMENTS_COMMAND_LINE) + $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS) + # Reset target list before populating it $1 := diff -r b2f9702efbe9 -r 09dd1740f176 test/make/TestJavaCompilation.gmk --- a/test/make/TestJavaCompilation.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/test/make/TestJavaCompilation.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -50,6 +50,9 @@ clean-jar1: $(RM) -r $(OUTPUT_DIR)/_jar1* $(OUTPUT_DIR)/jar1* +$(JAR1_MANIFEST): | $(OUTPUT_DIR)/_jar1_created + $(ECHO) "Test-Attribute: value" > $(JAR1_MANIFEST) + $(OUTPUT_DIR)/_jar1_created: $(DEPS) $(RM) -r $(JAR1_SRC_ROOT) $(RM) $(JAR1_FILE) @@ -61,7 +64,6 @@ $(TOUCH) $(JAR1_SRC_ROOT)/dir1/file1.class $(TOUCH) $(JAR1_SRC_ROOT)/dir2/file2.class $(TOUCH) $(JAR1_SRC_ROOT)/META-INF/metafile - $(ECHO) "Test-Attribute: value" > $(JAR1_MANIFEST) $(TOUCH) $@ $(eval $(call SetupArchive,BUILD_JAR1, \ @@ -77,7 +79,7 @@ $(DIFF) -r $(JAR1_SRC_ROOT)/dir1 $(JAR1_UNZIP)/dir1 $(DIFF) -r $(JAR1_SRC_ROOT)/dir2 $(JAR1_UNZIP)/dir2 $(DIFF) -r $(JAR1_SRC_ROOT)/META-INF/metafile $(JAR1_UNZIP)/META-INF/metafile - if [ "`$(GREP) 'Test-Attribute: value' $(JAR1_MANIFEST)`" = "" ]; then \ + if [ "`$(GREP) 'Test-Attribute: value' $(JAR1_UNZIP)/META-INF/MANIFEST.MF`" = "" ]; then \ $(ECHO) "Could not find Test-Attribute in manifest of $(JAR1_FILE)"; \ exit 1; \ fi @@ -88,7 +90,7 @@ # Change a source file and call this makefile again to force the jar to be # updated. -$(OUTPUT_DIR)_jar1_updated: $(OUTPUT_DIR)/_jar1_verified +$(OUTPUT_DIR)/_jar1_updated: $(OUTPUT_DIR)/_jar1_verified $(ECHO) updated > $(JAR1_SRC_ROOT)/dir1/file1.class $(ECHO) updated > $(JAR1_SRC_ROOT)/META-INF/metafile $(TOUCH) $(OUTPUT_DIR)/_jar1_created @@ -96,9 +98,26 @@ $(TOUCH) $@ update-jar1: $(OUTPUT_DIR)_jar1_updated -TEST_TARGETS += $(OUTPUT_DIR)_jar1_updated -.PHONY: clean-jar1 create-jar1 update-jar1 +# Change the manifest file and call this makefile again to force the jar +# to be updated +$(OUTPUT_DIR)/_jar1_updated_manifest: $(OUTPUT_DIR)/_jar1_updated + $(ECHO) "Test-Attribute: foobar" > $(JAR1_MANIFEST) + +$(MAKE) -f $(THIS_FILE) $(BUILD_JAR1) + $(RM) -r $(JAR1_UNZIP) + $(MKDIR) -p $(JAR1_UNZIP) + $(CD) $(JAR1_UNZIP) && $(UNZIP) $(JAR1_FILE) $(LOG_DEBUG) + if [ "`$(GREP) 'Test-Attribute: foobar' $(JAR1_UNZIP)/META-INF/MANIFEST.MF`" = "" ]; then \ + $(ECHO) "Could not find Test-Attribute in manifest of $(JAR1_FILE)"; \ + exit 1; \ + fi + $(TOUCH) $@ + +update-jar1-manifest: $(OUTPUT_DIR)/_jar1_updated_manifest + +TEST_TARGETS += $(OUTPUT_DIR)/_jar1_updated $(OUTPUT_DIR)/_jar1_updated_manifest + +.PHONY: clean-jar1 create-jar1 update-jar1 update-jar1-manifest ################################################################################ # Test: jar2 @@ -139,14 +158,14 @@ create-jar2: $(OUTPUT_DIR)/_jar2_verified TEST_TARGETS += $(OUTPUT_DIR)/_jar2_verified -$(OUTPUT_DIR)_jar2_updated: $(OUTPUT_DIR)/_jar2_verified +$(OUTPUT_DIR)/_jar2_updated: $(OUTPUT_DIR)/_jar2_verified $(ECHO) updated > $(JAR2_SRC_ROOT1)/dir1/file1.class $(TOUCH) $(OUTPUT_DIR)/_jar2_created +$(MAKE) -f $(THIS_FILE) $(OUTPUT_DIR)/_jar2_verified $(TOUCH) $@ -update-jar2: $(OUTPUT_DIR)_jar2_updated -TEST_TARGETS += $(OUTPUT_DIR)_jar2_updated +update-jar2: $(OUTPUT_DIR)/_jar2_updated +TEST_TARGETS += $(OUTPUT_DIR)/_jar2_updated .PHONY: clean-jar2 create-jar2 update-jar2 @@ -200,14 +219,14 @@ create-jar3: $(OUTPUT_DIR)/_jar3_verified TEST_TARGETS += $(OUTPUT_DIR)/_jar3_verified -$(OUTPUT_DIR)_jar3_updated: $(OUTPUT_DIR)/_jar3_verified +$(OUTPUT_DIR)/_jar3_updated: $(OUTPUT_DIR)/_jar3_verified $(ECHO) updated > $(JAR3_SRC_ROOT2)/extra-file $(TOUCH) $(OUTPUT_DIR)/_jar3_created +$(MAKE) -f $(THIS_FILE) $(OUTPUT_DIR)/_jar3_verified $(TOUCH) $@ -update-jar3: $(OUTPUT_DIR)_jar3_updated -TEST_TARGETS += $(OUTPUT_DIR)_jar3_updated +update-jar3: $(OUTPUT_DIR)/_jar3_updated +TEST_TARGETS += $(OUTPUT_DIR)/_jar3_updated .PHONY: clean-jar3 create-jar3 update-jar3 diff -r b2f9702efbe9 -r 09dd1740f176 test/make/TestMakeBase.gmk --- a/test/make/TestMakeBase.gmk Wed Jul 05 20:16:23 2017 +0200 +++ b/test/make/TestMakeBase.gmk Mon Jan 26 10:28:53 2015 +0100 @@ -33,7 +33,14 @@ $(SRC_ROOT)/make/common/MakeBase.gmk \ # +# On macosx, file system timestamps only have 1 second resultion so must add +# sleeps to properly test dependencies. +ifeq ($(OPENJDK_BUILD_OS), macosx) + SLEEP_ON_MAC := sleep 1 +endif + OUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/make-base +$(call MakeDir, $(OUTPUT_DIR)) ################################################################################ # Escape $ @@ -56,5 +63,110 @@ TEST_TARGETS += $(ESCAPE_DOLLAR_DIR)/_escape_dollar ################################################################################ +# Test ShellQuote + +SHELL_QUOTE_VALUE := foo '""' "''" bar +SHELL_QUOTE_RESULT := $(shell $(ECHO) $(call ShellQuote, \ + $(SHELL_QUOTE_VALUE))) + +ifneq ($(SHELL_QUOTE_VALUE), $(SHELL_QUOTE_RESULT)) + $(error Expected: >$(SHELL_QUOTE_VALUE)< - Result: >$(SHELL_QUOTE_RESULT)<) +endif + +################################################################################ +# Test read and write to file + +READ_WRITE_FILE := $(OUTPUT_DIR)/read-write +READ_WRITE_VALUE := foo '""' "''" \t\n\\ bar +$(call WriteFile, $(READ_WRITE_VALUE), $(READ_WRITE_FILE)) +READ_WRITE_RESULT := $(call ReadFile, $(READ_WRITE_FILE)) + +ifneq ($(READ_WRITE_VALUE), $(READ_WRITE_RESULT)) + $(error Expected: >$(READ_WRITE_VALUE)< - Result: >$(READ_WRITE_RESULT)<) +endif + +################################################################################ +# Test creating dependencies on make variables + +VARDEP_DIR := $(OUTPUT_DIR)/vardep +VARDEP_SRC_FILE := $(VARDEP_DIR)/src-file +VARDEP_TARGET_FILE := $(VARDEP_DIR)/target-file +VARDEP_FLAG_FILE := $(VARDEP_DIR)/flag-file + +$(VARDEP_DIR)/src-file: + $(MKDIR) -p $(@D) + $(ECHO) "some string XXX" > $@ + +$(VARDEP_TARGET_FILE): $(VARDEP_DIR)/src-file \ + $(call DependOnVariable, VARDEP_TEST_VAR) + $(MKDIR) -p $(@D) + $(SED) -e 's/XXX/$(VARDEP_TEST_VAR)/g' $< > $@ + $(TOUCH) $(VARDEP_FLAG_FILE) + +test-vardep: + $(RM) $(VARDEP_SRC_FILE) $(VARDEP_TARGET_FILE) $(VARDEP_FLAG_FILE) + # + # Simply create the target file and verify that it has the correct value + # + $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value1 $(VARDEP_TARGET_FILE) + $(PRINTF) "Expecting value1: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" + test "some string value1" = "`$(CAT) $(VARDEP_DIR)/target-file`" + test -e $(VARDEP_FLAG_FILE) + # + # Make the target file again and verify that the value is updated with + # the new value + # + $(SLEEP_ON_MAC) + $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) + $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" + test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" + test -e $(VARDEP_FLAG_FILE) + # + # Make the target again with the same value and verify that the recipe + # was never run by checking that the flag file was not recreated + # + $(SLEEP_ON_MAC) + $(RM) $(VARDEP_FLAG_FILE) + $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) + $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" + test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" + test ! -e $(VARDEP_FLAG_FILE) + # + # Test running with spaces at the end and the middle of the value + # and verify that the file isn't rewritten the second time + # + $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo " $(VARDEP_TARGET_FILE) + $(RM) $(VARDEP_FLAG_FILE) + $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo" $(VARDEP_TARGET_FILE) + test ! -e $(VARDEP_FLAG_FILE) + $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=" value3 foo" $(VARDEP_TARGET_FILE) + test ! -e $(VARDEP_FLAG_FILE) + +# Test specifying a specific value file to store variable in +VARDEP_VALUE_FILE := $(VARDEP_DIR)/value-file +VARDEP_TEST_VAR2 := value3 + +VARDEP_RETURN_VALUE := $(call DependOnVariable, VARDEP_TEST_VAR2, $(VARDEP_VALUE_FILE)) +ifneq ($(VARDEP_VALUE_FILE), $(VARDEP_RETURN_VALUE)) + $(error Expected: $(VARDEP_VALUE_FILE) - DependOnVariable: $(VARDEP_RETURN_VALUE)) +endif +VARDEP_FILE_CONTENTS := $(shell $(CAT) $(VARDEP_VALUE_FILE)) +ifneq ($(VARDEP_TEST_VAR2), $(VARDEP_FILE_CONTENTS)) + $(error Expected: $(VARDEP_TEST_VAR2) - DependOnVariable file contained: \ + $(VARDEP_FILE_CONTENTS)) +endif + +# Test with a variable value containing some problematic characters +VARDEP_TEST_VAR3 := foo '""' "''" bar +VARDEP_VALUE_FILE := $(call DependOnVariable, VARDEP_TEST_VAR3) +VARDEP_FILE_CONTENTS := $(shell $(CAT) $(VARDEP_VALUE_FILE)) +ifneq ($(VARDEP_TEST_VAR3), $(VARDEP_FILE_CONTENTS)) + $(error Expected: >$(VARDEP_TEST_VAR3)< - DependOnVariable file contained: \ + >$(VARDEP_FILE_CONTENTS)<) +endif + +TEST_TARGETS += test-vardep + +################################################################################ all: $(TEST_TARGETS)