Search in sources :

Example 21 with Event

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);
}
Also used : Reporter(com.google.devtools.build.lib.events.Reporter) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) EventHandler(com.google.devtools.build.lib.events.EventHandler) Event(com.google.devtools.build.lib.events.Event) EventBus(com.google.common.eventbus.EventBus)

Example 22 with Event

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;
}
Also used : Event(com.google.devtools.build.lib.events.Event)

Example 23 with Event

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;
}
Also used : Event(com.google.devtools.build.lib.events.Event)

Example 24 with Event

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;
}
Also used : ArrayList(java.util.ArrayList) Label(com.google.devtools.build.lib.cmdline.Label) Event(com.google.devtools.build.lib.events.Event)

Example 25 with Event

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);
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ExecException(com.google.devtools.build.lib.actions.ExecException) Event(com.google.devtools.build.lib.events.Event) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext)

Aggregations

Event (com.google.devtools.build.lib.events.Event)28 Test (org.junit.Test)15 EventHandler (com.google.devtools.build.lib.events.EventHandler)4 EventBus (com.google.common.eventbus.EventBus)3 ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)3 Reporter (com.google.devtools.build.lib.events.Reporter)3 MoreAsserts.assertContainsEvent (com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent)3 StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)3 ArrayList (java.util.ArrayList)3 ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)2 ActionMiddlemanEvent (com.google.devtools.build.lib.actions.ActionMiddlemanEvent)2 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)2 CachedActionEvent (com.google.devtools.build.lib.actions.CachedActionEvent)2 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)2 EventCollector (com.google.devtools.build.lib.events.EventCollector)2 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1