Fixed redeclaration from incremental compilation. Added workaround for JPS bug.
This commit is contained in:
+29
-5
@@ -19,6 +19,7 @@ package org.jetbrains.jet.cli.jvm.compiler;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -36,6 +37,8 @@ import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.jet.cli.common.CompilerPluginContext;
|
||||
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
@@ -51,8 +54,8 @@ import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
||||
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalPackage;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCache;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCacheProvider;
|
||||
@@ -63,9 +66,7 @@ import org.jetbrains.jet.utils.KotlinPaths;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
@@ -159,8 +160,11 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
@NotNull File directory
|
||||
) {
|
||||
CompilerConfiguration configuration = base.copy();
|
||||
|
||||
List<String> sourceRoots = Lists.newArrayList();
|
||||
|
||||
for (Module module : chunk) {
|
||||
configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, getAbsolutePaths(directory, module));
|
||||
sourceRoots.addAll(getAbsolutePaths(directory, module));
|
||||
|
||||
for (String classpathRoot : module.getClasspathRoots()) {
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, new File(classpathRoot));
|
||||
@@ -173,9 +177,29 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
configuration.add(JVMConfigurationKeys.MODULE_IDS, module.getModuleName());
|
||||
}
|
||||
|
||||
MessageCollector messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY);
|
||||
assert messageCollector != null : "messageCollector should be set: " + base;
|
||||
configuration.put(CommonConfigurationKeys.SOURCE_ROOTS_KEY, checkForDuplicatePaths(messageCollector, sourceRoots));
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private static List<String> checkForDuplicatePaths(@NotNull MessageCollector messageCollector, @NotNull List<String> sourceRoots) {
|
||||
Set<String> uniqueSourceRoots = Sets.newLinkedHashSet();
|
||||
|
||||
for (String sourceRoot : sourceRoots) {
|
||||
if (!uniqueSourceRoots.add(sourceRoot)) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.WARNING,
|
||||
"Duplicate source roots: " + sourceRoot,
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<String>(uniqueSourceRoots);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static FqName findMainClass(@NotNull GenerationState generationState, @NotNull List<JetFile> files) {
|
||||
MainFunctionDetector mainFunctionDetector = new MainFunctionDetector(generationState.getBindingContext());
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-module
|
||||
$TESTDATA_DIR$/duplicateSource.xml
|
||||
@@ -0,0 +1,2 @@
|
||||
WARNING: Duplicate source roots: $TESTDATA_DIR$/duplicateSource.kt
|
||||
OK
|
||||
@@ -0,0 +1,6 @@
|
||||
<modules>
|
||||
<module name="name" outputDir="whatever">
|
||||
<sources path="duplicateSource.kt"/>
|
||||
<sources path="duplicateSource.kt"/>
|
||||
</module>
|
||||
</modules>
|
||||
@@ -41,6 +41,11 @@ public class CliCommonTest extends CliBaseTest {
|
||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateSource() throws Exception {
|
||||
executeCompilerCompareOutputJVM();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diagnosticsOrder() throws Exception {
|
||||
executeCompilerCompareOutputJVM();
|
||||
|
||||
@@ -51,6 +51,11 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
|
||||
doJvmTest("compiler/testData/cli/jvm/diagnosticsOrder.args");
|
||||
}
|
||||
|
||||
@TestMetadata("duplicateSource.args")
|
||||
public void testDuplicateSource() throws Exception {
|
||||
doJvmTest("compiler/testData/cli/jvm/duplicateSource.args");
|
||||
}
|
||||
|
||||
@TestMetadata("extraHelp.args")
|
||||
public void testExtraHelp() throws Exception {
|
||||
doJvmTest("compiler/testData/cli/jvm/extraHelp.args");
|
||||
|
||||
@@ -49,6 +49,11 @@ public class KotlinSourceFileCollector {
|
||||
dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {
|
||||
@Override
|
||||
public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor root) throws IOException {
|
||||
//TODO this is a workaround for bug in JPS: the latter erroneously calls process with invalid parameters
|
||||
if (!root.getTarget().equals(target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isKotlinSourceFile(file)) {
|
||||
result.putValue(target, file);
|
||||
}
|
||||
|
||||
@@ -28,12 +28,31 @@ import java.util.regex.Pattern;
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("jps-plugin/testData/incremental")
|
||||
@InnerTestClasses({IncrementalJpsTestGenerated.PureKotlin.class})
|
||||
@InnerTestClasses({IncrementalJpsTestGenerated.CircularDependency.class, IncrementalJpsTestGenerated.PureKotlin.class})
|
||||
public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
|
||||
public void testAllFilesPresentInIncremental() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental"), Pattern.compile("^([^\\.]+)$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("jps-plugin/testData/incremental/circularDependency")
|
||||
@InnerTestClasses({})
|
||||
public static class CircularDependency extends AbstractIncrementalJpsTest {
|
||||
public void testAllFilesPresentInCircularDependency() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/circularDependency"), Pattern.compile("^([^\\.]+)$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("simple")
|
||||
public void testSimple() throws Exception {
|
||||
doTest("jps-plugin/testData/incremental/circularDependency/simple/");
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("CircularDependency");
|
||||
suite.addTestSuite(CircularDependency.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("jps-plugin/testData/incremental/pureKotlin")
|
||||
@InnerTestClasses({})
|
||||
public static class PureKotlin extends AbstractIncrementalJpsTest {
|
||||
@@ -231,6 +250,7 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("IncrementalJpsTestGenerated");
|
||||
suite.addTestSuite(IncrementalJpsTestGenerated.class);
|
||||
suite.addTest(CircularDependency.innerSuite());
|
||||
suite.addTest(PureKotlin.innerSuite());
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
Cleaning output files:
|
||||
out/production/module2/b/BPackage-module2_b-*.class
|
||||
out/production/module2/b/BPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
module2/src/module2_b.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module1/a/A.class
|
||||
out/production/module1/a/APackage-module1_a-*.class
|
||||
out/production/module1/a/APackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
module1/src/module1_a.kt
|
||||
End of files
|
||||
@@ -0,0 +1,2 @@
|
||||
module1->module2
|
||||
module2->module1
|
||||
@@ -0,0 +1,9 @@
|
||||
package a
|
||||
|
||||
class A
|
||||
|
||||
fun a() {
|
||||
// TODO: this call is compiled via package facade or package part depending on if callee comes from compiled or source
|
||||
// Must be uncommented when modules are supported in compiler
|
||||
//b.b()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package b
|
||||
|
||||
fun b() {
|
||||
// TODO: this call is compiled via package facade or package part depending on if callee comes from compiled or source
|
||||
// Must be uncommented when modules are supported in compiler
|
||||
// a.a()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package b
|
||||
|
||||
fun b() {
|
||||
// TODO: this call is compiled via package facade or package part depending on if callee comes from compiled or source
|
||||
// Must be uncommented when modules are supported in compiler
|
||||
// a.a()
|
||||
}
|
||||
|
||||
fun bb() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user