Search in sources :

Example 1 with BuildTool

use of com.google.devtools.build.lib.buildtool.BuildTool in project bazel by bazelbuild.

the class TestCommand method doTest.

private ExitCode doTest(CommandEnvironment env, OptionsProvider options, AggregatingTestListener testListener) {
    BlazeRuntime runtime = env.getRuntime();
    // Run simultaneous build and test.
    List<String> targets = ProjectFileSupport.getTargets(runtime, options);
    BuildRequest request = BuildRequest.create(getClass().getAnnotation(Command.class).name(), options, runtime.getStartupOptionsProvider(), targets, env.getReporter().getOutErr(), env.getCommandId(), env.getCommandStartTime());
    request.setRunTests();
    BuildResult buildResult = new BuildTool(env).processRequest(request, null);
    Collection<ConfiguredTarget> testTargets = buildResult.getTestTargets();
    // TODO(bazel-team): don't handle isEmpty here or fix up a bunch of tests
    if (buildResult.getSuccessfulTargets() == null) {
        // This can happen if there were errors in the target parsing or loading phase
        // (original exitcode=BUILD_FAILURE) or if there weren't but --noanalyze was given
        // (original exitcode=SUCCESS).
        env.getReporter().handle(Event.error("Couldn't start the build. Unable to run tests"));
        return buildResult.getSuccess() ? ExitCode.PARSING_FAILURE : buildResult.getExitCondition();
    }
    // more tests
    if (testTargets.isEmpty()) {
        env.getReporter().handle(Event.error(null, "No test targets were found, yet testing was requested"));
        return buildResult.getSuccess() ? ExitCode.NO_TESTS_FOUND : buildResult.getExitCondition();
    }
    boolean buildSuccess = buildResult.getSuccess();
    boolean testSuccess = analyzeTestResults(testTargets, testListener, options);
    if (testSuccess && !buildSuccess) {
        // If all tests run successfully, test summary should include warning if
        // there were build errors not associated with the test targets.
        printer.printLn(AnsiTerminalPrinter.Mode.ERROR + "All tests passed but there were other errors during the build.\n" + AnsiTerminalPrinter.Mode.DEFAULT);
    }
    return buildSuccess ? (testSuccess ? ExitCode.SUCCESS : ExitCode.TESTS_FAILED) : buildResult.getExitCondition();
}
Also used : BuildResult(com.google.devtools.build.lib.buildtool.BuildResult) BuildTool(com.google.devtools.build.lib.buildtool.BuildTool) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) BuildRequest(com.google.devtools.build.lib.buildtool.BuildRequest) BlazeRuntime(com.google.devtools.build.lib.runtime.BlazeRuntime)

Example 2 with BuildTool

use of com.google.devtools.build.lib.buildtool.BuildTool in project bazel by bazelbuild.

the class BuildCommand method exec.

@Override
public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
    BlazeRuntime runtime = env.getRuntime();
    List<String> targets = ProjectFileSupport.getTargets(runtime, options);
    BuildRequest request = BuildRequest.create(getClass().getAnnotation(Command.class).name(), options, runtime.getStartupOptionsProvider(), targets, env.getReporter().getOutErr(), env.getCommandId(), env.getCommandStartTime());
    return new BuildTool(env).processRequest(request, null).getExitCondition();
}
Also used : BuildTool(com.google.devtools.build.lib.buildtool.BuildTool) BuildRequest(com.google.devtools.build.lib.buildtool.BuildRequest) BlazeRuntime(com.google.devtools.build.lib.runtime.BlazeRuntime)

Example 3 with BuildTool

use of com.google.devtools.build.lib.buildtool.BuildTool in project bazel by bazelbuild.

the class MobileInstallCommand method exec.

@Override
public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
    BlazeRuntime runtime = env.getRuntime();
    Options mobileInstallOptions = options.getOptions(Options.class);
    WriteAdbArgsAction.Options adbOptions = options.getOptions(WriteAdbArgsAction.Options.class);
    if (adbOptions.start == StartType.WARM && !mobileInstallOptions.incremental) {
        env.getReporter().handle(Event.warn("Warm start is enabled, but will have no effect on a non-incremental build"));
    }
    List<String> targets = ProjectFileSupport.getTargets(runtime, options);
    BuildRequest request = BuildRequest.create(this.getClass().getAnnotation(Command.class).name(), options, runtime.getStartupOptionsProvider(), targets, env.getReporter().getOutErr(), env.getCommandId(), env.getCommandStartTime());
    return new BuildTool(env).processRequest(request, null).getExitCondition();
}
Also used : BuildTool(com.google.devtools.build.lib.buildtool.BuildTool) WriteAdbArgsAction(com.google.devtools.build.lib.rules.android.WriteAdbArgsAction) BuildRequest(com.google.devtools.build.lib.buildtool.BuildRequest) BlazeRuntime(com.google.devtools.build.lib.runtime.BlazeRuntime)

Aggregations

BuildRequest (com.google.devtools.build.lib.buildtool.BuildRequest)3 BuildTool (com.google.devtools.build.lib.buildtool.BuildTool)3 BlazeRuntime (com.google.devtools.build.lib.runtime.BlazeRuntime)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 BuildResult (com.google.devtools.build.lib.buildtool.BuildResult)1 WriteAdbArgsAction (com.google.devtools.build.lib.rules.android.WriteAdbArgsAction)1