Search in sources :

Example 36 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeCidrRunConfigurationRunner method getExecutableToDebug.

/**
 * Builds blaze C/C++ target in debug mode, and returns the output build artifact.
 *
 * @throws ExecutionException if no unique output artifact was found.
 */
private File getExecutableToDebug() throws ExecutionException {
    BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true);
    ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, ImmutableList.of("-c", "dbg", "--copt=-O0", "--copt=-g", "--strip=never"), ImmutableList.of("--dynamic_mode=off"), "Building debug binary");
    try {
        SaveUtil.saveAllFiles();
        BuildResult result = buildOperation.get();
        if (result.status != BuildResult.Status.SUCCESS) {
            throw new ExecutionException("Blaze failure building debug binary");
        }
    } catch (InterruptedException | CancellationException e) {
        buildOperation.cancel(true);
        throw new RunCanceledByUserException();
    } catch (java.util.concurrent.ExecutionException e) {
        throw new ExecutionException(e);
    }
    List<File> candidateFiles = buildResultHelper.getBuildArtifactsForTarget((Label) configuration.getTarget()).stream().filter(File::canExecute).collect(Collectors.toList());
    if (candidateFiles.isEmpty()) {
        throw new ExecutionException(String.format("No output artifacts found when building %s", configuration.getTarget()));
    }
    File file = findExecutable((Label) configuration.getTarget(), candidateFiles);
    if (file == null) {
        throw new ExecutionException(String.format("More than 1 executable was produced when building %s; don't know which one to debug", configuration.getTarget()));
    }
    LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
    return file;
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 37 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeCommandRunConfigurationRunManagerImplTest method loadStateAndGetStateElementShouldMatchAfterChangeAndRevert.

@Test
public void loadStateAndGetStateElementShouldMatchAfterChangeAndRevert() {
    final XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat());
    final Label label = Label.create("//package:rule");
    configuration.setTarget(label);
    final Element initialElement = runManager.getState();
    runManager.loadState(initialElement);
    final BlazeCommandRunConfiguration modifiedConfiguration = (BlazeCommandRunConfiguration) runManager.getAllConfigurations()[0];
    modifiedConfiguration.setTarget(Label.create("//new:label"));
    final Element modifiedElement = runManager.getState();
    assertThat(xmlOutputter.outputString(modifiedElement)).isNotEqualTo(xmlOutputter.outputString(initialElement));
    runManager.loadState(modifiedElement);
    final BlazeCommandRunConfiguration revertedConfiguration = (BlazeCommandRunConfiguration) runManager.getAllConfigurations()[0];
    revertedConfiguration.setTarget(label);
    final Element revertedElement = runManager.getState();
    assertThat(xmlOutputter.outputString(revertedElement)).isEqualTo(xmlOutputter.outputString(initialElement));
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) Label(com.google.idea.blaze.base.model.primitives.Label) Test(org.junit.Test)

Example 38 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeCommandRunConfigurationRunManagerImplTest method loadStateAndGetStateShouldMatch.

@Test
public void loadStateAndGetStateShouldMatch() {
    final Label label = Label.create("//package:rule");
    configuration.setTarget(label);
    final Element element = runManager.getState();
    runManager.loadState(element);
    final RunConfiguration[] configurations = runManager.getAllConfigurations();
    assertThat(configurations).hasLength(1);
    assertThat(configurations[0]).isInstanceOf(BlazeCommandRunConfiguration.class);
    final BlazeCommandRunConfiguration readConfiguration = (BlazeCommandRunConfiguration) configurations[0];
    assertThat(readConfiguration.getTarget()).isEqualTo(label);
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) Element(org.jdom.Element) Label(com.google.idea.blaze.base.model.primitives.Label) Test(org.junit.Test)

Example 39 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeCommandRunConfigurationTest method readAndWriteShouldMatch.

@Test
public void readAndWriteShouldMatch() throws Exception {
    Label label = Label.create("//package:rule");
    configuration.setTarget(label);
    Element element = new Element("test");
    configuration.writeExternal(element);
    BlazeCommandRunConfiguration readConfiguration = type.getFactory().createTemplateConfiguration(project);
    readConfiguration.readExternal(element);
    assertThat(readConfiguration.getTarget()).isEqualTo(label);
}
Also used : Element(org.jdom.Element) Label(com.google.idea.blaze.base.model.primitives.Label) Test(org.junit.Test)

Example 40 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class TransitiveDependencyMapTest method buildTargetMap.

private static TargetMap buildTargetMap() {
    Label simpleA = Label.create("//com/google/example/simple:a");
    Label simpleB = Label.create("//com/google/example/simple:b");
    Label chainA = Label.create("//com/google/example/chain:a");
    Label chainB = Label.create("//com/google/example/chain:b");
    Label chainC = Label.create("//com/google/example/chain:c");
    Label chainD = Label.create("//com/google/example/chain:d");
    Label diamondA = Label.create("//com/google/example/diamond:a");
    Label diamondB = Label.create("//com/google/example/diamond:b");
    Label diamondBB = Label.create("//com/google/example/diamond:bb");
    Label diamondBBB = Label.create("//com/google/example/diamond:bbb");
    Label diamondC = Label.create("//com/google/example/diamond:c");
    Label diamondCC = Label.create("//com/google/example/diamond:cc");
    Label diamondCCC = Label.create("//com/google/example/diamond:ccc");
    return TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(simpleA).addDependency(simpleB)).addTarget(TargetIdeInfo.builder().setLabel(simpleB)).addTarget(TargetIdeInfo.builder().setLabel(chainA).addDependency(chainB)).addTarget(TargetIdeInfo.builder().setLabel(chainB).addDependency(chainC)).addTarget(TargetIdeInfo.builder().setLabel(chainC).addDependency(chainD)).addTarget(TargetIdeInfo.builder().setLabel(chainD)).addTarget(TargetIdeInfo.builder().setLabel(diamondA).addDependency(diamondB).addDependency(diamondBB).addDependency(diamondBBB)).addTarget(TargetIdeInfo.builder().setLabel(diamondB).addDependency(diamondC)).addTarget(TargetIdeInfo.builder().setLabel(diamondBB).addDependency(diamondC).addDependency(diamondCC)).addTarget(TargetIdeInfo.builder().setLabel(diamondBBB).addDependency(diamondC).addDependency(diamondCC).addDependency(diamondCCC)).addTarget(TargetIdeInfo.builder().setLabel(diamondC)).addTarget(TargetIdeInfo.builder().setLabel(diamondCC)).addTarget(TargetIdeInfo.builder().setLabel(diamondCCC)).build();
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label)

Aggregations

Label (com.google.idea.blaze.base.model.primitives.Label)48 File (java.io.File)15 Test (org.junit.Test)11 Nullable (javax.annotation.Nullable)8 BlazeTestResults (com.google.idea.blaze.base.run.testlogs.BlazeTestResults)7 BuildEventStreamProtos (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos)6 BlazeTestResult (com.google.idea.blaze.base.run.testlogs.BlazeTestResult)6 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 Kind (com.google.idea.blaze.base.model.primitives.Kind)5 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)4 BuildEvent (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEvent)3 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)3 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)3 SourceToTargetMap (com.google.idea.blaze.base.targetmaps.SourceToTargetMap)3