From 8ebebbce32c7021cc0983dece4bb2644c79e64aa Mon Sep 17 00:00:00 2001 From: Jorn Vernee Date: Wed, 5 Oct 2022 10:26:53 +0000 Subject: [PATCH] 8294368: Java incremental builds broken on Windows after JDK-8293116 Reviewed-by: erikj, djelinski, jlahoda --- make/common/JavaCompilation.gmk | 11 +++++++++-- make/common/MakeBase.gmk | 11 +++++++++++ .../src/classes/build/tools/depend/Depend.java | 16 ++++++++++------ make/scripts/fixpath.sh | 17 +++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/make/common/JavaCompilation.gmk b/make/common/JavaCompilation.gmk index 880f65267ad..9c0ee467275 100644 --- a/make/common/JavaCompilation.gmk +++ b/make/common/JavaCompilation.gmk @@ -403,6 +403,7 @@ define SetupJavaCompilationBody $1_COMPILE_TARGET := $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_batch $1_FILELIST := $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_batch.filelist $1_MODFILELIST := $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_batch.modfiles + $1_MODFILELIST_FIXED := $$($1_MODFILELIST).fixed $1_API_TARGET := $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_pubapi $1_API_INTERNAL := $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$1_internalapi @@ -469,15 +470,21 @@ define SetupJavaCompilationBody $$(eval $1_MODFILES := $$?) $$(eval $$(call ListPathsSafely, $1_MODFILES, $$($1_MODFILELIST))) + # Convert the paths in the MODFILELIST file to Windows-style paths + # on Windows. This is needed because javac operates on Windows-style paths + # when running on Windows. On other platforms this just copies the MODFILELIST file. + $$($1_MODFILELIST_FIXED): $$($1_MODFILELIST) + $$(call FixPathFile, $$($1_MODFILELIST), $$($1_MODFILELIST_FIXED)) + # Do the actual compilation $$($1_COMPILE_TARGET): $$($1_SRCS) $$($1_FILELIST) $$($1_DEPENDS) \ $$($1_VARDEPS_FILE) $$($1_EXTRA_DEPS) $$($1_JAVAC_SERVER_CONFIG) \ - $$($1_MODFILELIST) + $$($1_MODFILELIST_FIXED) $$(call MakeDir, $$(@D)) $$(call ExecuteWithLog, $$($1_BIN)$$($1_MODULE_SUBDIR)/_the.$$($1_SAFE_NAME)_batch, \ $$($1_JAVAC_CMD) $$($1_FLAGS) \ $$($1_API_DIGEST_FLAGS) \ - -XDmodifiedInputs=$$($1_MODFILELIST) \ + -XDmodifiedInputs=$$($1_MODFILELIST_FIXED) \ -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_FILELIST)) && \ $(TOUCH) $$@ diff --git a/make/common/MakeBase.gmk b/make/common/MakeBase.gmk index e281a4ea51b..0ee41f5cf76 100644 --- a/make/common/MakeBase.gmk +++ b/make/common/MakeBase.gmk @@ -442,12 +442,23 @@ endif # list. # This is normally not needed since we use the FIXPATH prefix for command lines, # but might be needed in certain circumstances. +# +# FixPathFile is the file version of FixPath. It instead takes a file with paths in $1 +# and outputs the 'fixed' paths into the file in $2. If the file in $2 already exists +# it is overwritten. +# On non-Windows platforms this instead does a copy, so that $2 can still be used +# as a depenendency of a make rule, instead of having to conditionally depend on +# $1 instead, based on the target platform. ifeq ($(call isTargetOs, windows), true) FixPath = \ $(strip $(subst \,\\, $(shell $(FIXPATH_BASE) print $(patsubst $(FIXPATH), , $1)))) + FixPathFile = \ + $(shell $(FIXPATH_BASE) convert $1 $2) else FixPath = \ $1 + FixPathFile = \ + $(shell $(CP) $1 $2) endif ################################################################################ diff --git a/make/jdk/src/classes/build/tools/depend/Depend.java b/make/jdk/src/classes/build/tools/depend/Depend.java index d42a7d50a64..ce58ced90f8 100644 --- a/make/jdk/src/classes/build/tools/depend/Depend.java +++ b/make/jdk/src/classes/build/tools/depend/Depend.java @@ -154,7 +154,9 @@ public class Depend implements Plugin { if (internalAPIPath == null) { throw new IllegalStateException("Expected internalAPIPath to be set using -XDinternalAPIPath="); } - Set modified = new HashSet<>(Files.readAllLines(Paths.get(modifiedInputs))); + Set modified = Files.readAllLines(Paths.get(modifiedInputs)).stream() + .map(Paths::get) + .collect(Collectors.toSet()); Path internalAPIDigestFile = Paths.get(internalAPIPath); JavaCompiler compiler = JavaCompiler.instance(context); Class initialFileParserIntf = Class.forName("com.sun.tools.javac.main.JavaCompiler$InitialFileParserIntf"); @@ -255,7 +257,7 @@ public class Depend implements Plugin { } private com.sun.tools.javac.util.List doFilteredParse( - JavaCompiler compiler, Iterable fileObjects, Set modified, + JavaCompiler compiler, Iterable fileObjects, Set modified, Path internalAPIDigestFile, AtomicBoolean noApiChange, boolean debug) { Map internalAPI = new LinkedHashMap<>(); @@ -272,10 +274,11 @@ public class Depend implements Plugin { } Map files2CUT = new IdentityHashMap<>(); boolean fullRecompile = modified.stream() + .map(Path::toString) .anyMatch(f -> !StringUtils.toLowerCase(f).endsWith(".java")); ListBuffer result = new ListBuffer<>(); for (JavaFileObject jfo : fileObjects) { - if (modified.contains(jfo.getName())) { + if (modified.contains(Path.of(jfo.getName()))) { JCCompilationUnit parsed = compiler.parse(jfo); files2CUT.put(jfo, parsed); String currentSignature = treeDigest(parsed); @@ -289,7 +292,7 @@ public class Depend implements Plugin { if (fullRecompile) { for (JavaFileObject jfo : fileObjects) { - if (!modified.contains(jfo.getName())) { + if (!modified.contains(Path.of(jfo.getName()))) { JCCompilationUnit parsed = files2CUT.get(jfo); if (parsed == null) { parsed = compiler.parse(jfo); @@ -320,6 +323,7 @@ public class Depend implements Plugin { .findAny() .orElseGet(() -> "unknown"); String nonJavaModifiedFiles = modified.stream() + .map(Path::toString) .filter(f -> !StringUtils.toLowerCase(f) .endsWith(".java")) .collect(Collectors.joining(", ")); @@ -879,13 +883,13 @@ public class Depend implements Plugin { private class FilteredInitialFileParser implements InvocationHandler { private final JavaCompiler compiler; - private final Set modified; + private final Set modified; private final Path internalAPIDigestFile; private final AtomicBoolean noApiChange; private final boolean debug; public FilteredInitialFileParser(JavaCompiler compiler, - Set modified, + Set modified, Path internalAPIDigestFile, AtomicBoolean noApiChange, boolean debug) { diff --git a/make/scripts/fixpath.sh b/make/scripts/fixpath.sh index f93c908a06e..255b41a8680 100644 --- a/make/scripts/fixpath.sh +++ b/make/scripts/fixpath.sh @@ -352,6 +352,21 @@ function convert_path() { fi } +# Treat $1 as name of a file containing paths. Convert those paths to Windows style, +# and output them to the file specified by $2. +# If the output file already exists, it is overwritten. +function convert_file() { + infile="$1" + outfile="$2" + if [[ -e $outfile ]] ; then + rm $outfile + fi + while read line; do + convert_path "$line" + echo "$result" >> $outfile + done < $infile +} + # Treat $1 as name of a file containing paths. Convert those paths to Windows style, # in a new temporary file, and return a string "@" pointing to that # new file. @@ -498,6 +513,8 @@ if [[ "$ACTION" == "import" ]] ; then elif [[ "$ACTION" == "print" ]] ; then print_command_line "$@" echo "$result" +elif [[ "$ACTION" == "convert" ]] ; then + convert_file "$@" elif [[ "$ACTION" == "exec" ]] ; then exec_command_line "$@" # Propagate exit code