use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testAbsoluteSymlinkBadTargetRejected.
@Test
public void testAbsoluteSymlinkBadTargetRejected() 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"), "/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("Failed to resolve relative path links/link");
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 ExternalPackageBuilder method createAndAddRepositoryRule.
public Rule createAndAddRepositoryRule(Package.Builder pkg, RuleClass ruleClass, RuleClass bindRuleClass, Map<String, Object> kwargs, FuncallExpression ast) throws RuleFactory.InvalidRuleException, Package.NameConflictException, LabelSyntaxException, InterruptedException {
StoredEventHandler eventHandler = new StoredEventHandler();
BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(kwargs);
Rule rule = RuleFactory.createRule(pkg, ruleClass, attributeValues, eventHandler, ast, ast.getLocation(), /*env=*/
null, new AttributeContainer(ruleClass));
pkg.addEvents(eventHandler.getEvents());
overwriteRule(pkg, rule);
for (Map.Entry<String, Label> entry : ruleClass.getExternalBindingsFunction().apply(rule).entrySet()) {
Label nameLabel = Label.parseAbsolute("//external:" + entry.getKey());
addBindRule(pkg, bindRuleClass, nameLabel, entry.getValue(), rule.getLocation(), new AttributeContainer(bindRuleClass));
}
return rule;
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class ExternalPackageBuilder method addBindRule.
static void addBindRule(Builder pkg, RuleClass bindRuleClass, Label virtual, Label actual, Location location, AttributeContainer attributeContainer) throws RuleFactory.InvalidRuleException, Package.NameConflictException, InterruptedException {
Map<String, Object> attributes = Maps.newHashMap();
// Bound rules don't have a name field, but this works because we don't want more than one
// with the same virtual name.
attributes.put("name", virtual.getName());
if (actual != null) {
attributes.put("actual", actual);
}
StoredEventHandler handler = new StoredEventHandler();
BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(attributes);
Rule rule = RuleFactory.createRule(pkg, bindRuleClass, attributeValues, handler, /*ast=*/
null, location, /*env=*/
null, attributeContainer);
overwriteRule(pkg, rule);
rule.setVisibility(ConstantRuleVisibility.PUBLIC);
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class PackageFactory method evaluateBuildFile.
/**
* Constructs a Package instance, evaluates the BUILD-file AST inside the
* build environment, and populates the package with Rule instances as it
* goes. As with most programming languages, evaluation stops when an
* exception is encountered: no further rules after the point of failure will
* be constructed. We assume that rules constructed before the point of
* failure are valid; this assumption is not entirely correct, since a
* "vardef" after a rule declaration can affect the behavior of that rule.
*
* <p>Rule attribute checking is performed during evaluation. Each attribute
* must conform to the type specified for that <i>(rule class, attribute
* name)</i> pair. Errors reported at this stage include: missing value for
* mandatory attribute, value of wrong type. Such error cause Rule
* construction to be aborted, so the resulting package will have missing
* members.
*
* @see PackageFactory#PackageFactory
*/
// used by PackageFactoryApparatus
@VisibleForTesting
public Package.Builder evaluateBuildFile(String workspaceName, PackageIdentifier packageId, BuildFileAST buildFileAST, Path buildFilePath, Globber globber, Iterable<Event> pastEvents, RuleVisibility defaultVisibility, boolean containsError, MakeEnvironment.Builder pkgMakeEnv, Map<String, Extension> imports, ImmutableList<Label> skylarkFileDependencies) throws InterruptedException {
Package.Builder pkgBuilder = new Package.Builder(packageBuilderHelper.createFreshPackage(packageId, ruleClassProvider.getRunfilesPrefix()));
StoredEventHandler eventHandler = new StoredEventHandler();
try (Mutability mutability = Mutability.create("package %s", packageId)) {
Environment pkgEnv = Environment.builder(mutability).setGlobals(BazelLibrary.GLOBALS).setEventHandler(eventHandler).setImportedExtensions(imports).setPhase(Phase.LOADING).build();
SkylarkUtils.setToolsRepository(pkgEnv, ruleClassProvider.getToolsRepository());
pkgBuilder.setFilename(buildFilePath).setMakeEnv(pkgMakeEnv).setDefaultVisibility(defaultVisibility).setDefaultVisibilitySet(false).setSkylarkFileDependencies(skylarkFileDependencies).setWorkspaceName(workspaceName);
Event.replayEventsOn(eventHandler, pastEvents);
// Stuff that closes over the package context:
PackageContext context = new PackageContext(pkgBuilder, globber, eventHandler, ruleFactory.getAttributeContainerFactory());
buildPkgEnv(pkgEnv, context, ruleFactory);
pkgEnv.setupDynamic(PKG_CONTEXT, context);
pkgEnv.setupDynamic(Runtime.PKG_NAME, packageId.getPackageFragment().getPathString());
pkgEnv.setupDynamic(Runtime.REPOSITORY_NAME, packageId.getRepository().toString());
if (containsError) {
pkgBuilder.setContainsErrors();
}
if (!validatePackageIdentifier(packageId, buildFileAST.getLocation(), eventHandler)) {
pkgBuilder.setContainsErrors();
}
if (!validateAssignmentStatements(pkgEnv, buildFileAST, eventHandler)) {
pkgBuilder.setContainsErrors();
}
if (buildFileAST.containsErrors()) {
pkgBuilder.setContainsErrors();
}
// createPackage().
if (!buildFileAST.exec(pkgEnv, eventHandler)) {
pkgBuilder.setContainsErrors();
}
}
pkgBuilder.addEvents(eventHandler.getEvents());
return pkgBuilder;
}
use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.
the class FileFunctionTest method runTestInfiniteSymlinkExpansion.
private void runTestInfiniteSymlinkExpansion(boolean symlinkToAncestor, boolean absoluteSymlink) throws Exception {
Path otherPath = path("other");
RootedPath otherRootedPath = RootedPath.toRootedPath(pkgRoot, otherPath.relativeTo(pkgRoot));
Path ancestorPath = path("a");
RootedPath ancestorRootedPath = RootedPath.toRootedPath(pkgRoot, ancestorPath.relativeTo(pkgRoot));
FileSystemUtils.ensureSymbolicLink(otherPath, ancestorPath);
Path intermediatePath = path("inter");
RootedPath intermediateRootedPath = RootedPath.toRootedPath(pkgRoot, intermediatePath.relativeTo(pkgRoot));
Path descendantPath = path("a/b/c/d/e");
RootedPath descendantRootedPath = RootedPath.toRootedPath(pkgRoot, descendantPath.relativeTo(pkgRoot));
if (symlinkToAncestor) {
FileSystemUtils.ensureSymbolicLink(descendantPath, intermediatePath);
if (absoluteSymlink) {
FileSystemUtils.ensureSymbolicLink(intermediatePath, ancestorPath);
} else {
FileSystemUtils.ensureSymbolicLink(intermediatePath, ancestorRootedPath.getRelativePath());
}
} else {
FileSystemUtils.ensureSymbolicLink(ancestorPath, intermediatePath);
if (absoluteSymlink) {
FileSystemUtils.ensureSymbolicLink(intermediatePath, descendantPath);
} else {
FileSystemUtils.ensureSymbolicLink(intermediatePath, descendantRootedPath.getRelativePath());
}
}
StoredEventHandler eventHandler = new StoredEventHandler();
SequentialBuildDriver driver = makeDriver();
SkyKey ancestorPathKey = FileValue.key(ancestorRootedPath);
SkyKey descendantPathKey = FileValue.key(descendantRootedPath);
SkyKey otherPathKey = FileValue.key(otherRootedPath);
ImmutableList<SkyKey> keys;
ImmutableList<SkyKey> errorKeys;
ImmutableList<RootedPath> expectedChain;
if (symlinkToAncestor) {
keys = ImmutableList.of(descendantPathKey, otherPathKey);
errorKeys = ImmutableList.of(descendantPathKey);
expectedChain = ImmutableList.of(descendantRootedPath, intermediateRootedPath, ancestorRootedPath);
} else {
keys = ImmutableList.of(ancestorPathKey, otherPathKey);
errorKeys = keys;
expectedChain = ImmutableList.of(ancestorRootedPath, intermediateRootedPath, descendantRootedPath);
}
EvaluationResult<FileValue> result = driver.evaluate(keys, /*keepGoing=*/
true, DEFAULT_THREAD_COUNT, eventHandler);
assertTrue(result.hasError());
for (SkyKey key : errorKeys) {
ErrorInfo errorInfo = result.getError(key);
// FileFunction detects infinite symlink expansion explicitly.
assertThat(errorInfo.getCycleInfo()).isEmpty();
FileSymlinkInfiniteExpansionException fsiee = (FileSymlinkInfiniteExpansionException) errorInfo.getException();
assertThat(fsiee.getMessage()).contains("Infinite symlink expansion");
assertThat(fsiee.getChain()).containsExactlyElementsIn(expectedChain).inOrder();
}
// Check that the unique symlink expansion error was reported exactly once.
assertThat(eventHandler.getEvents()).hasSize(1);
assertThat(Iterables.getOnlyElement(eventHandler.getEvents()).getMessage()).contains("infinite symlink expansion detected");
}
Aggregations