use of com.google.idea.blaze.base.model.SyncState in project intellij by bazelbuild.
the class JdepsFileReader method loadJdepsFiles.
/**
* Loads any updated jdeps files since the last invocation of this method.
*/
@Nullable
public JdepsMap loadJdepsFiles(Project project, BlazeContext parentContext, ArtifactLocationDecoder artifactLocationDecoder, Iterable<TargetIdeInfo> targetsToLoad, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
JdepsState oldState = previousSyncState != null ? previousSyncState.get(JdepsState.class) : null;
JdepsState jdepsState = Scope.push(parentContext, (context) -> {
context.push(new TimingScope("LoadJdepsFiles", EventType.Other));
return doLoadJdepsFiles(project, context, artifactLocationDecoder, oldState, targetsToLoad);
});
if (jdepsState == null) {
return null;
}
syncStateBuilder.put(JdepsState.class, jdepsState);
return targetKey -> jdepsState.targetToJdeps.get(targetKey);
}
use of com.google.idea.blaze.base.model.SyncState in project intellij by bazelbuild.
the class BlazeSyncTask method doSyncProject.
/**
* @return true if sync successfully completed
*/
private SyncResult doSyncProject(BlazeContext context, @Nullable BlazeProjectData oldBlazeProjectData) {
long syncStartTime = System.currentTimeMillis();
if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
IssueOutput.error(String.format("Workspace '%s' doesn't exist.", workspaceRoot.directory())).submit(context);
return SyncResult.FAILURE;
}
BlazeVcsHandler vcsHandler = BlazeVcsHandler.vcsHandlerForProject(project);
if (vcsHandler == null) {
IssueOutput.error("Could not find a VCS handler").submit(context);
return SyncResult.FAILURE;
}
ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor();
WorkspacePathResolverAndProjectView workspacePathResolverAndProjectView = computeWorkspacePathResolverAndProjectView(context, vcsHandler, executor);
if (workspacePathResolverAndProjectView == null) {
return SyncResult.FAILURE;
}
ProjectViewSet projectViewSet = workspacePathResolverAndProjectView.projectViewSet;
List<String> syncFlags = BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.INFO, BlazeInvocationContext.Sync);
syncStats.setSyncFlags(syncFlags);
ListenableFuture<BlazeInfo> blazeInfoFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, importSettings.getBuildSystem(), Blaze.getBuildSystemProvider(project).getSyncBinaryPath(), workspaceRoot, syncFlags);
ListenableFuture<WorkingSet> workingSetFuture = vcsHandler.getWorkingSet(project, context, workspaceRoot, executor);
BlazeInfo blazeInfo = FutureUtil.waitForFuture(context, blazeInfoFuture).timed(Blaze.buildSystemName(project) + "Info", EventType.BlazeInvocation).withProgressMessage(String.format("Running %s info...", Blaze.buildSystemName(project))).onError(String.format("Could not run %s info", Blaze.buildSystemName(project))).run().result();
if (blazeInfo == null) {
return SyncResult.FAILURE;
}
BlazeVersionData blazeVersionData = BlazeVersionData.build(importSettings.getBuildSystem(), workspaceRoot, blazeInfo);
if (!BuildSystemVersionChecker.verifyVersionSupported(context, blazeVersionData)) {
return SyncResult.FAILURE;
}
WorkspacePathResolver workspacePathResolver = workspacePathResolverAndProjectView.workspacePathResolver;
ArtifactLocationDecoder artifactLocationDecoder = new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver);
WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
syncStats.setLanguagesActive(new ArrayList<>(workspaceLanguageSettings.activeLanguages));
syncStats.setWorkspaceType(workspaceLanguageSettings.getWorkspaceType());
for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
syncPlugin.installSdks(context);
}
if (!ProjectViewVerifier.verifyProjectView(project, context, workspacePathResolver, projectViewSet, workspaceLanguageSettings)) {
return SyncResult.FAILURE;
}
final BlazeProjectData newBlazeProjectData;
WorkingSet workingSet = FutureUtil.waitForFuture(context, workingSetFuture).timed("WorkingSet", EventType.Other).withProgressMessage("Computing VCS working set...").onError("Could not compute working set").run().result();
if (context.isCancelled()) {
return SyncResult.CANCELLED;
}
if (context.hasErrors()) {
return SyncResult.FAILURE;
}
if (workingSet != null) {
printWorkingSet(context, workingSet);
}
SyncState.Builder syncStateBuilder = new SyncState.Builder();
SyncState previousSyncState = oldBlazeProjectData != null ? oldBlazeProjectData.syncState : null;
List<TargetExpression> targets = Lists.newArrayList();
if (syncParams.addProjectViewTargets) {
Collection<TargetExpression> projectViewTargets = projectViewSet.listItems(TargetSection.KEY);
if (!projectViewTargets.isEmpty()) {
syncStats.setBlazeProjectTargets(new ArrayList<>(projectViewTargets));
targets.addAll(projectViewTargets);
printTargets(context, "project view", projectViewTargets);
}
}
if (syncParams.addWorkingSet && workingSet != null) {
Collection<? extends TargetExpression> workingSetTargets = getWorkingSetTargets(projectViewSet, workingSet);
if (!workingSetTargets.isEmpty()) {
targets.addAll(workingSetTargets);
syncStats.setWorkingSetTargets(new ArrayList<>(workingSetTargets));
printTargets(context, "working set", workingSetTargets);
}
}
if (!syncParams.targetExpressions.isEmpty()) {
targets.addAll(syncParams.targetExpressions);
printTargets(context, syncParams.title, syncParams.targetExpressions);
}
ShardedTargetsResult shardedTargetsResult = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectViewSet, workspacePathResolver, targets);
if (shardedTargetsResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
return SyncResult.FAILURE;
}
ShardedTargetList shardedTargets = shardedTargetsResult.shardedTargets;
syncStats.setSyncSharded(shardedTargets.shardedTargets.size() > 1);
BlazeConfigurationHandler configHandler = new BlazeConfigurationHandler(blazeInfo);
boolean mergeWithOldState = !syncParams.addProjectViewTargets;
BlazeIdeInterface.IdeResult ideQueryResult = getIdeQueryResult(project, context, projectViewSet, blazeVersionData, configHandler, shardedTargets, workspaceLanguageSettings, artifactLocationDecoder, syncStateBuilder, previousSyncState, mergeWithOldState);
if (context.isCancelled()) {
return SyncResult.CANCELLED;
}
context.output(PrintOutput.log("ide-query result: " + ideQueryResult.buildResult.status));
if (ideQueryResult.targetMap == null || ideQueryResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
context.setHasError();
if (ideQueryResult.buildResult.outOfMemory()) {
SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
}
return SyncResult.FAILURE;
}
TargetMap targetMap = ideQueryResult.targetMap;
context.output(PrintOutput.log("Target map size: " + ideQueryResult.targetMap.targets().size()));
BuildResult ideInfoResult = ideQueryResult.buildResult;
ListenableFuture<ImmutableMultimap<TargetKey, TargetKey>> reverseDependenciesFuture = BlazeExecutor.getInstance().submit(() -> ReverseDependencyMap.createRdepsMap(targetMap));
BuildResult ideResolveResult = resolveIdeArtifacts(project, context, workspaceRoot, projectViewSet, blazeVersionData, workspaceLanguageSettings, shardedTargets);
if (ideResolveResult.status == BuildResult.Status.FATAL_ERROR) {
context.setHasError();
if (ideResolveResult.outOfMemory()) {
SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
}
return SyncResult.FAILURE;
}
if (context.isCancelled()) {
return SyncResult.CANCELLED;
}
Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("UpdateSyncState", EventType.Other));
for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
syncPlugin.updateSyncState(project, childContext, workspaceRoot, projectViewSet, workspaceLanguageSettings, blazeInfo, workingSet, workspacePathResolver, artifactLocationDecoder, targetMap, syncStateBuilder, previousSyncState);
}
});
ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = FutureUtil.waitForFuture(context, reverseDependenciesFuture).timed("ReverseDependencies", EventType.Other).onError("Failed to compute reverse dependency map").run().result();
if (reverseDependencies == null) {
return SyncResult.FAILURE;
}
newBlazeProjectData = new BlazeProjectData(syncStartTime, targetMap, blazeInfo, blazeVersionData, workspacePathResolver, artifactLocationDecoder, workspaceLanguageSettings, syncStateBuilder.build(), reverseDependencies);
FileCaches.onSync(project, context, projectViewSet, newBlazeProjectData, syncParams.syncMode);
ListenableFuture<?> prefetch = PrefetchService.getInstance().prefetchProjectFiles(project, projectViewSet, newBlazeProjectData);
FutureUtil.waitForFuture(context, prefetch).withProgressMessage("Prefetching files...").timed("PrefetchFiles", EventType.Prefetching).onError("Prefetch failed").run();
ListenableFuture<DirectoryStructure> directoryStructureFuture = DirectoryStructure.getRootDirectoryStructure(project, workspaceRoot, projectViewSet);
refreshVirtualFileSystem(context, newBlazeProjectData);
DirectoryStructure directoryStructure = FutureUtil.waitForFuture(context, directoryStructureFuture).withProgressMessage("Computing directory structure...").timed("DirectoryStructure", EventType.Other).onError("Directory structure computation failed").run().result();
if (directoryStructure == null) {
return SyncResult.FAILURE;
}
boolean success = updateProject(context, projectViewSet, blazeVersionData, directoryStructure, oldBlazeProjectData, newBlazeProjectData);
if (!success) {
return SyncResult.FAILURE;
}
SyncResult syncResult = SyncResult.SUCCESS;
if (ideInfoResult.status == BuildResult.Status.BUILD_ERROR || ideResolveResult.status == BuildResult.Status.BUILD_ERROR) {
final String errorType = ideInfoResult.status == BuildResult.Status.BUILD_ERROR ? "BUILD file errors" : "compilation errors";
String message = String.format("Sync was successful, but there were %s. " + "The project may not be fully updated or resolve until fixed. " + "If the errors are from your working set, please uncheck " + "'Blaze > Sync > Expand Sync to Working Set' and try again.", errorType);
context.output(PrintOutput.error(message));
IssueOutput.warn(message).submit(context);
syncResult = SyncResult.PARTIAL_SUCCESS;
}
return syncResult;
}
use of com.google.idea.blaze.base.model.SyncState in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImpl method updateTargetMap.
@Override
public IdeResult updateTargetMap(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeVersionData blazeVersionData, BlazeConfigurationHandler configHandler, ShardedTargetList shardedTargets, WorkspaceLanguageSettings workspaceLanguageSettings, ArtifactLocationDecoder artifactLocationDecoder, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState, boolean mergeWithOldState) {
State prevState = previousSyncState != null ? previousSyncState.get(State.class) : null;
// If the language filter has changed, redo everything from scratch
if (prevState != null && !prevState.workspaceLanguageSettings.equals(workspaceLanguageSettings)) {
prevState = null;
}
// If the aspect strategy has changed, redo everything from scratch
final AspectStrategy aspectStrategy = AspectStrategyProvider.findAspectStrategy(blazeVersionData);
if (prevState != null && !Objects.equals(prevState.aspectStrategyName, aspectStrategy.getName())) {
prevState = null;
}
IdeInfoResult ideInfoResult = getIdeInfo(project, context, workspaceRoot, projectViewSet, workspaceLanguageSettings.activeLanguages, shardedTargets, aspectStrategy);
context.output(PrintOutput.log("ide-info result: " + ideInfoResult.buildResult.status));
if (ideInfoResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
return new IdeResult(prevState != null ? prevState.targetMap : null, ideInfoResult.buildResult);
}
// any old state that we have in an attempt not to lose too much code.
if (ideInfoResult.buildResult.status == BuildResult.Status.BUILD_ERROR) {
mergeWithOldState = true;
}
Collection<File> fileList = ideInfoResult.files;
List<File> updatedFiles = Lists.newArrayList();
List<File> removedFiles = Lists.newArrayList();
ImmutableMap<File, Long> fileState = FileDiffer.updateFiles(prevState != null ? prevState.fileState : null, fileList, updatedFiles, removedFiles);
if (fileState == null) {
return new IdeResult(prevState != null ? prevState.targetMap : null, BuildResult.FATAL_ERROR);
}
// if we're merging with the old state, no files are removed
int targetCount = fileList.size() + (mergeWithOldState ? removedFiles.size() : 0);
int removedCount = mergeWithOldState ? 0 : removedFiles.size();
context.output(PrintOutput.log(String.format("Total rules: %d, new/changed: %d, removed: %d", targetCount, updatedFiles.size(), removedCount)));
ListenableFuture<?> prefetchFuture = PrefetchService.getInstance().prefetchFiles(project, updatedFiles, true, false);
if (!FutureUtil.waitForFuture(context, prefetchFuture).timed("FetchAspectOutput", EventType.Prefetching).withProgressMessage("Reading IDE info result...").run().success()) {
return new IdeResult(prevState != null ? prevState.targetMap : null, BuildResult.FATAL_ERROR);
}
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project)).add(projectViewSet).build();
State state = updateState(project, context, prevState, fileState, configHandler, workspaceLanguageSettings, importRoots, aspectStrategy, updatedFiles, removedFiles, mergeWithOldState);
if (state == null) {
return new IdeResult(prevState != null ? prevState.targetMap : null, BuildResult.FATAL_ERROR);
}
syncStateBuilder.put(State.class, state);
return new IdeResult(state.targetMap, ideInfoResult.buildResult);
}
Aggregations