Search in sources :

Example 6 with TargetExpression

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;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeAndroidRunConfigurationHandler(com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey)

Example 7 with TargetExpression

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);
}
Also used : BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ImmutableList(com.google.common.collect.ImmutableList) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) RuleTypeAndLabel(com.google.idea.blaze.base.sync.sharding.QueryResultLineProcessor.RuleTypeAndLabel) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult)

Example 8 with TargetExpression

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Example 9 with TargetExpression

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Example 10 with TargetExpression

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);
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ExternalTask(com.google.idea.blaze.base.async.process.ExternalTask) AdditionalLanguagesHelper(com.google.idea.blaze.base.lang.AdditionalLanguagesHelper) Result(com.google.idea.blaze.base.scope.Result) LanguageSupport(com.google.idea.blaze.base.sync.projectview.LanguageSupport) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) ScopedFunction(com.google.idea.blaze.base.scope.ScopedFunction) Map(java.util.Map) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) IntellijIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo) FileDiffer(com.google.idea.blaze.base.filecache.FileDiffer) BlazeConsoleLineProcessorProvider(com.google.idea.blaze.base.console.BlazeConsoleLineProcessorProvider) Blaze(com.google.idea.blaze.base.settings.Blaze) BiMap(com.google.common.collect.BiMap) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AspectStrategy(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy) Predicate(java.util.function.Predicate) Collection(java.util.Collection) BuildSystemProvider(com.google.idea.blaze.base.bazel.BuildSystemProvider) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) Set(java.util.Set) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Sets(com.google.common.collect.Sets) Serializable(java.io.Serializable) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) Objects(java.util.Objects) List(java.util.List) LineProcessingOutputStream(com.google.idea.blaze.base.async.process.LineProcessingOutputStream) Status(com.google.idea.blaze.base.sync.aspects.BuildResult.Status) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Joiner(com.google.common.base.Joiner) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AspectStrategyProvider(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyProvider) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NavigatableAdapter(com.intellij.pom.NavigatableAdapter) HashSet(java.util.HashSet) Kind(com.google.idea.blaze.base.model.primitives.Kind) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) Scope(com.google.idea.blaze.base.scope.Scope) OutputGroup(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) PerformanceWarning(com.google.idea.blaze.base.scope.output.PerformanceWarning) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) PrefetchFileSource(com.google.idea.blaze.base.prefetch.PrefetchFileSource) SyncState(com.google.idea.blaze.base.model.SyncState) Maps(com.google.common.collect.Maps) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashBiMap(com.google.common.collect.HashBiMap) Futures(com.google.common.util.concurrent.Futures) Ordering(com.google.common.collect.Ordering) BlazeVersionData(com.google.idea.blaze.base.model.BlazeVersionData) BlazeConfigurationHandler(com.google.idea.blaze.base.command.info.BlazeConfigurationHandler) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeFlags(com.google.idea.blaze.base.command.BlazeFlags) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) List(java.util.List) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) File(java.io.File)

Aggregations

TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)31 Test (org.junit.Test)11 WildcardTargetPattern (com.google.idea.blaze.base.model.primitives.WildcardTargetPattern)10 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)8 File (java.io.File)6 Label (com.google.idea.blaze.base.model.primitives.Label)5 ImmutableList (com.google.common.collect.ImmutableList)3 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)3 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)2 BuildSystemProvider (com.google.idea.blaze.base.bazel.BuildSystemProvider)2 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)2 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)2 Kind (com.google.idea.blaze.base.model.primitives.Kind)2