use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class PackageFactory method createPackageFromPreprocessingResult.
/****************************************************************************
* Package creation.
*/
/**
* Loads, scans parses and evaluates the build file at "buildFile", and
* creates and returns a Package builder instance capable of building a package identified by
* "packageId".
*
* <p>This method returns a builder to allow the caller to do additional work, if necessary.
*
* <p>This method assumes "packageId" is a valid package name according to the
* {@link LabelValidator#validatePackageName} heuristic.
*
* <p>See {@link #evaluateBuildFile} for information on AST retention.
*
* <p>Executes {@code globber.onCompletion()} on completion and executes
* {@code globber.onInterrupt()} on an {@link InterruptedException}.
*/
// Used outside of bazel!
public Package.Builder createPackageFromPreprocessingResult(String workspaceName, PackageIdentifier packageId, Path buildFile, Preprocessor.Result preprocessingResult, List<Statement> preludeStatements, Map<String, Extension> imports, ImmutableList<Label> skylarkFileDependencies, RuleVisibility defaultVisibility, Globber globber) throws InterruptedException {
StoredEventHandler localReporterForParsing = new StoredEventHandler();
// Run the lexer and parser with a local reporter, so that errors from other threads do not
// show up below.
BuildFileAST buildFileAST = parseBuildFile(packageId, preprocessingResult.result, preludeStatements, localReporterForParsing);
AstAfterPreprocessing astAfterPreprocessing = new AstAfterPreprocessing(preprocessingResult, buildFileAST, localReporterForParsing);
return createPackageFromPreprocessingAst(workspaceName, packageId, buildFile, astAfterPreprocessing, imports, skylarkFileDependencies, defaultVisibility, globber);
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class WorkspaceFactory method execute.
/**
* Actually runs through the AST, calling the functions in the WORKSPACE file and adding rules
* to the //external package.
*/
public void execute(BuildFileAST ast, Map<String, Extension> importedExtensions) throws InterruptedException {
Preconditions.checkNotNull(ast);
Preconditions.checkNotNull(importedExtensions);
execute(ast, importedExtensions, new StoredEventHandler());
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class WorkspaceFactory method parse.
@VisibleForTesting
public void parse(ParserInputSource source, @Nullable StoredEventHandler localReporter) throws BuildFileContainsErrorsException, InterruptedException {
// because most people are just using it to resolve Maven dependencies.
if (localReporter == null) {
localReporter = new StoredEventHandler();
}
BuildFileAST buildFileAST = BuildFileAST.parseBuildFile(source, localReporter);
if (buildFileAST.containsErrors()) {
throw new BuildFileContainsErrorsException(Label.EXTERNAL_PACKAGE_IDENTIFIER, "Failed to parse " + source.getPath());
}
execute(buildFileAST, null, localReporter);
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected.
@Test
public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception {
// Failure expected
StoredEventHandler storingEventHandler = new StoredEventHandler();
reporter.removeHandler(failFastHandler);
reporter.addHandler(storingEventHandler);
final Artifact out = createTreeArtifact("output");
TreeArtifactTestAction action = new TreeArtifactTestAction(out) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
try {
buildArtifact(action.getSoleOutput());
// Should have thrown
fail();
} catch (BuildFailedException e) {
List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains("A TreeArtifact may not contain relative symlinks whose target paths traverse " + "outside of the TreeArtifact");
assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class ConfiguredTargetFunction method createConfiguredTarget.
@Nullable
private ConfiguredTargetValue createConfiguredTarget(SkyframeBuildView view, Environment env, Target target, BuildConfiguration configuration, OrderedSetMultimap<Attribute, ConfiguredTarget> depValueMap, ImmutableMap<Label, ConfigMatchingProvider> configConditions, NestedSetBuilder<Package> transitivePackages) throws ConfiguredTargetFunctionException, InterruptedException {
StoredEventHandler events = new StoredEventHandler();
BuildConfiguration ownerConfig = (configuration == null) ? null : configuration.getArtifactOwnerConfiguration();
CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment(new ConfiguredTargetKey(target.getLabel(), ownerConfig), false, events, env, configuration);
if (env.valuesMissing()) {
return null;
}
Preconditions.checkNotNull(depValueMap);
ConfiguredTarget configuredTarget = view.createConfiguredTarget(target, configuration, analysisEnvironment, depValueMap, configConditions);
events.replayOn(env.getListener());
if (events.hasErrors()) {
analysisEnvironment.disable(target);
throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException("Analysis of target '" + target.getLabel() + "' failed; build aborted", target.getLabel()));
}
Preconditions.checkState(!analysisEnvironment.hasErrors(), "Analysis environment hasError() but no errors reported");
if (env.valuesMissing()) {
return null;
}
analysisEnvironment.disable(target);
Preconditions.checkNotNull(configuredTarget, target);
ImmutableMap<Artifact, ActionAnalysisMetadata> generatingActions;
// rule implementation).
try {
generatingActions = Actions.filterSharedActionsAndThrowActionConflict(analysisEnvironment.getRegisteredActions());
} catch (ActionConflictException e) {
throw new ConfiguredTargetFunctionException(e);
}
return new ConfiguredTargetValue(configuredTarget, generatingActions, transitivePackages.build());
}
Aggregations