Compile modules with circular dependency as one module

This commit is contained in:
Nikolay Krasko
2015-05-05 19:07:22 +03:00
parent 3b18a44340
commit 2d8dcaddd0
13 changed files with 146 additions and 3 deletions
@@ -170,15 +170,21 @@ public class KotlinToJVMBytecodeCompiler {
for (Module module : chunk) {
addKotlinSourceRoots(configuration, getAbsolutePaths(directory, module));
}
for (Module module : chunk) {
for (String javaSourceRoot : module.getJavaSourceRoots()) {
addJavaSourceRoot(configuration, new File(javaSourceRoot));
}
}
for (Module module : chunk) {
for (String classpathRoot : module.getClasspathRoots()) {
addJvmClasspathRoot(configuration, new File(classpathRoot));
}
}
for (Module module : chunk) {
for (String annotationsRoot : module.getAnnotationsRoots()) {
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, new File(annotationsRoot));
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.jps.build;
import com.google.common.collect.Lists;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.LightVirtualFile;
@@ -33,6 +34,7 @@ import org.jetbrains.jps.util.JpsPathUtil;
import org.jetbrains.kotlin.codegen.AsmUtil;
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.test.MockLibraryUtil;
import org.jetbrains.kotlin.utils.PathUtil;
import org.jetbrains.org.objectweb.asm.ClassReader;
import org.jetbrains.org.objectweb.asm.ClassVisitor;
@@ -258,7 +260,7 @@ public class KotlinJpsBuildTest extends AbstractKotlinJpsBuildTestCase {
assertFilesExistInOutput(module, "Foo.class", "Bar.class");
assertFilesNotExistInOutput(module, EXCLUDE_FILES);
checkWhen(touch("src/foo.kt"), null, new String[] { klass("kotlinProject", "Foo")} );
checkWhen(touch("src/foo.kt"), null, new String[] {klass("kotlinProject", "Foo")});
checkWhen(touch("src/Excluded.kt"), null, NOTHING );
checkWhen(touch("src/dir/YetAnotherExcluded.kt"), null, NOTHING);
}
@@ -270,7 +272,7 @@ public class KotlinJpsBuildTest extends AbstractKotlinJpsBuildTestCase {
assertFilesExistInOutput(module, "Foo.class", "Bar.class");
assertFilesNotExistInOutput(module, EXCLUDE_FILES);
checkWhen(touch("src/foo.kt"), null, new String[] { klass("kotlinProject", "Foo")} );
checkWhen(touch("src/foo.kt"), null, new String[] {klass("kotlinProject", "Foo")});
checkWhen(touch("src/dir/subdir/bar.kt"), null, new String[] { klass("kotlinProject", "Bar")} );
checkWhen(touch("src/dir/Excluded.kt"), null, NOTHING );
@@ -284,7 +286,7 @@ public class KotlinJpsBuildTest extends AbstractKotlinJpsBuildTestCase {
assertFilesExistInOutput(module, "Foo.class", "Bar.class");
assertFilesNotExistInOutput(module, EXCLUDE_FILES);
checkWhen(touch("src/foo.kt"), null, new String[] { klass("kotlinProject", "Foo")} );
checkWhen(touch("src/foo.kt"), null, new String[] {klass("kotlinProject", "Foo")});
checkWhen(touch("src/exclude/Excluded.kt"), null, NOTHING);
checkWhen(touch("src/exclude/YetAnotherExcluded.kt"), null, NOTHING);
@@ -416,6 +418,19 @@ public class KotlinJpsBuildTest extends AbstractKotlinJpsBuildTestCase {
checkWhen(touch("module2/src/b.kt"), null, packageClasses("module2", "module2/src/b.kt", "test.TestPackage"));
}
public void testCircularDependencyWithReferenceToOldVersionLib() throws IOException {
initProject();
File libraryJar = MockLibraryUtil.compileLibraryToJar(
workDir.getAbsolutePath() + File.separator + "oldModuleLib/src", "module-lib", false);
addDependency(JpsJavaDependencyScope.COMPILE, Lists.newArrayList(findModule("module1"), findModule("module2")), false,
"module-lib", libraryJar);
BuildResult result = makeAll();
result.assertSuccessful();
}
private void createKotlinJavaScriptLibraryArchive() {
File jarFile = new File(workDir, KOTLIN_JS_LIBRARY_JAR);
try {
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
<component name="CopyrightManager" default="">
<module2copyright />
</component>
<component name="DependencyValidationManager">
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</component>
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/module1/module1.iml" filepath="$PROJECT_DIR$/module1/module1.iml" />
<module fileurl="file://$PROJECT_DIR$/module2/module2.iml" filepath="$PROJECT_DIR$/module2/module2.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="xUTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="module" module-name="module2" />
</component>
</module>
@@ -0,0 +1,6 @@
package module1;
public class JavaClass {
public static void newJavaMethod() {}
public static void oldJavaMethod() {}
}
@@ -0,0 +1,11 @@
package module1
import module2.*
fun foo() {
JavaClass.oldJavaMethod()
JavaClass.newJavaMethod()
KotlinObject.oldKotlinMethod()
KotlinObject.newKotlinMethod()
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="module" module-name="module1" />
</component>
</module>
@@ -0,0 +1,9 @@
package module2
public object KotlinObject {
public fun oldKotlinMethod() {
}
public fun newKotlinMethod() {
}
}
@@ -0,0 +1,11 @@
package module2
import module1.*
fun bar() {
JavaClass.oldJavaMethod()
JavaClass.newJavaMethod()
KotlinObject.oldKotlinMethod()
KotlinObject.newKotlinMethod()
}
@@ -0,0 +1,5 @@
package module1;
public class JavaClass {
public static void oldJavaMethod() {}
}
@@ -0,0 +1,9 @@
package module1
import module2.*
fun foo() {
JavaClass.oldJavaMethod()
KotlinObject.oldKotlinMethod()
}
@@ -0,0 +1,6 @@
package module2
public object KotlinObject {
public fun oldKotlinMethod() {
}
}
@@ -0,0 +1,9 @@
package module2
import module1.*
fun bar() {
JavaClass.oldJavaMethod()
KotlinObject.oldKotlinMethod()
}