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