use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class BlazeAndroidProjectStructureSyncer method getRunConfigurationTargets.
// Collect potential android run configuration targets
private static List<TargetIdeInfo> getRunConfigurationTargets(Project project, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Set<TargetKey> androidResourceModules) {
List<TargetIdeInfo> result = Lists.newArrayList();
Set<Label> runConfigurationModuleTargets = Sets.newHashSet();
// Doing this now will cut down on root changes later
for (TargetExpression targetExpression : projectViewSet.listItems(TargetSection.KEY)) {
if (!(targetExpression instanceof Label)) {
continue;
}
Label label = (Label) targetExpression;
runConfigurationModuleTargets.add(label);
}
// Get any pre-existing targets
for (RunConfiguration runConfiguration : RunManager.getInstance(project).getAllConfigurationsList()) {
BlazeAndroidRunConfigurationHandler handler = BlazeAndroidRunConfigurationHandler.getHandlerFrom(runConfiguration);
if (handler == null) {
continue;
}
runConfigurationModuleTargets.add(handler.getLabel());
}
for (Label label : runConfigurationModuleTargets) {
TargetKey targetKey = TargetKey.forPlainTarget(label);
// If it's a resource module, it will already have been created
if (androidResourceModules.contains(targetKey)) {
continue;
}
// Ensure the label is a supported android rule that exists
TargetIdeInfo target = blazeProjectData.targetMap.get(targetKey);
if (target == null) {
continue;
}
if (!target.kindIsOneOf(Kind.ANDROID_BINARY, Kind.ANDROID_TEST)) {
continue;
}
result.add(target);
}
return result;
}
use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class WildcardTargetExpander method queryIndividualTargets.
/**
* Runs a blaze query to expand the input target patterns to individual blaze targets.
*/
private static ExpandedTargetsResult queryIndividualTargets(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ImmutableSet<String> handledRuleTypes, List<TargetExpression> targetPatterns) {
String query = queryString(targetPatterns);
if (query.isEmpty()) {
// will be empty if there are no non-excluded targets
return new ExpandedTargetsResult(ImmutableList.of(), BuildResult.SUCCESS);
}
BlazeCommand.Builder builder = BlazeCommand.builder(getBinaryPath(project), BlazeCommandName.QUERY).addBlazeFlags(BlazeFlags.KEEP_GOING).addBlazeFlags("--output=label_kind").addBlazeFlags(queryString(targetPatterns));
ImmutableList.Builder<TargetExpression> output = ImmutableList.builder();
// it's fine to include wildcards here; they're guaranteed not to clash with actual labels.
Set<String> explicitTargets = targetPatterns.stream().map(TargetExpression::toString).collect(Collectors.toSet());
Predicate<RuleTypeAndLabel> filter = !filterByRuleType.getValue() ? t -> true : t -> handledRuleTypes.contains(t.ruleType) || explicitTargets.contains(t.label);
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(builder.build()).context(context).stdout(LineProcessingOutputStream.of(new QueryResultLineProcessor(output, filter))).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
BuildResult buildResult = BuildResult.fromExitCode(retVal);
return new ExpandedTargetsResult(output.build(), buildResult);
}
use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class PartialSyncAction method updateForBlazeProject.
@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
VirtualFile virtualFile = getSelectedFile(e);
List<TargetExpression> targets = getTargets(project, virtualFile);
ActionPresentationHelper.of(e).disableIf(BlazeSyncStatus.getInstance(project).syncInProgress()).disableIf(targets.isEmpty()).setTextWithSubject("Partially Sync File", "Partially Sync %s", virtualFile).disableWithoutSubject().hideInContextMenuIfDisabled().commit();
}
use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class PartialSyncAction method actionPerformedInBlazeProject.
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
VirtualFile virtualFile = getSelectedFile(e);
List<TargetExpression> targets = getTargets(project, virtualFile);
BlazeSyncManager.getInstance(project).partialSync(targets);
}
use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImpl method getIdeInfo.
private static IdeInfoResult getIdeInfo(Project project, BlazeContext parentContext, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, ImmutableSet<LanguageClass> activeLanguages, ShardedTargetList shardedTargets, AspectStrategy aspectStrategy) {
return Scope.push(parentContext, context -> {
context.push(new TimingScope(String.format("Execute%sCommand", Blaze.buildSystemName(project)), EventType.BlazeInvocation));
Set<File> ideInfoFiles = new LinkedHashSet<>();
Function<Integer, String> progressMessage = count -> String.format("Building IDE info files for shard %s of %s...", count, shardedTargets.shardedTargets.size());
Function<List<TargetExpression>, BuildResult> invocation = targets -> {
IdeInfoResult result = getIdeInfoForTargets(project, context, workspaceRoot, projectViewSet, activeLanguages, targets, aspectStrategy);
ideInfoFiles.addAll(result.files);
return result.buildResult;
};
BuildResult result = shardedTargets.runShardedCommand(project, context, progressMessage, invocation);
return new IdeInfoResult(ideInfoFiles, result);
});
}
Aggregations