Search in sources :

Example 16 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeConfigurationResolverTest method testTargetWithMixedSources.

@Test
public void testTargetWithMixedSources() {
    ProjectView projectView = projectView(directories("foo/bar"), targets("//foo/bar:binary"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo/bar:binary", Kind.CC_BINARY, ImmutableList.of(src("foo/bar/binary.cc"), gen("foo/bar/generated.cc")))).build();
    assertThatResolving(projectView, targetMap).producesConfigurationsFor("//foo/bar:binary");
}
Also used : ProjectView(com.google.idea.blaze.base.projectview.ProjectView) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 17 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeConfigurationResolverTest method testSingleSourceTargetWithSourceDependencies.

@Test
public void testSingleSourceTargetWithSourceDependencies() {
    ProjectView projectView = projectView(directories("foo/bar"), targets("//foo/bar:binary"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo/bar:binary", Kind.CC_BINARY, ImmutableList.of(src("foo/bar/binary.cc"))).addDependency("//foo/bar:library").addDependency("//third_party:library")).addTarget(createCcTarget("//foo/bar:library", Kind.CC_LIBRARY, ImmutableList.of(src("foo/bar/library.cc")), ImmutableList.of("SOME_DEFINE=1"))).addTarget(createCcTarget("//third_party:library", Kind.CC_LIBRARY, ImmutableList.of(src("third_party/library.cc")))).build();
    assertThatResolving(projectView, targetMap).producesConfigurationsFor("//foo/bar:binary", "//foo/bar:library");
}
Also used : ProjectView(com.google.idea.blaze.base.projectview.ProjectView) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 18 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeConfigurationResolverTest method testComplexProject.

@Test
public void testComplexProject() {
    ProjectView projectView = projectView(directories("foo/bar", "foo/baz"), targets("//foo:test", "//foo/bar:binary", "//foo/baz:test"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo:test", Kind.CC_TEST, ImmutableList.of(src("foo/test.cc"))).addDependency("//foo:library").addDependency("//foo/bar:library").addDependency("//third_party:library")).addTarget(createCcTarget("//foo:library", Kind.CC_TEST, ImmutableList.of(src("foo/library.cc")))).addTarget(createCcTarget("//foo/bar:binary", Kind.CC_BINARY, ImmutableList.of(src("foo/bar/binary.cc")), ImmutableList.of("SOME_DEFINE=1")).addDependency("//foo/bar:library").addDependency("//foo/bar:empty").addDependency("//foo/bar:generated").addDependency("//foo/bar:mixed").addDependency("//third_party:library")).addTarget(createCcTarget("//foo/bar:library", Kind.CC_LIBRARY, ImmutableList.of(src("foo/bar/library.cc")), ImmutableList.of("SOME_DEFINE=2"))).addTarget(createCcTarget("//foo/bar:empty", Kind.CC_LIBRARY, ImmutableList.of())).addTarget(createCcTarget("//foo/bar:generated", Kind.CC_LIBRARY, ImmutableList.of(gen("foo/bar/generated.cc")))).addTarget(createCcTarget("//foo/bar:mixed", Kind.CC_LIBRARY, ImmutableList.of(src("foo/bar/mixed_src.cc"), gen("foo/bar/mixed_gen.cc")), ImmutableList.of("SOME_DEFINE=3"))).addTarget(createCcTarget("//foo/baz:test", Kind.CC_TEST, ImmutableList.of(src("foo/baz/test.cc")), ImmutableList.of("SOME_DEFINE=4")).addDependency("//foo/baz:binary").addDependency("//foo/baz:library").addDependency("//foo/qux:library")).addTarget(createCcTarget("//foo/baz:binary", Kind.CC_BINARY, ImmutableList.of(src("foo/baz/binary.cc")), ImmutableList.of("SOME_DEFINE=5"))).addTarget(createCcTarget("//foo/baz:library", Kind.CC_LIBRARY, ImmutableList.of(src("foo/baz/library.cc")), ImmutableList.of("SOME_DEFINE=6"))).addTarget(createCcTarget("//foo/qux:library", Kind.CC_LIBRARY, ImmutableList.of(src("foo/qux/library.cc")))).addTarget(createCcTarget("//third_party:library", Kind.CC_LIBRARY, ImmutableList.of(src("third_party/library.cc")))).build();
    assertThatResolving(projectView, targetMap).producesConfigurationsFor("//foo/bar:binary", "//foo/bar:library", "//foo/bar:mixed", "//foo/baz:test", "//foo/baz:binary", "//foo/baz:library");
}
Also used : ProjectView(com.google.idea.blaze.base.projectview.ProjectView) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 19 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeResolveConfigurationEquivalenceTest method testEmptyConfigurations.

@Test
public void testEmptyConfigurations() {
    ProjectView projectView = projectView(directories("foo/bar"), targets("//foo/bar:one", "//foo/bar:two", "//foo/bar:three"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(createCcToolchain()).addTarget(createCcTarget("//foo/bar:one", Kind.CC_BINARY, sources("foo/bar/one.cc"), defines(), includes())).addTarget(createCcTarget("//foo/bar:two", Kind.CC_BINARY, sources("foo/bar/two.cc"), defines(), includes())).addTarget(createCcTarget("//foo/bar:three", Kind.CC_BINARY, sources("foo/bar/three.cc"), defines(), includes())).build();
    List<BlazeResolveConfiguration> configurations = resolve(projectView, targetMap);
    assertThat(configurations).hasSize(1);
    assertThat(get(configurations, "//foo/bar:one and 2 other target(s)")).isNotNull();
    for (BlazeResolveConfiguration configuration : configurations) {
        assertThat(configuration.getProjectHeadersRoots().getRoots()).isEmpty();
        assertThat(getHeaders(configuration, OCLanguageKind.CPP)).isEmpty();
        assertThat(configuration.getCompilerMacros()).isEqualTo(macros());
    }
}
Also used : ProjectView(com.google.idea.blaze.base.projectview.ProjectView) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 20 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap 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;
}
Also used : ExternalTask(com.google.idea.blaze.base.async.process.ExternalTask) InvokeAfterUpdateMode(com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode) ModalityState(com.intellij.openapi.application.ModalityState) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) ProjectManager(com.intellij.openapi.project.ProjectManager) FileUtil(com.intellij.openapi.util.io.FileUtil) GuavaHelper.toImmutableMap(com.google.idea.common.guava.GuavaHelper.toImmutableMap) ConcurrencyUtil(com.google.idea.common.concurrency.ConcurrencyUtil) BlazeConsoleLineProcessorProvider(com.google.idea.blaze.base.console.BlazeConsoleLineProcessorProvider) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) BuildOutput(com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AspectStrategy(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) CancellationException(java.util.concurrent.CancellationException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) Preconditions.checkState(com.google.common.base.Preconditions.checkState) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) List(java.util.List) LineProcessingOutputStream(com.google.idea.blaze.base.async.process.LineProcessingOutputStream) Status(com.google.idea.blaze.base.sync.aspects.BuildResult.Status) Stream(java.util.stream.Stream) 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) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) 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) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Kind(com.google.idea.blaze.base.model.primitives.Kind) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) ImmutableList(com.google.common.collect.ImmutableList) OutputGroup(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior) Project(com.intellij.openapi.project.Project) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) IOException(java.io.IOException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) BlazeFlags(com.google.idea.blaze.base.command.BlazeFlags) ProgressiveTaskWithProgressIndicator(com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) IdeInfoFromProtobuf(com.google.idea.blaze.base.sync.aspects.IdeInfoFromProtobuf) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Label(com.google.idea.blaze.base.model.primitives.Label) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BuildOutput(com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) AspectStrategy(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)77 Test (org.junit.Test)56 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)33 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)17 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)16 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)10 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)10 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 File (java.io.File)10 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)9 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)8 ImmutableSet (com.google.common.collect.ImmutableSet)7