Report correct build targets for outputs + tests on output removal
Original commit: 2a43d2adee
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
<orderEntry type="library" name="jps" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="jps-test" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="idea-full" level="project" />
|
||||
<orderEntry type="module" module-name="backend" scope="TEST" />
|
||||
<orderEntry type="module" module-name="descriptors" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.jetbrains.jet.compiler.runner.SimpleOutputItem;
|
||||
import org.jetbrains.jet.jps.JpsKotlinCompilerSettings;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
import org.jetbrains.jps.ModuleChunk;
|
||||
import org.jetbrains.jps.builders.BuildTarget;
|
||||
import org.jetbrains.jps.builders.DirtyFilesHolder;
|
||||
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor;
|
||||
import org.jetbrains.jps.incremental.*;
|
||||
@@ -47,10 +48,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.*;
|
||||
import static org.jetbrains.jet.compiler.runner.KotlinCompilerRunner.runK2JsCompiler;
|
||||
@@ -165,9 +163,20 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
runK2JvmCompiler(commonSettings, k2JvmSettings, messageCollector, environment, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {
|
||||
BuildTarget<?> target = sourceToTarget.get(outputItem.getSourceFiles().iterator().next());
|
||||
outputConsumer.registerOutputFile(
|
||||
representativeTarget,
|
||||
target != null ? target : representativeTarget,
|
||||
outputItem.getOutputFile(),
|
||||
paths(outputItem.getSourceFiles()));
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ 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.containers.ContainerUtil;
|
||||
import org.jetbrains.jet.codegen.NamespaceCodegen;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jps.builders.BuildResult;
|
||||
import org.jetbrains.jps.model.java.JpsJavaDependencyScope;
|
||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
||||
@@ -26,6 +29,7 @@ import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.util.JpsPathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
private static final String PROJECT_NAME = "kotlinProject";
|
||||
@@ -36,6 +40,7 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
super.setUp();
|
||||
File sourceFilesRoot = new File(TEST_DATA_PATH + getTestName(false));
|
||||
workDir = copyTestDataToTmpDir(sourceFilesRoot);
|
||||
getOrCreateProjectDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,6 +49,11 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File doGetProjectDir() throws IOException {
|
||||
return workDir;
|
||||
}
|
||||
|
||||
private void initProject() {
|
||||
addJdk(JDK_NAME);
|
||||
loadProject(workDir.getAbsolutePath() + File.separator + PROJECT_NAME + ".ipr");
|
||||
@@ -62,6 +72,15 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
|
||||
public void testKotlinProject() {
|
||||
doTest();
|
||||
|
||||
assertOutputDeleted("src/test1.kt", "_DefaultPackage", "kotlinProject");
|
||||
}
|
||||
|
||||
public void testKotlinProjectTwoFilesInOnePackage() {
|
||||
doTest();
|
||||
|
||||
assertOutputDeleted("src/test1.kt", "_DefaultPackage", "kotlinProject");
|
||||
assertOutputDeleted("src/test2.kt", "_DefaultPackage", "kotlinProject");
|
||||
}
|
||||
|
||||
public void testKotlinJavaProject() {
|
||||
@@ -106,14 +125,9 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
}
|
||||
}
|
||||
result.assertSuccessful();
|
||||
}
|
||||
|
||||
public void testTestDependencyLibrary() throws Throwable {
|
||||
initProject();
|
||||
addKotlinRuntimeDependency(JpsJavaDependencyScope.TEST, myProject.getModules(), false);
|
||||
makeAll().assertSuccessful();
|
||||
change(workDir + "/src/src.kt", "fun foo() { println() }");
|
||||
makeAll().assertFailed();
|
||||
assertOutputDeleted("src/kt2.kt", "kt2.Kt2Package", "kotlinProject");
|
||||
assertOutputDeleted("module2/src/kt1.kt", "kt1.Kt1Package", "module2");
|
||||
}
|
||||
|
||||
public void testReexportedDependency() {
|
||||
@@ -133,7 +147,10 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
assertNotNull(outputUrl);
|
||||
File outputDir = new File(JpsPathUtil.urlToPath(outputUrl));
|
||||
File outputFile = new File(outputDir, relativePath);
|
||||
assertTrue("Output not written: " + outputFile.getAbsolutePath() + "\n Directory contents: \n" + dirContents(outputFile.getParentFile()),
|
||||
assertTrue("Output not written: " +
|
||||
outputFile.getAbsolutePath() +
|
||||
"\n Directory contents: \n" +
|
||||
dirContents(outputFile.getParentFile()),
|
||||
outputFile.exists());
|
||||
}
|
||||
|
||||
@@ -148,4 +165,25 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void assertOutputDeleted(String sourceFileName, String packageClassFqName, String moduleName) {
|
||||
File file = new File(workDir, sourceFileName);
|
||||
change(file.getAbsolutePath());
|
||||
makeAll();
|
||||
|
||||
String outputDirPrefix = "out/production/" + moduleName + "/";
|
||||
assertDeleted(outputDirPrefix + packageClassFqName.replace('.', '/') + ".class",
|
||||
outputDirPrefix + getInternalNameForPackagePartClass(file, packageClassFqName) + ".class");
|
||||
}
|
||||
|
||||
private static String getInternalNameForPackagePartClass(File sourceFile, String packageClassFqName) {
|
||||
LightVirtualFile fakeVirtualFile = new LightVirtualFile(sourceFile.getPath()) {
|
||||
@Override
|
||||
public String getPath() {
|
||||
// strip extra "/" from the beginning
|
||||
return super.getPath().substring(1);
|
||||
}
|
||||
};
|
||||
return NamespaceCodegen.getNamespacePartType(new FqName(packageClassFqName), fakeVirtualFile).getInternalName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="kotlinProject" />
|
||||
</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,3 @@
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun bar() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user