From 14f8c25015f60e2e1af2c2806df9315b2c5ef2ed Mon Sep 17 00:00:00 2001 From: Ulf Adams Date: Wed, 9 Sep 2015 14:56:35 +0000 Subject: Rewrite the preprocessor infrastructure to return events as part of the result. -- MOS_MIGRATED_REVID=102658808 --- .../devtools/build/lib/packages/Preprocessor.java | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java') diff --git a/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java b/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java index a479ca9f55..babe5ff555 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java @@ -13,13 +13,15 @@ // limitations under the License. package com.google.devtools.build.lib.packages; -import com.google.devtools.build.lib.events.EventHandler; +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.packages.PackageFactory.Globber; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.ParserInputSource; import com.google.devtools.build.lib.vfs.PathFragment; import java.io.IOException; +import java.util.List; import java.util.Set; import javax.annotation.Nullable; @@ -96,19 +98,22 @@ public interface Preprocessor { public final boolean preprocessed; public final boolean containsErrors; public final boolean containsTransientErrors; + public final List events; private Result(ParserInputSource result, - boolean preprocessed, boolean containsPersistentErrors, boolean containsTransientErrors) { + boolean preprocessed, boolean containsPersistentErrors, boolean containsTransientErrors, + List events) { this.result = result; this.preprocessed = preprocessed; this.containsErrors = containsPersistentErrors || containsTransientErrors; this.containsTransientErrors = containsTransientErrors; + this.events = ImmutableList.copyOf(events); } /** Convenience factory for a {@link Result} wrapping non-preprocessed BUILD file contents. */ public static Result noPreprocessing(ParserInputSource buildFileSource) { return new Result(buildFileSource, /*preprocessed=*/false, /*containsErrors=*/false, - /*containsTransientErrors=*/false); + /*containsTransientErrors=*/false, ImmutableList.of()); } /** @@ -116,19 +121,20 @@ public interface Preprocessor { * read and has valid syntax and was preprocessed. But note that there may have been be errors * during preprocessing. */ - public static Result success(ParserInputSource result, boolean containsErrors) { + public static Result success(ParserInputSource result, boolean containsErrors, + List events) { return new Result(result, /*preprocessed=*/true, /*containsPersistentErrors=*/containsErrors, - /*containsTransientErrors=*/false); + /*containsTransientErrors=*/false, events); } - public static Result invalidSyntax(PathFragment buildFile) { + public static Result invalidSyntax(PathFragment buildFile, List events) { return new Result(ParserInputSource.create(EMPTY_CHARS, buildFile), /*preprocessed=*/true, - /*containsPersistentErrors=*/true, /*containsTransientErrors=*/false); + /*containsPersistentErrors=*/true, /*containsTransientErrors=*/false, events); } - public static Result transientError(PathFragment buildFile) { + public static Result transientError(PathFragment buildFile, List events) { return new Result(ParserInputSource.create(EMPTY_CHARS, buildFile), /*preprocessed=*/false, - /*containsPersistentErrors=*/false, /*containsTransientErrors=*/true); + /*containsPersistentErrors=*/false, /*containsTransientErrors=*/true, events); } } @@ -140,7 +146,6 @@ public interface Preprocessor { * @param in the BUILD file to be preprocessed. * @param packageName the BUILD file's package. * @param globber a globber for evaluating globs. - * @param eventHandler a eventHandler on which to report warnings/errors. * @param globalEnv the GLOBALS Python environment. * @param ruleNames the set of names of all rules in the build language. * @throws IOException if there was an I/O problem during preprocessing. @@ -150,7 +155,6 @@ public interface Preprocessor { ParserInputSource in, String packageName, Globber globber, - EventHandler eventHandler, Environment globalEnv, Set ruleNames) throws IOException, InterruptedException; -- cgit v1.2.3