use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class FastBuildIncrementalCompilerImpl method getPathsToCompile.
private Set<File> getPathsToCompile(Label label, TargetMap targetMap, Set<File> modifiedSinceBuild) {
BlazeProjectData projectData = projectDataManager.getBlazeProjectData();
Set<File> sourceFiles = new HashSet<>();
Set<TargetKey> seenTargets = new HashSet<>();
recursivelyAddModifiedJavaSources(projectData.artifactLocationDecoder, targetMap, TargetKey.forPlainTarget(label), seenTargets, sourceFiles, modifiedSinceBuild);
return sourceFiles;
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class FastBuildServiceImpl method buildDeployJar.
private ListenableFuture<FastBuildState.BuildOutput> buildDeployJar(Label label, FastBuildParameters buildParameters) {
Label deployJarLabel = createDeployJarLabel(label);
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
// TODO(plumpy): this assumes we're running this build as part of a run action. I try not to
// make that assumption anywhere else, so this should be supplied by the caller.
BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
AspectStrategy aspectStrategy = AspectStrategyProvider.findAspectStrategy(projectDataManager.getBlazeProjectData().blazeVersionData);
BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> file.endsWith(deployJarLabel.targetName().toString()) || aspectStrategy.getAspectOutputFilePredicate().test(file));
ListenableFuture<BuildResult> buildResultFuture = ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {
@Override
protected BuildResult execute(BlazeContext context) {
context.push(new IssuesScope(project, /* focusProblemsViewOnIssue */
true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
context.output(new StatusOutput("Building base deploy jar for fast builds: " + deployJarLabel.targetName()));
BlazeCommand.Builder command = BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD).addTargets(label).addTargets(deployJarLabel).addBlazeFlags(buildParameters.blazeFlags()).addBlazeFlags(buildResultHelper.getBuildFlags());
List<String> outputGroups = new ArrayList<>();
// needed to retrieve the deploy jar
outputGroups.add("default");
outputGroups.addAll(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
aspectStrategy.addAspectAndOutputGroups(command, outputGroups);
int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
return BuildResult.fromExitCode(exitCode);
}
});
ListenableFuture<BuildOutput> buildOutputFuture = transform(buildResultFuture, result -> {
if (result.status != Status.SUCCESS) {
throw new RuntimeException("Blaze failure building deploy jar");
}
ImmutableList<File> deployJarArtifacts = buildResultHelper.getBuildArtifactsForTarget(deployJarLabel);
checkState(deployJarArtifacts.size() == 1);
File deployJar = deployJarArtifacts.get(0);
ImmutableList<File> ideInfoFiles = buildResultHelper.getArtifactsForOutputGroups(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
ImmutableMap<TargetKey, TargetIdeInfo> targetMap = ideInfoFiles.stream().map(file -> readTargetIdeInfo(aspectStrategy, file)).filter(Objects::nonNull).collect(toImmutableMap(ideInfo -> ideInfo.key, i -> i));
return BuildOutput.create(deployJar, new TargetMap(targetMap));
}, ConcurrencyUtil.getAppExecutorService());
buildOutputFuture.addListener(buildResultHelper::close, ConcurrencyUtil.getAppExecutorService());
return buildOutputFuture;
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeResolveConfiguration method representMultipleTargets.
/**
* Indicate that this single configuration represents N other targets. NOTE: this changes the
* identifier used by {@link #compareTo}, so any data structures using compareTo must be
* invalidated when this changes.
*/
void representMultipleTargets(Collection<TargetKey> targets) {
TargetKey minTargetKey = targets.stream().min(TargetKey::compareTo).orElse(null);
Preconditions.checkNotNull(minTargetKey);
String minTarget = minTargetKey.toString();
if (targets.size() == 1) {
displayNameIdentifier = minTarget;
} else {
displayNameIdentifier = String.format("%s and %d other target(s)", minTarget, targets.size() - 1);
}
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeCreateResourceUtils method setupResDirectoryChoices.
static void setupResDirectoryChoices(Project project, @Nullable VirtualFile contextFile, JBLabel resDirLabel, ComboboxWithBrowseButton resDirComboAndBrowser) {
// Reset the item list before filling it back up.
resDirComboAndBrowser.getComboBox().removeAllItems();
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData != null) {
BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
if (syncData != null) {
ImmutableCollection<TargetKey> rulesRelatedToContext = null;
File fileFromContext = null;
if (contextFile != null) {
fileFromContext = VfsUtilCore.virtualToIoFile(contextFile);
rulesRelatedToContext = SourceToTargetMap.getInstance(project).getRulesForSourceFile(fileFromContext);
if (rulesRelatedToContext.isEmpty()) {
rulesRelatedToContext = null;
}
}
ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
// Sort:
// - contextFile/res if contextFile is a directory,
// to optimize the right click on directory case, or the "closest" string
// match to the contextFile from the res directories known to blaze
// - the rest of the direct dirs, then transitive dirs of the context rules,
// then any known res dir in the project
// as a backup, in alphabetical order.
Set<File> resourceDirs = Sets.newTreeSet();
Set<File> transitiveDirs = Sets.newTreeSet();
Set<File> allResDirs = Sets.newTreeSet();
for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
Collection<File> resources = artifactLocationDecoder.decodeAll(androidResourceModule.resources);
Collection<File> transitiveResources = artifactLocationDecoder.decodeAll(androidResourceModule.transitiveResources);
// labelsRelatedToContext should include deps,
// but as a first pass we only check the rules themselves
// for resources. If we come up empty, then have anyResDir as a backup.
allResDirs.addAll(transitiveResources);
if (rulesRelatedToContext != null && !rulesRelatedToContext.contains(androidResourceModule.targetKey)) {
continue;
}
resourceDirs.addAll(resources);
transitiveDirs.addAll(transitiveResources);
}
// No need to show some directories twice.
transitiveDirs.removeAll(resourceDirs);
JComboBox resDirCombo = resDirComboAndBrowser.getComboBox();
// Allow the user to browse and overwrite some of the entries,
// in case our inference is wrong.
resDirCombo.setEditable(true);
// After the use confirms the choice, a directory will be created if it is missing.
if (fileFromContext != null && fileFromContext.isDirectory()) {
File closestDirToContext = new File(fileFromContext.getPath(), "res");
resDirCombo.setSelectedItem(closestDirToContext);
} else {
// If we're not completely sure, let people know there are options
// via the placeholder text, and put the most likely on top.
String placeHolder = PLACEHOLDER_TEXT;
resDirCombo.addItem(placeHolder);
resDirCombo.setSelectedItem(placeHolder);
if (fileFromContext != null) {
File closestDirToContext = findClosestDirToContext(fileFromContext.getPath(), resourceDirs);
closestDirToContext = closestDirToContext != null ? closestDirToContext : findClosestDirToContext(fileFromContext.getPath(), transitiveDirs);
if (closestDirToContext != null) {
resDirCombo.addItem(closestDirToContext);
resourceDirs.remove(closestDirToContext);
transitiveDirs.remove(closestDirToContext);
}
}
}
if (!resourceDirs.isEmpty() || !transitiveDirs.isEmpty()) {
for (File resourceDir : resourceDirs) {
resDirCombo.addItem(resourceDir);
}
for (File resourceDir : transitiveDirs) {
resDirCombo.addItem(resourceDir);
}
} else {
for (File resourceDir : allResDirs) {
resDirCombo.addItem(resourceDir);
}
}
resDirComboAndBrowser.setVisible(true);
resDirLabel.setVisible(true);
}
}
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImpl method updateState.
@Nullable
static State updateState(Project project, BlazeContext parentContext, @Nullable State prevState, ImmutableMap<File, Long> fileState, BlazeConfigurationHandler configHandler, WorkspaceLanguageSettings workspaceLanguageSettings, ImportRoots importRoots, AspectStrategy aspectStrategy, List<File> newFiles, List<File> removedFiles, boolean mergeWithOldState) {
Result<State> result = Scope.push(parentContext, (ScopedFunction<Result<State>>) context -> {
context.push(new TimingScope("UpdateTargetMap", EventType.Other));
ImmutableMap<File, Long> nextFileState = fileState;
if (mergeWithOldState && prevState != null) {
ImmutableMap.Builder<File, Long> fileStateBuilder = ImmutableMap.<File, Long>builder().putAll(fileState);
for (Map.Entry<File, Long> entry : prevState.fileState.entrySet()) {
if (!fileState.containsKey(entry.getKey())) {
fileStateBuilder.put(entry);
}
}
nextFileState = fileStateBuilder.build();
}
State state = new State();
state.fileState = nextFileState;
state.workspaceLanguageSettings = workspaceLanguageSettings;
state.aspectStrategyName = aspectStrategy.getName();
Map<TargetKey, TargetIdeInfo> targetMap = Maps.newHashMap();
if (prevState != null) {
targetMap.putAll(prevState.targetMap.map());
state.fileToTargetMapKey.putAll(prevState.fileToTargetMapKey);
}
if (!mergeWithOldState) {
for (File removedFile : removedFiles) {
TargetKey key = state.fileToTargetMapKey.remove(removedFile);
if (key != null) {
targetMap.remove(key);
}
}
}
AtomicLong totalSizeLoaded = new AtomicLong(0);
Set<LanguageClass> ignoredLanguages = Sets.newConcurrentHashSet();
ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor();
List<ListenableFuture<TargetFilePair>> futures = Lists.newArrayList();
for (File file : newFiles) {
futures.add(executor.submit(() -> {
totalSizeLoaded.addAndGet(file.length());
IntellijIdeInfo.TargetIdeInfo message = aspectStrategy.readAspectFile(file);
TargetIdeInfo target = protoToTarget(workspaceLanguageSettings, importRoots, message, ignoredLanguages);
return new TargetFilePair(file, target);
}));
}
Set<TargetKey> newTargets = new HashSet<>();
Set<String> configurations = new LinkedHashSet<>();
configurations.add(configHandler.defaultConfigurationPathComponent);
int duplicateTargetLabels = 0;
try {
for (TargetFilePair targetFilePair : Futures.allAsList(futures).get()) {
if (targetFilePair.target != null) {
File file = targetFilePair.file;
String config = configHandler.getConfigurationPathComponent(file);
configurations.add(config);
TargetKey key = targetFilePair.target.key;
if (targetMap.putIfAbsent(key, targetFilePair.target) == null) {
state.fileToTargetMapKey.forcePut(file, key);
} else {
if (!newTargets.add(key)) {
duplicateTargetLabels++;
}
if (Objects.equals(config, configHandler.defaultConfigurationPathComponent)) {
targetMap.put(key, targetFilePair.target);
state.fileToTargetMapKey.forcePut(file, key);
}
}
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return Result.error(null);
} catch (ExecutionException e) {
return Result.error(e);
}
context.output(PrintOutput.log(String.format("Loaded %d aspect files, total size %dkB", newFiles.size(), totalSizeLoaded.get() / 1024)));
if (duplicateTargetLabels > 0) {
context.output(new PerformanceWarning(String.format("There were %d duplicate rules, built with the following " + "configurations: %s.\nYour IDE sync is slowed down by ~%d%%.", duplicateTargetLabels, configurations, (100 * duplicateTargetLabels / targetMap.size()))));
}
ignoredLanguages.retainAll(LanguageSupport.availableAdditionalLanguages(workspaceLanguageSettings.getWorkspaceType()));
warnIgnoredLanguages(project, context, ignoredLanguages);
state.targetMap = new TargetMap(ImmutableMap.copyOf(targetMap));
return Result.of(state);
});
if (result.error != null) {
logger.error(result.error);
return null;
}
return result.result;
}
Aggregations