Search in sources :

Example 6 with BuildResultHelper

use of com.google.idea.blaze.base.command.buildresult.BuildResultHelper 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 7 with BuildResultHelper

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

the class ClassFileManifestBuilder method buildManifest.

/**
 * Builds a .class file manifest, then diffs against any previously calculated manifest for this
 * debugging session.
 *
 * @return null if no diff is available (either no manifest could be calculated, or no previously
 *     calculated manifest is available.
 */
@Nullable
public static ClassFileManifest.Diff buildManifest(ExecutionEnvironment env, @Nullable HotSwapProgress progress) throws ExecutionException {
    if (!HotSwapUtils.canHotSwap(env)) {
        return null;
    }
    BlazeCommandRunConfiguration configuration = getConfiguration(env);
    Project project = configuration.getProject();
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        throw new ExecutionException("Not synced yet; please sync project");
    }
    JavaClasspathAspectStrategy aspectStrategy = JavaClasspathAspectStrategy.findStrategy(projectData.blazeVersionData);
    if (aspectStrategy == null) {
        return null;
    }
    try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
        ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, aspectStrategy.getBuildFlags(), ImmutableList.of(), "Building debug binary");
        if (progress != null) {
            progress.setCancelWorker(() -> buildOperation.cancel(true));
        }
        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);
        }
        ImmutableList<File> jars = buildResultHelper.getArtifactsForOutputGroups(ImmutableSet.of(JavaClasspathAspectStrategy.OUTPUT_GROUP)).stream().filter(f -> f.getName().endsWith(".jar")).collect(toImmutableList());
        ClassFileManifest oldManifest = getManifest(env);
        ClassFileManifest newManifest = ClassFileManifest.build(jars, oldManifest);
        env.getCopyableUserData(MANIFEST_KEY).set(newManifest);
        return oldManifest != null ? ClassFileManifest.modifiedClasses(oldManifest, newManifest) : null;
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) RunProfile(com.intellij.execution.configurations.RunProfile) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) WrappingRunConfiguration(com.intellij.execution.configurations.WrappingRunConfiguration) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeBeforeRunCommandHelper(com.google.idea.blaze.base.run.BlazeBeforeRunCommandHelper) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ImmutableList(com.google.common.collect.ImmutableList) HotSwapProgress(com.intellij.debugger.impl.HotSwapProgress) Project(com.intellij.openapi.project.Project) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) GuavaHelper.toImmutableList(com.google.idea.common.guava.GuavaHelper.toImmutableList) Nullable(javax.annotation.Nullable) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Nullable(javax.annotation.Nullable)

Example 8 with BuildResultHelper

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

the class BlazeApkBuildStepMobileInstall method build.

@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
    ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {

        @Override
        protected Void execute(BlazeContext context) {
            DeviceFutures deviceFutures = deviceSession.deviceFutures;
            assert deviceFutures != null;
            IDevice device = resolveDevice(context, deviceFutures);
            if (device == null) {
                return null;
            }
            BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.MOBILE_INSTALL);
            command.addBlazeFlags(BlazeFlags.DEVICE, device.getSerialNumber());
            // Redundant, but we need this to get around bug in bazel.
            // https://github.com/bazelbuild/bazel/issues/4922
            command.addBlazeFlags(BlazeFlags.ADB_ARG + "-s ", BlazeFlags.ADB_ARG + device.getSerialNumber());
            if (USE_SDK_ADB.getValue()) {
                File adb = AndroidSdkUtils.getAdb(project);
                if (adb != null) {
                    command.addBlazeFlags(BlazeFlags.ADB, adb.toString());
                }
            }
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
            BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project, blazeFlags);
            BuildResultHelper buildResultHelper = deployInfoHelper.getBuildResultHelper();
            command.addTargets(label).addBlazeFlags(blazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags("--output_groups=android_deploy_info").addExeFlags(exeFlags);
            SaveUtil.saveAllFiles();
            int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            FileCaches.refresh(project);
            if (retVal != 0) {
                context.setHasError();
                return null;
            }
            deployInfo = deployInfoHelper.readDeployInfo(context);
            if (deployInfo == null) {
                IssueOutput.error("Could not read apk deploy info from build").submit(context);
            }
            return null;
        }
    };
    ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle(String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
    try {
        Futures.get(buildFuture, ExecutionException.class);
    } catch (ExecutionException e) {
        context.setHasError();
    } catch (CancellationException e) {
        context.setCancelled();
    }
    return context.shouldContinue();
}
Also used : BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) IDevice(com.android.ddmlib.IDevice) DeviceFutures(com.android.tools.idea.run.DeviceFutures) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) 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) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) File(java.io.File)

Example 9 with BuildResultHelper

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

the class BlazeIdeInterfaceAspectsImpl method doResolveIdeArtifacts.

/**
 * Blaze build invocation requesting the 'intellij-resolve' aspect output group.
 *
 * <p>Prefetches the output artifacts built by this invocation.
 */
private static BuildResult doResolveIdeArtifacts(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeVersionData blazeVersionData, WorkspaceLanguageSettings workspaceLanguageSettings, List<TargetExpression> targets) {
    try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(getGenfilePrefetchFilter())) {
        BlazeCommand.Builder blazeCommandBuilder = BlazeCommand.builder(getBinaryPath(project), BlazeCommandName.BUILD).addTargets(targets).addBlazeFlags(BlazeFlags.KEEP_GOING).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.Sync));
        // Request the 'intellij-resolve' aspect output group.
        AspectStrategyProvider.findAspectStrategy(blazeVersionData).addAspectAndOutputGroups(blazeCommandBuilder, OutputGroup.RESOLVE, workspaceLanguageSettings.activeLanguages);
        // Run the blaze build command, parsing any output artifacts produced.
        int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(blazeCommandBuilder.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run(new TimingScope("ExecuteBlazeCommand", EventType.BlazeInvocation));
        BuildResult result = BuildResult.fromExitCode(retVal);
        if (result.status != BuildResult.Status.FATAL_ERROR) {
            prefetchGenfiles(project, context, buildResultHelper.getBuildArtifacts());
        } else {
            buildResultHelper.close();
        }
        return result;
    }
}
Also used : BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand)

Aggregations

BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)9 CancellationException (java.util.concurrent.CancellationException)7 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)6 File (java.io.File)5 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)4 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)4 ScopedTask (com.google.idea.blaze.base.scope.ScopedTask)4 BuildResult (com.google.idea.blaze.base.sync.aspects.BuildResult)4 ExecutionException (com.intellij.execution.ExecutionException)4 Label (com.google.idea.blaze.base.model.primitives.Label)3 RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)2 IssueOutputFilter (com.google.idea.blaze.base.issueparser.IssueOutputFilter)2 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)2 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)2 BlazeConsoleScope (com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope)2