use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class AspectFunction method createAspect.
@Nullable
private AspectValue createAspect(Environment env, AspectKey key, ImmutableList<Aspect> aspectPath, Aspect aspect, ConfiguredAspectFactory aspectFactory, ConfiguredTarget associatedTarget, BuildConfiguration aspectConfiguration, ImmutableMap<Label, ConfigMatchingProvider> configConditions, OrderedSetMultimap<Attribute, ConfiguredTarget> directDeps, NestedSetBuilder<Package> transitivePackages) throws AspectFunctionException, InterruptedException {
SkyframeBuildView view = buildViewProvider.getSkyframeBuildView();
StoredEventHandler events = new StoredEventHandler();
CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment(key, false, events, env, aspectConfiguration);
if (env.valuesMissing()) {
return null;
}
ConfiguredAspect configuredAspect;
if (ConfiguredTargetFunction.aspectMatchesConfiguredTarget(associatedTarget, aspect)) {
configuredAspect = view.getConfiguredTargetFactory().createAspect(analysisEnvironment, associatedTarget, aspectPath, aspectFactory, aspect, directDeps, configConditions, aspectConfiguration, view.getHostConfiguration(aspectConfiguration));
} else {
configuredAspect = ConfiguredAspect.forNonapplicableTarget(aspect.getDescriptor());
}
events.replayOn(env.getListener());
if (events.hasErrors()) {
analysisEnvironment.disable(associatedTarget.getTarget());
throw new AspectFunctionException(new AspectCreationException("Analysis of target '" + associatedTarget.getLabel() + "' failed; build aborted"));
}
Preconditions.checkState(!analysisEnvironment.hasErrors(), "Analysis environment hasError() but no errors reported");
if (env.valuesMissing()) {
return null;
}
analysisEnvironment.disable(associatedTarget.getTarget());
Preconditions.checkNotNull(configuredAspect);
return new AspectValue(key, aspect, associatedTarget.getLabel(), associatedTarget.getTarget().getLocation(), configuredAspect, ImmutableList.copyOf(analysisEnvironment.getRegisteredActions()), transitivePackages.build());
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class ResolverTest method testArtifactResolution.
@Test
public void testArtifactResolution() throws Exception {
StoredEventHandler handler = new StoredEventHandler();
DefaultModelResolver modelResolver = Mockito.mock(DefaultModelResolver.class);
Resolver resolver = new Resolver(handler, modelResolver);
resolver.resolveArtifact("x:y:1.2.3");
Collection<Rule> rules = resolver.getRules();
assertThat(rules).hasSize(1);
Rule rule = rules.iterator().next();
assertThat(rule.name()).isEqualTo("x_y");
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class BuildViewTestCase method getRuleContextForSkylark.
/**
* Creates and returns a rule context to use for Skylark tests that is equivalent to the one
* that was used to create the given configured target.
*/
protected RuleContext getRuleContextForSkylark(ConfiguredTarget target) throws Exception {
// TODO(bazel-team): we need this horrible workaround because CachingAnalysisEnvironment
// only works with StoredErrorEventListener despite the fact it accepts the interface
// ErrorEventListener, so it's not possible to create it with reporter.
// See BuildView.getRuleContextForTesting().
StoredEventHandler eventHandler = new StoredEventHandler() {
@Override
public synchronized void handle(Event e) {
super.handle(e);
reporter.handle(e);
}
};
return view.getRuleContextForTesting(target, eventHandler, masterConfig);
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class BlazeExecutorTest method testDebugPrintActionContexts.
@Test
public void testDebugPrintActionContexts() throws Exception {
TestExecutorBuilder builder = new TestExecutorBuilder(directories, binTools);
OptionsParser parser = OptionsParser.newOptionsParser(TestExecutorBuilder.DEFAULT_OPTIONS);
parser.parse("--debug_print_action_contexts");
Reporter reporter = new Reporter(new EventBus());
StoredEventHandler storedEventHandler = new StoredEventHandler();
reporter.addHandler(storedEventHandler);
SpawnActionContext mockStrategy = Mockito.mock(SpawnActionContext.class);
builder.setReporter(reporter).setOptionsParser(parser).setExecution("mock", mockStrategy);
builder.build();
Event event = Iterables.find(storedEventHandler.getEvents(), new Predicate<Event>() {
@Override
public boolean apply(@Nullable Event event) {
return event.getMessage().contains("SpawnActionContextMap: \"mock\" = ");
}
});
assertThat(event).isNotNull();
assertThat(event.getMessage()).contains("\"mock\" = " + mockStrategy.getClass().getSimpleName());
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class SubincludePreprocessor method preprocess.
@Override
public Preprocessor.Result preprocess(Path buildFilePath, byte[] buildFileBytes, String packageName, Globber globber, Set<String> ruleNames) throws IOException, InterruptedException {
StoredEventHandler eventHandler = new StoredEventHandler();
char[] content = FileSystemUtils.convertFromLatin1(buildFileBytes);
while (true) {
Matcher matcher = SUBINCLUDE_REGEX.matcher(CharBuffer.wrap(content));
if (!matcher.find()) {
break;
}
String name = matcher.group(1);
String path = resolveSubinclude(name);
char[] subContent;
if (path.isEmpty()) {
// This location is not correct, but will do for testing purposes.
eventHandler.handle(Event.error(Location.fromFile(buildFilePath), "Cannot find subincluded file \'" + name + "\'"));
// Emit a mocksubinclude(), so we know to preprocess again if the file becomes
// visible. We cannot fail the preprocess here, as it would drop the content.
subContent = new char[0];
} else {
// TODO(bazel-team): figure out the correct behavior for a non-existent file from an
// existent package.
subContent = FileSystemUtils.readContentAsLatin1(fileSystem.getPath(path));
}
String mock = "\nmocksubinclude('" + name + "', '" + path + "')\n";
content = Chars.concat(Arrays.copyOf(content, matcher.start()), mock.toCharArray(), subContent, Arrays.copyOfRange(content, matcher.end(), content.length));
}
if (Chars.indexOf(content, TRANSIENT_ERROR.toCharArray()) >= 0) {
throw new IOException("transient error requested in " + buildFilePath.asFragment());
}
return Preprocessor.Result.success(ParserInputSource.create(content, buildFilePath.asFragment()), eventHandler.hasErrors(), eventHandler.getEvents());
}
Aggregations