Search in sources :

Example 61 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectCommandLineLabel.

@Test
public void aspectCommandLineLabel() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   print('This aspect does nothing')", "   return struct()", "MyAspect = aspect(implementation=_impl)");
    scratch.file("test/BUILD", "java_library(name = 'xxx',)");
    AnalysisResult analysisResult = update(ImmutableList.of("//test:aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(getLabelsToBuild(analysisResult)).containsExactly("//test:xxx");
    assertThat(getAspectDescriptions(analysisResult)).containsExactly("//test:aspect.bzl%MyAspect(//test:xxx)");
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 62 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class SkylarkAspectsTest method attributesWithAspectsReused.

@Test
public void attributesWithAspectsReused() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   return struct()", "my_aspect = aspect(_impl)", "a_dict = { 'foo' : attr.label_list(aspects = [my_aspect]) }");
    scratch.file("test/r1.bzl", "load(':aspect.bzl', 'my_aspect', 'a_dict')", "def _rule_impl(ctx):", "   pass", "r1 = rule(_rule_impl, attrs = a_dict)");
    scratch.file("test/r2.bzl", "load(':aspect.bzl', 'my_aspect', 'a_dict')", "def _rule_impl(ctx):", "   pass", "r2 = rule(_rule_impl, attrs = a_dict)");
    scratch.file("test/BUILD", "load(':r1.bzl', 'r1')", "load(':r2.bzl', 'r2')", "r1(name = 'x1')", "r2(name = 'x2', foo = [':x1'])");
    AnalysisResult analysisResult = update("//test:x2");
    assertThat(analysisResult.hasError()).isFalse();
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 63 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class BuildTool method runAnalysisPhase.

/**
   * Performs the initial phases 0-2 of the build: Setup, Loading and Analysis.
   * <p>
   * Postcondition: On success, populates the BuildRequest's set of targets to
   * build.
   *
   * @return null if loading / analysis phases were successful; a useful error
   *         message if loading or analysis phase errors were encountered and
   *         request.keepGoing.
   * @throws InterruptedException if the current thread was interrupted.
   * @throws ViewCreationFailedException if analysis failed for any reason.
   */
private AnalysisResult runAnalysisPhase(BuildRequest request, LoadingResult loadingResult, BuildConfigurationCollection configurations) throws InterruptedException, ViewCreationFailedException {
    Stopwatch timer = Stopwatch.createStarted();
    getReporter().handle(Event.progress("Loading complete.  Analyzing..."));
    Profiler.instance().markPhase(ProfilePhase.ANALYZE);
    BuildView view = new BuildView(env.getDirectories(), runtime.getRuleClassProvider(), env.getSkyframeExecutor(), runtime.getCoverageReportActionFactory(request));
    AnalysisResult analysisResult = view.update(loadingResult, configurations, request.getAspects(), request.getViewOptions(), request.getTopLevelArtifactContext(), env.getReporter(), env.getEventBus());
    // TODO(bazel-team): Merge these into one event.
    env.getEventBus().post(new AnalysisPhaseCompleteEvent(analysisResult.getTargetsToBuild(), view.getTargetsVisited(), timer.stop().elapsed(TimeUnit.MILLISECONDS)));
    env.getEventBus().post(new TestFilteringCompleteEvent(analysisResult.getTargetsToBuild(), analysisResult.getTargetsToTest()));
    // Check licenses.
    // We check licenses if the first target configuration has license checking enabled. Right now,
    // it is not possible to have multiple target configurations with different settings for this
    // flag, which allows us to take this short cut.
    boolean checkLicenses = configurations.getTargetConfigurations().get(0).checkLicenses();
    if (checkLicenses) {
        Profiler.instance().markPhase(ProfilePhase.LICENSE);
        validateLicensingForTargets(analysisResult.getTargetsToBuild(), request.getViewOptions().keepGoing);
    }
    return analysisResult;
}
Also used : BuildView(com.google.devtools.build.lib.analysis.BuildView) AnalysisPhaseCompleteEvent(com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent) Stopwatch(com.google.common.base.Stopwatch) TestFilteringCompleteEvent(com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)

Example 64 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class BuildViewTest method testMultipleRootCauseReporting.

@Test
public void testMultipleRootCauseReporting() throws Exception {
    scratch.file("gp/BUILD", "sh_library(name = 'gp', deps = ['//p:p'])");
    scratch.file("p/BUILD", "sh_library(name = 'p', deps = ['//c1:not', '//c2:not'])");
    scratch.file("c1/BUILD");
    scratch.file("c2/BUILD");
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    LoadingFailureRecorder recorder = new LoadingFailureRecorder();
    eventBus.register(recorder);
    AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//gp");
    assertThat(result.hasError()).isTrue();
    assertThat(recorder.events).hasSize(2);
    assertTrue(recorder.events.toString(), recorder.events.contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//c1:not"))));
    assertThat(recorder.events).contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//c2:not")));
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 65 with AnalysisResult

use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.

the class BuildViewTest method testRootCauseReportingFileSymlinks.

/**
   * Tests that skyframe reports the root cause as being the target that depended on the symlink
   * cycle.
   */
@Test
public void testRootCauseReportingFileSymlinks() throws Exception {
    scratch.file("gp/BUILD", "sh_library(name = 'gp', deps = ['//p'])");
    scratch.file("p/BUILD", "sh_library(name = 'p', deps = ['//c'])");
    scratch.file("c/BUILD", "sh_library(name = 'c', deps = [':c1', ':c2'])", "sh_library(name = 'c1', deps = ['//cycles1'])", "sh_library(name = 'c2', deps = ['//cycles2'])");
    Path cycles1BuildFilePath = scratch.file("cycles1/BUILD", "sh_library(name = 'cycles1', srcs = glob(['*.sh']))");
    Path cycles2BuildFilePath = scratch.file("cycles2/BUILD", "sh_library(name = 'cycles2', srcs = glob(['*.sh']))");
    cycles1BuildFilePath.getParentDirectory().getRelative("cycles1.sh").createSymbolicLink(new PathFragment("cycles1.sh"));
    cycles2BuildFilePath.getParentDirectory().getRelative("cycles2.sh").createSymbolicLink(new PathFragment("cycles2.sh"));
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    LoadingFailureRecorder recorder = new LoadingFailureRecorder();
    eventBus.register(recorder);
    AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//gp");
    assertThat(result.hasError()).isTrue();
    assertThat(recorder.events).hasSize(2);
    assertTrue(recorder.events.toString(), recorder.events.contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//cycles1"))));
    assertTrue(recorder.events.toString(), recorder.events.contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//cycles2"))));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Aggregations

AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)69 Test (org.junit.Test)63 ViewCreationFailedException (com.google.devtools.build.lib.analysis.ViewCreationFailedException)21 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)12 EventBus (com.google.common.eventbus.EventBus)8 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)7 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)6 Artifact (com.google.devtools.build.lib.actions.Artifact)5 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)5 SkylarkList (com.google.devtools.build.lib.syntax.SkylarkList)5 Nullable (javax.annotation.Nullable)5 Label (com.google.devtools.build.lib.cmdline.Label)4 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)3 SkylarkNestedSet (com.google.devtools.build.lib.syntax.SkylarkNestedSet)3 Key (com.google.devtools.build.lib.packages.ClassObjectConstructor.Key)2 SkylarkKey (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey)2 Stopwatch (com.google.common.base.Stopwatch)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 AnalysisPhaseCompleteEvent (com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent)1 BuildInfoEvent (com.google.devtools.build.lib.analysis.BuildInfoEvent)1