use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.
the class LexerTest method createLexer.
/**
* Create a lexer which takes input from the specified string. Resets the
* error handler beforehand.
*/
private Lexer createLexer(String input) {
PathFragment somePath = new PathFragment("/some/path.txt");
ParserInputSource inputSource = ParserInputSource.create(input, somePath);
Reporter reporter = new Reporter(new EventBus());
reporter.addHandler(new EventHandler() {
@Override
public void handle(Event event) {
if (EventKind.ERRORS.contains(event.getKind())) {
lastErrorLocation = event.getLocation();
lastError = lastErrorLocation.getPath() + ":" + event.getLocation().getStartLineAndColumn().getLine() + ": " + event.getMessage();
}
}
});
return new Lexer(inputSource, reporter);
}
use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.
the class MoreAsserts method assertContainsEvent.
/**
* If the specified EventCollector does not contain an event of a kind of 'kinds' which has
* 'expectedEvent' as a substring, an informative assertion fails. Otherwise
* the matching event is returned.
*/
public static Event assertContainsEvent(Iterable<Event> eventCollector, String expectedEvent, Set<EventKind> kinds) {
for (Event event : eventCollector) {
// Consequently, we use toString() instead of getMessage().
if (event.toString().contains(expectedEvent) && kinds.contains(event.getKind())) {
return event;
}
}
String eventsString = eventsToString(eventCollector);
assertWithMessage("Event '" + expectedEvent + "' not found" + (eventsString.length() == 0 ? "" : ("; found these though:" + eventsString))).that(false).isTrue();
// unreachable
return null;
}
use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.
the class MoreAsserts method assertContainsEventWithWordsInQuotes.
/**
* If the specified EventCollector does not contain an event which has
* each of {@code words} surrounded by single quotes as a substring, an
* informative assertion fails. Otherwise the matching event is returned.
*/
public static Event assertContainsEventWithWordsInQuotes(Iterable<Event> eventCollector, String... words) {
for (Event event : eventCollector) {
boolean found = true;
for (String word : words) {
if (!event.getMessage().contains("'" + word + "'")) {
found = false;
break;
}
}
if (found) {
return event;
}
}
String eventsString = eventsToString(eventCollector);
assertWithMessage("Event containing words " + Arrays.toString(words) + " in " + "single quotes not found" + (eventsString.length() == 0 ? "" : ("; found these though:" + eventsString))).that(false).isTrue();
// unreachable
return null;
}
use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.
the class EnvironmentGroup method processMemberEnvironments.
/**
* Checks that the group's declared environments are legitimate same-package environment
* rules and prepares the "fulfills" relationships between these environments to support
* {@link #getFulfillers}.
*
* @param pkgTargets mapping from label name to target instance for this group's package
* @return a list of validation errors that occurred
*/
List<Event> processMemberEnvironments(Map<String, Target> pkgTargets) {
List<Event> events = new ArrayList<>();
// Maps an environment to the environments that directly fulfill it.
Multimap<Label, Label> directFulfillers = HashMultimap.create();
for (Label envName : environments) {
Target env = pkgTargets.get(envName.getName());
if (isValidEnvironment(env, envName, "", events)) {
AttributeMap attr = NonconfigurableAttributeMapper.of((Rule) env);
for (Label fulfilledEnv : attr.get("fulfills", BuildType.LABEL_LIST)) {
if (isValidEnvironment(pkgTargets.get(fulfilledEnv.getName()), fulfilledEnv, "in \"fulfills\" attribute of " + envName + ": ", events)) {
directFulfillers.put(fulfilledEnv, envName);
}
}
}
}
// Now that we know which environments directly fulfill each other, compute which environments
// transitively fulfill each other. We could alternatively compute this on-demand, but since
// we don't expect these chains to be very large we opt toward computing them once at package
// load time.
Verify.verify(fulfillersMap.isEmpty());
for (Label envName : environments) {
setTransitiveFulfillers(envName, directFulfillers, fulfillersMap);
}
return events;
}
use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.
the class JavaHeaderCompileAction method execute.
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
if (!useDirectClasspath()) {
super.execute(actionExecutionContext);
return;
}
Executor executor = actionExecutionContext.getExecutor();
SpawnActionContext context = getContext(executor);
try {
context.exec(getDirectSpawn(), actionExecutionContext);
} catch (ExecException e) {
// if the direct input spawn failed, try again with transitive inputs to produce better
// better messages
super.execute(actionExecutionContext);
// the compilation should never fail with direct deps but succeed with transitive inputs
if (fallbackError) {
throw e.toActionExecutionException("header compilation failed unexpectedly", executor.getVerboseFailures(), this);
}
Event event = Event.warn(getOwner().getLocation(), "header compilation failed unexpectedly");
executor.getEventHandler().handle(event);
}
}
Aggregations