Search in sources :

Example 1 with ParsedBepOutput

use of com.google.idea.blaze.base.command.buildresult.ParsedBepOutput in project intellij by bazelbuild.

the class BlazeApkDeployInfoProtoHelper method readDeployInfoProtoForTarget.

public AndroidDeployInfo readDeployInfoProtoForTarget(Label target, BuildResultHelper buildResultHelper, Predicate<String> pathFilter) throws GetDeployInfoException {
    ImmutableList<File> deployInfoFiles;
    try {
        deployInfoFiles = BlazeArtifact.getLocalFiles(buildResultHelper.getBuildArtifactsForTarget(target, pathFilter));
    } catch (GetArtifactsException e) {
        throw new GetDeployInfoException(e.getMessage());
    }
    if (deployInfoFiles.isEmpty()) {
        Logger log = Logger.getInstance(BlazeApkDeployInfoProtoHelper.class.getName());
        try {
            ParsedBepOutput bepOutput = buildResultHelper.getBuildOutput();
            log.warn("Local execroot: " + bepOutput.getLocalExecRoot());
            log.warn("All output artifacts:");
            for (OutputArtifact outputArtifact : bepOutput.getAllOutputArtifacts(path -> true)) {
                log.warn(outputArtifact.getKey() + " -> " + outputArtifact.getRelativePath());
            }
            log.warn("All local artifacts for " + target + ":");
            List<OutputArtifact> allBuildArtifacts = buildResultHelper.getBuildArtifactsForTarget(target, path -> true);
            List<File> allLocalFiles = BlazeArtifact.getLocalFiles(allBuildArtifacts);
            for (File file : allLocalFiles) {
                String path = file.getPath();
                log.warn(path);
                if (pathFilter.test(path)) {
                    log.warn("Note: " + path + " passes pathFilter but was not recognized!");
                }
            }
        } catch (GetArtifactsException e) {
            log.warn("Error occured when gathering logs:", e);
        }
        throw new GetDeployInfoException("No deploy info proto artifact found.  Was android_deploy_info in the output groups?");
    }
    if (deployInfoFiles.size() > 1) {
        throw new GetDeployInfoException("More than one deploy info proto artifact found: " + deployInfoFiles.stream().map(File::getPath).collect(Collectors.joining(", ", "[", "]")));
    }
    try (InputStream inputStream = new FileInputStream(deployInfoFiles.get(0))) {
        return AndroidDeployInfo.parseFrom(inputStream);
    } catch (IOException e) {
        throw new GetDeployInfoException(e.getMessage());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) IOException(java.io.IOException) Logger(com.intellij.openapi.diagnostic.Logger) FileInputStream(java.io.FileInputStream) GetArtifactsException(com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) File(java.io.File)

Example 2 with ParsedBepOutput

use of com.google.idea.blaze.base.command.buildresult.ParsedBepOutput in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method nullExecRoot.

@Test
public void nullExecRoot() throws Exception {
    // Return null execroot
    when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, null, null, null, 0, BuildResult.SUCCESS));
    // Mobile-install build step requires only one device be active.  DeviceFutures class is final,
    // so we have to make one with a stub AndroidDevice.
    DeviceFutures deviceFutures = new DeviceFutures(ImmutableList.of(new FakeDevice()));
    // Return fake deploy info proto and mocked deploy info data object.
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(getProject(), new File(getExecRoot()), fakeProto)).thenReturn(mockDeployInfo);
    // Perform
    MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, blazeFlags, execFlags, helper);
    buildStep.build(context, new DeviceSession(null, deviceFutures, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Could not locate execroot!");
}
Also used : AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) MobileInstallBuildStep(com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) File(java.io.File) Test(org.junit.Test)

Example 3 with ParsedBepOutput

use of com.google.idea.blaze.base.command.buildresult.ParsedBepOutput in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method setupBuildResultHelperProvider.

/**
 * Setup build result helper to return BEP output with test execroot by default.
 */
@Before
public void setupBuildResultHelperProvider() throws GetArtifactsException {
    mockBuildResultHelper = mock(BuildResultHelper.class);
    when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, getExecRoot(), null, null, 0, BuildResult.SUCCESS));
    registerExtension(BuildResultHelperProvider.EP_NAME, new BuildResultHelperProvider() {

        @Override
        public Optional<BuildResultHelper> doCreate(Project project, BlazeInfo blazeInfo) {
            return Optional.of(mockBuildResultHelper);
        }

        @Override
        public Optional<BuildResultHelper> doCreateForLocalBuild(Project project) {
            return Optional.of(mockBuildResultHelper);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) Optional(java.util.Optional) BuildResultHelperProvider(com.google.idea.blaze.base.command.buildresult.BuildResultHelperProvider) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) Before(org.junit.Before)

Example 4 with ParsedBepOutput

use of com.google.idea.blaze.base.command.buildresult.ParsedBepOutput in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method setupBuildResultHelperProvider.

/**
 * Setup build result helper to return BEP output with test execroot by default.
 */
@Before
public void setupBuildResultHelperProvider() throws GetArtifactsException {
    mockBuildResultHelper = mock(BuildResultHelper.class);
    when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, getExecRoot(), null, null, 0, BuildResult.SUCCESS));
    registerExtension(BuildResultHelperProvider.EP_NAME, new BuildResultHelperProvider() {

        @Override
        public Optional<BuildResultHelper> doCreate(Project project, BlazeInfo blazeInfo) {
            return Optional.of(mockBuildResultHelper);
        }

        @Override
        public Optional<BuildResultHelper> doCreateForLocalBuild(Project project) {
            return Optional.of(mockBuildResultHelper);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) Optional(java.util.Optional) BuildResultHelperProvider(com.google.idea.blaze.base.command.buildresult.BuildResultHelperProvider) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) Before(org.junit.Before)

Example 5 with ParsedBepOutput

use of com.google.idea.blaze.base.command.buildresult.ParsedBepOutput in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method nullExecRoot.

@Test
public void nullExecRoot() throws GetDeployInfoException, ApkProvisionException, GetArtifactsException {
    setupProject();
    Label testTarget = Label.create("//java/com/foo/app:instrumentation_test");
    Label instrumentorTarget = Label.create("//java/com/foo/app:test_app");
    Label appTarget = Label.create("//java/com/foo/app:app");
    ImmutableList<String> blazeFlags = ImmutableList.of("some_blaze_flag", "some_other_flag");
    MessageCollector messageCollector = new MessageCollector();
    BlazeContext context = new BlazeContext();
    context.addOutputSink(IssueOutput.class, messageCollector);
    // Return null execroot
    when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, null, null, null, 0, BuildResult.SUCCESS));
    // Setup interceptor for fake running of blaze commands and capture details.
    ExternalTaskInterceptor externalTaskInterceptor = new ExternalTaskInterceptor();
    registerApplicationService(ExternalTaskProvider.class, externalTaskInterceptor);
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeInstrumentorProto = AndroidDeployInfo.newBuilder().build();
    AndroidDeployInfo fakeAppProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    when(helper.readDeployInfoProtoForTarget(eq(instrumentorTarget), any(BuildResultHelper.class), any())).thenReturn(fakeInstrumentorProto);
    when(helper.readDeployInfoProtoForTarget(eq(appTarget), any(BuildResultHelper.class), any())).thenReturn(fakeAppProto);
    when(helper.extractInstrumentationTestDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeInstrumentorProto), eq(fakeAppProto))).thenReturn(mockDeployInfo);
    // Perform
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), testTarget, blazeFlags, helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Could not locate execroot!");
}
Also used : AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) MessageCollector(com.google.idea.blaze.android.MessageCollector) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) File(java.io.File) Test(org.junit.Test)

Aggregations

ParsedBepOutput (com.google.idea.blaze.base.command.buildresult.ParsedBepOutput)7 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)6 File (java.io.File)4 AndroidDeployInfo (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo)3 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)3 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)3 DeviceSession (com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession)3 BuildResultHelperProvider (com.google.idea.blaze.base.command.buildresult.BuildResultHelperProvider)3 BlazeInfo (com.google.idea.blaze.base.command.info.BlazeInfo)3 Project (com.intellij.openapi.project.Project)3 Optional (java.util.Optional)3 Before (org.junit.Before)3 Test (org.junit.Test)3 DeviceFutures (com.android.tools.idea.run.DeviceFutures)1 MessageCollector (com.google.idea.blaze.android.MessageCollector)1 MobileInstallBuildStep (com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep)1 BlazeInstrumentationTestApkBuildStep (com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep)1 FullApkBuildStep (com.google.idea.blaze.android.run.runner.FullApkBuildStep)1 GetArtifactsException (com.google.idea.blaze.base.command.buildresult.BuildResultHelper.GetArtifactsException)1 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)1