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());
}
}
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!");
}
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);
}
});
}
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);
}
});
}
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!");
}
Aggregations