# HG changeset patch # User erikj # Date 1510775455 28800 # Node ID f7e430cbfe343fd0f0e410037c4ba758098a7d75 # Parent 0084b493dfc9b58b7a39a2844ae64ecee5b1f43a 8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS) Reviewed-by: tbell diff -r 0084b493dfc9 -r f7e430cbfe34 make/common/MakeBase.gmk --- a/make/common/MakeBase.gmk Wed Nov 15 23:25:40 2017 +0530 +++ b/make/common/MakeBase.gmk Wed Nov 15 11:50:55 2017 -0800 @@ -473,15 +473,32 @@ $(subst $(SPACE),?,$(strip $1)) ################################################################################ -# Make directory without forking mkdir if not needed +# Make directory without forking mkdir if not needed. +# +# If a directory with an encoded space is provided, the wildcard function +# sometimes returns false answers (typically if the dir existed when the +# makefile was parsed, but was deleted by a previous rule). In that case, always +# call mkdir regardless of what wildcard says. +# # 1: List of directories to create MakeDir = \ $(strip \ - $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, $(if $(wildcard $d), , \ - "$(call DecodeSpace, $d)")))) \ + $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \ + $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \ + $(if $(wildcard $d), , $d) \ + ) \ + ))) \ $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \ ) +# Make directory for target file. Should handle spaces in filenames. Just +# calling $(call MakeDir $(@D)) will not work if the directory contains a space +# and the target file already exists. In that case, the target file will have +# its wildcard ? resolved and the $(@D) will evaluate each space separated dir +# part on its own. +MakeTargetDir = \ + $(call MakeDir, $(dir $(call EncodeSpace, $@))) + ################################################################################ # Assign a variable only if it is empty # Param 1 - Variable to assign @@ -499,7 +516,7 @@ # If the source and target parent directories are the same, recursive copy doesn't work # so we fall back on regular copy, which isn't preserving symlinks. define install-file - $(call MakeDir, $(@D)) + $(call MakeTargetDir) $(RM) '$(call DecodeSpace, $@)' if [ '$(call DecodeSpace, $(dir $@))' != \ '$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \ @@ -526,21 +543,21 @@ # If copying a soft link to a directory, need to delete the target first to avoid # weird errors. define install-file - $(call MakeDir, $(@D)) + $(call MakeTargetDir) $(RM) '$(call DecodeSpace, $@)' $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then $(XATTR) -cs '$(call DecodeSpace, $@)'; fi endef else define install-file - $(call MakeDir, $(@D)) + $(call MakeTargetDir) $(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' endef endif # Variant of install file that does not preserve symlinks define install-file-nolink - $(call MakeDir, $(@D)) + $(call MakeTargetDir) $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' endef @@ -590,13 +607,13 @@ # careful when using this on Windows since the symlink created is only valid in # the unix emulation environment. define link-file-relative - $(call MakeDir, $(@D)) + $(call MakeTargetDir) $(RM) '$(call DecodeSpace, $@)' $(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)' endef define link-file-absolute - $(call MakeDir, $(@D)) + $(call MakeTargetDir) $(RM) '$(call DecodeSpace, $@)' $(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' endef diff -r 0084b493dfc9 -r f7e430cbfe34 test/make/TestCopyFiles.gmk --- a/test/make/TestCopyFiles.gmk Wed Nov 15 23:25:40 2017 +0530 +++ b/test/make/TestCopyFiles.gmk Wed Nov 15 11:50:55 2017 -0800 @@ -44,6 +44,7 @@ DEST_DIR := $(OUTPUT_DIR)/dest $(OUTPUT_DIR)/_src_created: $(DEPS) + $(RM) -r $(DEST_DIR) $(RM) -r $(SRC_DIR) $(MKDIR) -p $(SRC_DIR) $(MKDIR) -p $(SRC_DIR)/foo @@ -51,7 +52,7 @@ $(TOUCH) $(SRC_DIR)/foo/foofile $(TOUCH) "$(SRC_DIR)/foo/foo file" # Spaces in directories only works with gnu make 4.0 or later - ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION)))) + ifeq (4.0dfd, $(firstword $(sort 4.0 $(MAKE_VERSION)))) $(MKDIR) -p "$(SRC_DIR)/foo bar" $(TOUCH) "$(SRC_DIR)/foo bar/foobarfile" $(TOUCH) "$(SRC_DIR)/foo bar/foo bar file" @@ -65,15 +66,32 @@ FILES := $(call CacheFind, $(SRC_DIR)), \ )) +# Optionally define a rule that deletes all the target files after the makefile +# has been parsed. GNU make has specific problems with this in combination with +# spaces in directory names. +ifeq ($(DELETE_FIRST), true) + delete-targets: + $(RM) -r $(DEST_DIR) + $(ECHO) '$(DEST_DIR)/foo' '$(wildcard $(DEST_DIR)/foo)' + + $(COPY_1): delete-targets +endif + do-copy1: $(COPY_1) run-test1: $(OUTPUT_DIR)/_src_created + $(ECHO) "Copy 1 first time" +$(MAKE) -f $(THIS_FILE) do-copy1 $(DIFF) -r $(SRC_DIR) $(DEST_DIR) + # Rerun the copy a second time, with the targets present at make parse + # time, but then deleted by a prerequisite rule. + $(ECHO) "Copy 1 second time" + +$(MAKE) -f $(THIS_FILE) do-copy1 DELETE_FIRST=true + $(DIFF) -r $(SRC_DIR) $(DEST_DIR) TEST_TARGETS += run-test1 -.PHONY: do-copy1 run-test1 +.PHONY: do-copy1 run-test1 delete-targets ################################################################################