mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8015145: Smartjavac needs more flexibility with linking to sources
Reviewed-by: jjg, ohrstrom
This commit is contained in:
parent
0c6e63367d
commit
fd4983b254
3 changed files with 49 additions and 9 deletions
|
@ -808,7 +808,10 @@ public class JavacState
|
||||||
|
|
||||||
// Create a set of filenames with full paths.
|
// Create a set of filenames with full paths.
|
||||||
for (Source s : now.sources().values()) {
|
for (Source s : now.sources().values()) {
|
||||||
calculatedSources.add(s.file().getPath());
|
// Don't include link only sources when comparing sources to compile
|
||||||
|
if (!s.isLinkedOnly()) {
|
||||||
|
calculatedSources.add(s.file().getPath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Read in the file and create another set of filenames with full paths.
|
// Read in the file and create another set of filenames with full paths.
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -249,16 +249,19 @@ public class Main {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find all source files allowable for linking.
|
// Create a map of all source files that are available for linking. Both -src and
|
||||||
|
// -sourcepath point to such files. It is possible to specify multiple
|
||||||
|
// -sourcepath options to enable different filtering rules. If the
|
||||||
|
// filters are the same for multiple sourcepaths, they may be concatenated
|
||||||
|
// using :(;). Before sending the list of sourcepaths to javac, they are
|
||||||
|
// all concatenated. The list created here is used by the SmartFileWrapper to
|
||||||
|
// make sure only the correct sources are actually available.
|
||||||
// We might find more modules here as well.
|
// We might find more modules here as well.
|
||||||
Map<String,Source> sources_to_link_to = new HashMap<String,Source>();
|
Map<String,Source> sources_to_link_to = new HashMap<String,Source>();
|
||||||
// Always reuse -src for linking as well! This means that we might
|
findFiles(args, "-src", Util.set(".java"), sources_to_link_to, modules, current_module, true);
|
||||||
// get two -sourcepath on the commandline after the rewrite, which is
|
|
||||||
// fine. We can have as many as we like. You need to have separate -src/-sourcepath/-classpath
|
|
||||||
// if you need different filtering rules for different roots. If you have the same filtering
|
|
||||||
// rules for all sourcepath roots, you can concatenate them using :(;) as before.
|
|
||||||
rewriteOptions(args, "-src", "-sourcepath");
|
|
||||||
findFiles(args, "-sourcepath", Util.set(".java"), sources_to_link_to, modules, current_module, true);
|
findFiles(args, "-sourcepath", Util.set(".java"), sources_to_link_to, modules, current_module, true);
|
||||||
|
// Rewrite the -src option to make it through to the javac instances.
|
||||||
|
rewriteOptions(args, "-src", "-sourcepath");
|
||||||
|
|
||||||
// Find all class files allowable for linking.
|
// Find all class files allowable for linking.
|
||||||
// And pickup knowledge of all modules found here.
|
// And pickup knowledge of all modules found here.
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @summary Tests sjavac basic functionality
|
||||||
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
@ -82,11 +87,13 @@ class SJavac {
|
||||||
compileWithOverrideSource();
|
compileWithOverrideSource();
|
||||||
compileWithInvisibleSources();
|
compileWithInvisibleSources();
|
||||||
compileCircularSources();
|
compileCircularSources();
|
||||||
|
compileExcludingDependency();
|
||||||
|
|
||||||
delete(gensrc);
|
delete(gensrc);
|
||||||
delete(gensrc2);
|
delete(gensrc2);
|
||||||
delete(gensrc3);
|
delete(gensrc3);
|
||||||
delete(bin);
|
delete(bin);
|
||||||
|
delete(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialCompile() throws Exception {
|
void initialCompile() throws Exception {
|
||||||
|
@ -381,6 +388,33 @@ class SJavac {
|
||||||
delete(bin);
|
delete(bin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests compiling class A that depends on class B without compiling class B
|
||||||
|
* @throws Exception If test fails
|
||||||
|
*/
|
||||||
|
void compileExcludingDependency() throws Exception {
|
||||||
|
System.out.println("\nVerify that excluding classes from compilation but not from linking works.");
|
||||||
|
System.out.println("---------------------------------------------------------------------------");
|
||||||
|
|
||||||
|
delete(gensrc);
|
||||||
|
delete(bin);
|
||||||
|
previous_bin_state = collectState(bin);
|
||||||
|
|
||||||
|
populate(gensrc,
|
||||||
|
"alfa/A.java",
|
||||||
|
"package alfa; public class A { beta.B b; }",
|
||||||
|
"beta/B.java",
|
||||||
|
"package beta; public class B { }");
|
||||||
|
|
||||||
|
compile("-x", "beta", "-src", "gensrc", "-x", "alfa", "-sourcepath", "gensrc",
|
||||||
|
"-d", "bin", "--server:portfile=testserver,background=false");
|
||||||
|
|
||||||
|
Map<String,Long> new_bin_state = collectState(bin);
|
||||||
|
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
|
||||||
|
"bin/alfa/A.class",
|
||||||
|
"bin/javac_state");
|
||||||
|
}
|
||||||
|
|
||||||
void removeFrom(Path dir, String... args) throws IOException {
|
void removeFrom(Path dir, String... args) throws IOException {
|
||||||
for (String filename : args) {
|
for (String filename : args) {
|
||||||
Path p = dir.resolve(filename);
|
Path p = dir.resolve(filename);
|
||||||
|
@ -405,7 +439,7 @@ class SJavac {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete(Path root) throws IOException {
|
void delete(final Path root) throws IOException {
|
||||||
if (!Files.exists(root)) return;
|
if (!Files.exists(root)) return;
|
||||||
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
|
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue