JPS: switched to use dirty files without incremental compilation (temporary hack for recompiling all).
Fixed compiling files from excluded directories.
Original commit: e5a58e0c70
This commit is contained in:
@@ -134,8 +134,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
return ExitCode.NOTHING_DONE;
|
||||
}
|
||||
|
||||
List<File> sourceFiles = KotlinSourceFileCollector.getAllKotlinSourceFiles(representativeTarget);
|
||||
//List<File> sourceFiles = KotlinSourceFileCollector.getDirtySourceFiles(dirtyFilesHolder);
|
||||
List<File> sourceFiles = KotlinSourceFileCollector.getDirtySourceFiles(dirtyFilesHolder);
|
||||
|
||||
if (sourceFiles.isEmpty()) {
|
||||
return ExitCode.NOTHING_DONE;
|
||||
@@ -157,7 +156,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
NO_LOCATION);
|
||||
}
|
||||
|
||||
File moduleFile = KotlinBuilderModuleScriptGenerator.generateModuleDescription(context, chunk);
|
||||
File moduleFile = KotlinBuilderModuleScriptGenerator.generateModuleDescription(context, dirtyFilesHolder);
|
||||
if (moduleFile == null) {
|
||||
// No Kotlin sources found
|
||||
return ExitCode.NOTHING_DONE;
|
||||
@@ -169,15 +168,9 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
moduleFile, outputItemCollector);
|
||||
}
|
||||
|
||||
// If there's only one target, this map is empty: get() always returns null, and the representativeTarget will be used below
|
||||
Map<File, BuildTarget<?>> sourceToTarget = new HashMap<File, BuildTarget<?>>();
|
||||
if (chunk.getTargets().size() > 1) {
|
||||
for (ModuleBuildTarget target : chunk.getTargets()) {
|
||||
for (File file : KotlinSourceFileCollector.getAllKotlinSourceFiles(target)) {
|
||||
sourceToTarget.put(file, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<File, ModuleBuildTarget> sourceToTarget = KotlinSourceFileCollector.getMapDirtySourcesToTarget(dirtyFilesHolder);
|
||||
|
||||
boolean isAllRegistered = false;
|
||||
|
||||
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {
|
||||
BuildTarget<?> target = null;
|
||||
@@ -186,15 +179,21 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
target = sourceToTarget.get(sourceFiles.iterator().next());
|
||||
}
|
||||
else {
|
||||
messageCollector.report(ERROR,
|
||||
INTERNAL_ERROR_PREFIX + "outputItem.sourceFiles is null or empty, outputItem = " + outputItem,
|
||||
NO_LOCATION);
|
||||
messageCollector.report(EXCEPTION, "KotlinBuilder: outputItem.sourceFiles is null or empty, outputItem = " + outputItem, NO_LOCATION);
|
||||
}
|
||||
|
||||
outputConsumer.registerOutputFile(
|
||||
target != null ? target : representativeTarget,
|
||||
outputItem.getOutputFile(),
|
||||
paths(outputItem.getSourceFiles()));
|
||||
//TODO FIX: Hack for compile all files if someone changed, because we don't have incremental compilation.
|
||||
if (!isAllRegistered) {
|
||||
isAllRegistered = true;
|
||||
sourceFiles = sourceToTarget.keySet();
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
messageCollector.report(EXCEPTION, "KotlinBuilder: target is null for outputItem = " + outputItem, NO_LOCATION);
|
||||
}
|
||||
else {
|
||||
outputConsumer.registerOutputFile(target, outputItem.getOutputFile(), paths(sourceFiles));
|
||||
}
|
||||
}
|
||||
|
||||
return ExitCode.OK;
|
||||
|
||||
+25
-11
@@ -17,13 +17,14 @@
|
||||
package org.jetbrains.jet.jps.build;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.compiler.runner.KotlinModuleDescriptionBuilder;
|
||||
import org.jetbrains.jet.compiler.runner.KotlinModuleDescriptionBuilderFactory;
|
||||
import org.jetbrains.jet.compiler.runner.KotlinModuleXmlBuilderFactory;
|
||||
import org.jetbrains.jps.ModuleChunk;
|
||||
import org.jetbrains.jps.builders.DirtyFilesHolder;
|
||||
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor;
|
||||
import org.jetbrains.jps.incremental.CompileContext;
|
||||
import org.jetbrains.jps.incremental.ModuleBuildTarget;
|
||||
@@ -46,27 +47,39 @@ import java.util.*;
|
||||
import static org.jetbrains.jet.compiler.runner.KotlinModuleDescriptionBuilder.DependencyProcessor;
|
||||
import static org.jetbrains.jet.compiler.runner.KotlinModuleDescriptionBuilder.DependencyProvider;
|
||||
import static org.jetbrains.jet.jps.build.JpsUtils.getAllDependencies;
|
||||
import static org.jetbrains.jet.jps.build.KotlinSourceFileCollector.getMapTargetToDirtySources;
|
||||
|
||||
public class KotlinBuilderModuleScriptGenerator {
|
||||
|
||||
public static final KotlinModuleDescriptionBuilderFactory FACTORY = KotlinModuleXmlBuilderFactory.INSTANCE;
|
||||
|
||||
@Nullable
|
||||
public static File generateModuleDescription(CompileContext context, ModuleChunk chunk)
|
||||
throws IOException
|
||||
{
|
||||
public static File generateModuleDescription(
|
||||
CompileContext context,
|
||||
DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder
|
||||
) throws IOException {
|
||||
KotlinModuleDescriptionBuilder builder = FACTORY.create();
|
||||
|
||||
boolean noSources = true;
|
||||
|
||||
Set<File> outputDirs = new HashSet<File>();
|
||||
for (ModuleBuildTarget target : chunk.getTargets()) {
|
||||
outputDirs.add(getOutputDir(target));
|
||||
}
|
||||
for (ModuleBuildTarget target : chunk.getTargets()) {
|
||||
Map<ModuleBuildTarget, List<File>> target2sources = getMapTargetToDirtySources(dirtyFilesHolder);
|
||||
|
||||
Set<ModuleBuildTarget> targets = target2sources.keySet();
|
||||
Set<File> outputDirs = ContainerUtil.map2Set(targets, new Function<ModuleBuildTarget, File>() {
|
||||
@Override
|
||||
public File fun(ModuleBuildTarget target) {
|
||||
return getOutputDir(target);
|
||||
}
|
||||
});
|
||||
|
||||
for (ModuleBuildTarget target : targets) {
|
||||
File outputDir = getOutputDir(target);
|
||||
|
||||
List<File> sourceFiles = KotlinSourceFileCollector.getAllKotlinSourceFiles(target);
|
||||
List<File> sourceFiles = target2sources.get(target);
|
||||
if (sourceFiles == null) {
|
||||
sourceFiles = Collections.emptyList();
|
||||
}
|
||||
|
||||
noSources &= sourceFiles.isEmpty();
|
||||
|
||||
builder.addModule(
|
||||
@@ -82,7 +95,8 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
|
||||
if (noSources) return null;
|
||||
|
||||
File scriptFile = new File(getOutputDir(chunk.representativeTarget()), "script." + FACTORY.getFileExtension());
|
||||
ModuleBuildTarget representativeTarget = targets.iterator().next();
|
||||
File scriptFile = new File(getOutputDir(representativeTarget), "script." + FACTORY.getFileExtension());
|
||||
|
||||
writeScriptToFile(context, builder.asText(), scriptFile);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.jps.build;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.builders.DirtyFilesHolder;
|
||||
@@ -29,7 +30,7 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class KotlinSourceFileCollector {
|
||||
// For incremental compilation
|
||||
@@ -50,6 +51,49 @@ public class KotlinSourceFileCollector {
|
||||
return sourceFiles;
|
||||
}
|
||||
|
||||
public static Map<ModuleBuildTarget, List<File>> getMapTargetToDirtySources(
|
||||
DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder
|
||||
) throws IOException {
|
||||
final Map<ModuleBuildTarget, List<File>> target2sources = new HashMap<ModuleBuildTarget, List<File>>();
|
||||
|
||||
dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {
|
||||
@Override
|
||||
public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor root) throws IOException {
|
||||
List<File> sources = target2sources.get(target);
|
||||
if (sources == null) {
|
||||
sources = new SmartList<File>();
|
||||
target2sources.put(target, sources);
|
||||
}
|
||||
|
||||
if (isKotlinSourceFile(file)) {
|
||||
sources.add(file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return target2sources;
|
||||
}
|
||||
|
||||
|
||||
public static Map<File, ModuleBuildTarget> getMapDirtySourcesToTarget(
|
||||
DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder
|
||||
) throws IOException {
|
||||
final Map<File, ModuleBuildTarget> source2target = new HashMap<File, ModuleBuildTarget>();
|
||||
|
||||
dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {
|
||||
@Override
|
||||
public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor root) throws IOException {
|
||||
if (isKotlinSourceFile(file)) {
|
||||
source2target.put(file, target);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return source2target;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<File> getAllKotlinSourceFiles(@NotNull ModuleBuildTarget target) {
|
||||
final List<File> result = ContainerUtil.newArrayList();
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.jps.build;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.jet.codegen.NamespaceCodegen;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -73,14 +74,34 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
public void testKotlinProject() {
|
||||
doTest();
|
||||
|
||||
assertOutputDeleted("src/test1.kt", "_DefaultPackage", "kotlinProject");
|
||||
assertOutputDeletedPackageInModule("kotlinProject", "src/test1.kt", "_DefaultPackage");
|
||||
}
|
||||
|
||||
public void testExcludeFolderInSourceRoot() {
|
||||
doTest();
|
||||
|
||||
JpsModule module = myProject.getModules().get(0);
|
||||
assertFileExistsInOutput(module, "Foo.class");
|
||||
|
||||
assertOutputDeletedInModule("kotlinProject", "src/foo.kt", "Foo");
|
||||
}
|
||||
|
||||
public void testExcludeModuleFolderInSourceRootOfAnotherModule() {
|
||||
doTest();
|
||||
|
||||
for (JpsModule module : myProject.getModules()) {
|
||||
assertFileExistsInOutput(module, "Foo.class");
|
||||
}
|
||||
|
||||
assertOutputDeletedInModule("kotlinProject", "src/foo.kt", "Foo");
|
||||
assertOutputDeletedInModule("module2", "src/module2/src/foo.kt", "Foo");
|
||||
}
|
||||
|
||||
public void testKotlinProjectTwoFilesInOnePackage() {
|
||||
doTest();
|
||||
|
||||
assertOutputDeleted("src/test1.kt", "_DefaultPackage", "kotlinProject");
|
||||
assertOutputDeleted("src/test2.kt", "_DefaultPackage", "kotlinProject");
|
||||
assertOutputDeletedPackageInModule("kotlinProject", "src/test1.kt", "_DefaultPackage");
|
||||
assertOutputDeletedPackageInModule("kotlinProject", "src/test2.kt", "_DefaultPackage");
|
||||
}
|
||||
|
||||
public void testKotlinJavaProject() {
|
||||
@@ -126,8 +147,8 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
}
|
||||
result.assertSuccessful();
|
||||
|
||||
assertOutputDeleted("src/kt2.kt", "kt2.Kt2Package", "kotlinProject");
|
||||
assertOutputDeleted("module2/src/kt1.kt", "kt1.Kt1Package", "module2");
|
||||
assertOutputDeletedPackageInModule("kotlinProject", "src/kt2.kt", "kt2.Kt2Package");
|
||||
assertOutputDeletedPackageInModule("module2", "module2/src/kt1.kt", "kt1.Kt1Package");
|
||||
}
|
||||
|
||||
public void testReexportedDependency() {
|
||||
@@ -166,14 +187,35 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void assertOutputDeleted(String sourceFileName, String packageClassFqName, String moduleName) {
|
||||
private void assertOutputDeletedPackageInModule(String moduleName, String sourceFileName, String packageClassFqNames) {
|
||||
File file = new File(workDir, sourceFileName);
|
||||
String[] packageClasses = { packageClassFqNames, getInternalNameForPackagePartClass(file, packageClassFqNames) };
|
||||
|
||||
assertOutputDeletedInModule(moduleName, sourceFileName, packageClasses);
|
||||
}
|
||||
|
||||
private void assertOutputDeletedInModule(final String moduleName, String sourceFileName, String... classFqNames) {
|
||||
String[] paths = ContainerUtil.map2Array(classFqNames, String.class, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String classFqName) {
|
||||
return outputPathInModuleByClassFqName(moduleName, classFqName);
|
||||
}
|
||||
});
|
||||
|
||||
assertOutputDeleted(sourceFileName, paths);
|
||||
}
|
||||
|
||||
private void assertOutputDeleted(String sourceFileName, String... paths) {
|
||||
File file = new File(workDir, sourceFileName);
|
||||
change(file.getAbsolutePath());
|
||||
makeAll().assertSuccessful();
|
||||
|
||||
assertDeleted(paths);
|
||||
}
|
||||
|
||||
private static String outputPathInModuleByClassFqName(String moduleName, String classFqName) {
|
||||
String outputDirPrefix = "out/production/" + moduleName + "/";
|
||||
assertDeleted(outputDirPrefix + packageClassFqName.replace('.', '/') + ".class",
|
||||
outputDirPrefix + getInternalNameForPackagePartClass(file, packageClassFqName) + ".class");
|
||||
return outputDirPrefix + classFqName.replace('.', '/') + ".class";
|
||||
}
|
||||
|
||||
private static String getInternalNameForPackagePartClass(File sourceFile, String packageClassFqName) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?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" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/src/exclude"/>
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.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>
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
class Foo
|
||||
@@ -0,0 +1 @@
|
||||
class Foo
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?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" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/src/module2" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/src/module2/module2.iml" filepath="$PROJECT_DIR$/src/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>
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
class Foo
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?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="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
class Foo
|
||||
Reference in New Issue
Block a user