diff --git a/make/common/JavaCompilation.gmk b/make/common/JavaCompilation.gmk index 880f65267ade5..9c0ee46727582 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 a9d806da0c070..8bb60b6795838 100644 --- a/make/common/MakeBase.gmk +++ b/make/common/MakeBase.gmk @@ -443,12 +443,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 d42a7d50a64d9..ce58ced90f88a 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 void init(JavacTask jt, String... args) { 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 ClassLoader getClassLoader(JavaFileManager.Location location) { } 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 @@ private com.sun.tools.javac.util.List doFilteredParse( } 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 @@ private com.sun.tools.javac.util.List doFilteredParse( 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 @@ private com.sun.tools.javac.util.List doFilteredParse( .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 Void visitModifiers(ModifiersTree node, Void p) { 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 f93c908a06e4d..255b41a868011 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