build: remove obsolete outputs from OutputToTargetRegistry

This commit is contained in:
nik
2018-02-01 14:12:31 +03:00
parent f79810c583
commit e591e3fac8
2 changed files with 16 additions and 6 deletions
@@ -506,7 +506,7 @@ public class IncProjectBuilder {
SourceToOutputMappingImpl mapping = null;
try {
mapping = myProjectDescriptor.dataManager.createSourceToOutputMapForStaleTarget(type, stringId);
clearOutputFiles(context, mapping, type);
clearOutputFiles(context, mapping, type, ids.second);
}
finally {
if (mapping != null) {
@@ -526,13 +526,17 @@ public class IncProjectBuilder {
public static void clearOutputFiles(CompileContext context, BuildTarget<?> target) throws IOException {
final SourceToOutputMapping map = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target);
BuildTargetType<?> targetType = target.getTargetType();
clearOutputFiles(context, map, targetType);
clearOutputFiles(context, map, targetType, context.getProjectDescriptor().dataManager.getTargetsState().getBuildTargetId(target));
registerTargetsWithClearedOutput(context, Collections.singletonList(target));
}
private static void clearOutputFiles(CompileContext context, SourceToOutputMapping mapping, BuildTargetType<?> targetType) throws IOException {
private static void clearOutputFiles(CompileContext context,
SourceToOutputMapping mapping,
BuildTargetType<?> targetType,
int targetId) throws IOException {
final THashSet<File> dirsToDelete = targetType instanceof ModuleBasedBuildTargetType<?>
? new THashSet<>(FileUtil.FILE_HASHING_STRATEGY) : null;
OutputToTargetRegistry outputToTargetRegistry = context.getProjectDescriptor().dataManager.getOutputToTargetRegistry();
for (String srcPath : mapping.getSources()) {
final Collection<String> outs = mapping.getOutputs(srcPath);
if (outs != null && !outs.isEmpty()) {
@@ -540,6 +544,7 @@ public class IncProjectBuilder {
for (String out : outs) {
BuildOperations.deleteRecursively(out, deletedPaths, dirsToDelete);
}
outputToTargetRegistry.removeMapping(outs, targetId);
if (!deletedPaths.isEmpty()) {
context.processMessage(new FileDeletedEvent(deletedPaths));
}
@@ -9,7 +9,8 @@ import org.jetbrains.jps.util.JpsPathUtil
class CleanStaleTargetsTest : JpsBuildTestCase() {
fun `test delete old output when module is deleted`() {
doTestDeleteOldOutput {
//todo[nik, jeka] currently references to classes from deleted module aren't removed ClassToSubclasses, ClassToClassDependency, SourceFileToClasses mappings
doTestDeleteOldOutput(false) {
myProject.removeModule(it)
}
}
@@ -28,7 +29,7 @@ class CleanStaleTargetsTest : JpsBuildTestCase() {
}
}
private fun doTestDeleteOldOutput(action: (JpsModule) -> Unit) {
private fun doTestDeleteOldOutput(checkMappings: Boolean = true, action: (JpsModule) -> Unit) {
JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(myProject).outputUrl = JpsPathUtil.pathToUrl(getAbsolutePath("out"))
val aRoot = PathUtil.getParentPath(createFile("a/src/A.java", "class A {}"))
val aModule = addModule("a", arrayOf(aRoot), null, null, jdk)
@@ -44,10 +45,14 @@ class CleanStaleTargetsTest : JpsBuildTestCase() {
//do not clean output when just one other target is built to avoid unexpectedly long builds
assertOutput(aOutput.absolutePath, directoryContent { file("A.class") })
buildAllModules()
val buildResult = buildAllModules()
//clean output of stale targets when all targets of this type are built
if (aOutput.exists()) {
assertOutput(aOutput.absolutePath, directoryContent { })
}
if (checkMappings) {
checkMappingsAreSameAfterRebuild(buildResult)
}
}
}