standalone mode of external compiler: don't force full project rebuild for the first time

This commit is contained in:
nik
2012-08-22 17:43:44 +04:00
parent 04e20c3f79
commit 9328663d0c
3 changed files with 15 additions and 22 deletions
@@ -33,7 +33,6 @@ public class BuildRunner {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.cmdline.BuildRunner");
private final JpsModelLoader myModelLoader;
private final Set<String> myModules;
private BuildType myBuildType;
private final List<String> myArtifacts;
private final List<String> myFilePaths;
private final Map<String, String> myBuilderParams;
@@ -41,22 +40,15 @@ public class BuildRunner {
public BuildRunner(JpsModelLoader modelLoader,
Set<String> modules,
BuildType buildType,
List<String> artifacts, List<String> filePaths, Map<String, String> builderParams) {
myModelLoader = modelLoader;
myModules = modules;
myBuildType = buildType;
myArtifacts = artifacts;
myFilePaths = filePaths;
myBuilderParams = builderParams;
}
public ProjectDescriptor load(MessageHandler msgHandler, File dataStorageRoot, BuildFSState fsState) throws IOException {
if (!dataStorageRoot.exists()) {
// invoked the very first time for this project. Force full rebuild
myBuildType = BuildType.PROJECT_REBUILD;
}
final boolean inMemoryMappingsDelta = System.getProperty(GlobalOptions.USE_MEMORY_TEMP_CACHE_OPTION) != null;
ProjectTimestamps projectTimestamps = null;
BuildDataManager dataManager = null;
@@ -91,18 +83,18 @@ public class BuildRunner {
}
public void runBuild(ProjectDescriptor pd, CanceledStatus cs, @Nullable Callbacks.ConstantAffectionResolver constantSearch,
MessageHandler msgHandler, final boolean includeTests) throws Exception {
MessageHandler msgHandler, final boolean includeTests, BuildType buildType) throws Exception {
for (int attempt = 0; attempt < 2; attempt++) {
if (myForceCleanCaches && myModules.isEmpty() && myFilePaths.isEmpty()) {
// if compilation scope is the whole project and cache rebuild is forced, use PROJECT_REBUILD for faster compilation
myBuildType = BuildType.PROJECT_REBUILD;
buildType = BuildType.PROJECT_REBUILD;
}
final CompileScope compileScope = createCompilationScope(myBuildType, pd, myModules, myArtifacts, myFilePaths, includeTests);
final CompileScope compileScope = createCompilationScope(buildType, pd, myModules, myArtifacts, myFilePaths, includeTests);
final IncProjectBuilder builder = new IncProjectBuilder(pd, BuilderRegistry.getInstance(), myBuilderParams, cs, constantSearch);
builder.addMessageHandler(msgHandler);
try {
switch (myBuildType) {
switch (buildType) {
case PROJECT_REBUILD:
builder.build(compileScope, false, true, myForceCleanCaches);
break;
@@ -134,10 +126,6 @@ public class BuildRunner {
}
}
public BuildType getBuildType() {
return myBuildType;
}
private static CompileScope createCompilationScope(BuildType buildType,
ProjectDescriptor pd,
Set<String> modules,
@@ -49,6 +49,7 @@ final class BuildSession implements Runnable, CanceledStatus {
private final Map<Pair<String, String>, ConstantSearchFuture> mySearchTasks = Collections.synchronizedMap(new HashMap<Pair<String, String>, ConstantSearchFuture>());
private final ConstantSearch myConstantSearch = new ConstantSearch();
private final BuildRunner myBuildRunner;
private BuildType myBuildType;
BuildSession(UUID sessionId,
Channel channel,
@@ -69,7 +70,7 @@ final class BuildSession implements Runnable, CanceledStatus {
// session params
myProjectPath = FileUtil.toCanonicalPath(params.getProjectId());
String globalOptionsPath = FileUtil.toCanonicalPath(globals.getGlobalOptionsPath());
BuildType myBuildType = convertCompileType(params.getBuildType());
myBuildType = convertCompileType(params.getBuildType());
Set<String> modules = new HashSet<String>(params.getModuleNameList());
List<String> artifacts = params.getArtifactNameList();
List<String> filePaths = params.getFilePathList();
@@ -79,7 +80,7 @@ final class BuildSession implements Runnable, CanceledStatus {
}
myInitialFSDelta = delta;
JpsModelLoaderImpl loader = new JpsModelLoaderImpl(myProjectPath, globalOptionsPath, pathVars, globalEncoding, ignorePatterns, null);
myBuildRunner = new BuildRunner(loader, modules, myBuildType, artifacts, filePaths, builderParams);
myBuildRunner = new BuildRunner(loader, modules, artifacts, filePaths, builderParams);
}
public void run() {
@@ -145,10 +146,14 @@ final class BuildSession implements Runnable, CanceledStatus {
try {
final boolean shouldApplyEvent = loadFsState(fsState, dataStorageRoot, myInitialFSDelta);
if (shouldApplyEvent && myBuildRunner.getBuildType() == BuildType.MAKE && !containsChanges(myInitialFSDelta) && !fsState.hasWorkToDo()) {
if (shouldApplyEvent && myBuildType == BuildType.MAKE && !containsChanges(myInitialFSDelta) && !fsState.hasWorkToDo()) {
applyFSEvent(null, myInitialFSDelta);
return;
}
if (!dataStorageRoot.exists()) {
// invoked the very first time for this project. Force full rebuild
myBuildType = BuildType.PROJECT_REBUILD;
}
ProjectDescriptor pd = myBuildRunner.load(msgHandler, dataStorageRoot, fsState);
myProjectDescriptor = pd;
if (shouldApplyEvent) {
@@ -161,7 +166,7 @@ final class BuildSession implements Runnable, CanceledStatus {
// ensure events from controller are processed after FSState initialization
myEventsProcessor.startProcessing();
myBuildRunner.runBuild(pd, cs, myConstantSearch, msgHandler, true);
myBuildRunner.runBuild(pd, cs, myConstantSearch, msgHandler, true, myBuildType);
}
finally {
saveData(fsState, dataStorageRoot);
@@ -115,9 +115,9 @@ public class Standalone {
public static void runBuild(JpsModelLoader loader, final File dataStorageRoot, BuildType buildType, Set<String> modulesSet,
List<String> artifactsList, final boolean includeTests, final MessageHandler messageHandler) throws Exception {
final BuildRunner buildRunner = new BuildRunner(loader, modulesSet, buildType, artifactsList, Collections.<String>emptyList(), Collections.<String, String>emptyMap());
final BuildRunner buildRunner = new BuildRunner(loader, modulesSet, artifactsList, Collections.<String>emptyList(), Collections.<String, String>emptyMap());
ProjectDescriptor descriptor = buildRunner.load(messageHandler, dataStorageRoot, new BuildFSState(true));
buildRunner.runBuild(descriptor, CanceledStatus.NULL, null, messageHandler, includeTests);
buildRunner.runBuild(descriptor, CanceledStatus.NULL, null, messageHandler, includeTests, buildType);
}
private static class ConsoleMessageHandler implements MessageHandler {