Here are the examples of the java api com.google.devtools.build.lib.vfs.RootedPath.toRootedPath() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
127 Examples
19
View Complete Implementation : PackageFactoryTestBase.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
protected boolean isValidPackageName(String packageName) throws Exception {
// Write a license decl just in case it's a third_party package:
Path buildFile = scratch.file(getPathPrefix() + "/" + packageName + "/BUILD", "licenses(['notice'])");
Package pkg = packages.createPackage(packageName, RootedPath.toRootedPath(root, buildFile));
return !pkg.containsErrors();
}
19
View Complete Implementation : LocalRepositoryLookupFunctionTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testLocalRepository_absolutePath_nonNormalized() throws Exception {
scratch.overwriteFile("WORKSPACE", "local_repository(name='local', path='/abs/local/./repo')");
scratch.file("/abs/local/repo/WORKSPACE");
scratch.file("/abs/local/repo/BUILD");
LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory(RootedPath.toRootedPath(Root.fromPath(rootDirectory.getRelative("/abs")), PathFragment.create("local/repo")));
replacedertThat(repositoryLookupValue).isNotNull();
replacedertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local");
replacedertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("/abs/local/repo"));
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPackageConstantIsForbidden() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/pina/BUILD", "cc_library(name=PACKAGE_NAME + '-colada')");
packages.createPackage("pina", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("The value 'PACKAGE_NAME' has been removed");
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPrefixBetweenRules1() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/fruit/kiwi/BUILD", "genrule(name='kiwi1', srcs=[], outs=['a'], cmd='')", "genrule(name='kiwi2', srcs=[], outs=['a/b'], cmd='')");
packages.createPackage("fruit/kiwi", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("output file 'a/b' of rule 'kiwi2' conflicts " + "with output file 'a' of rule 'kiwi1'");
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testCreationOfInputFiles() throws Exception {
Path buildFile = scratch.file("/foo/BUILD", "exports_files(['Z'])", "cc_library(name='W', deps=['X', 'Y'])", "cc_library(name='X', srcs=['X'])", "cc_library(name='Y')");
Package pkg = packages.createPackage("foo", RootedPath.toRootedPath(root, buildFile));
replacedertThat(pkg.containsErrors()).isFalse();
// X is a rule with a circular self-dependency.
replacedertThat(pkg.getTarget("X").getClreplaced()).isSameInstanceAs(Rule.clreplaced);
// Y is a rule
replacedertThat(pkg.getTarget("Y").getClreplaced()).isSameInstanceAs(Rule.clreplaced);
// Z is a file
replacedertThat(pkg.getTarget("Z").getClreplaced()).isSameInstanceAs(InputFile.clreplaced);
// A is nothing
NoSuchTargetException e = replacedertThrows(NoSuchTargetException.clreplaced, () -> pkg.getTarget("A"));
replacedertThat(e).hasMessageThat().isEqualTo("no such target '//foo:A': " + "target 'A' not declared in package 'foo' defined by /foo/BUILD");
// These are the only input files: BUILD, Z
Set<String> inputFiles = Sets.newTreeSet();
for (InputFile inputFile : pkg.getTargets(InputFile.clreplaced)) {
inputFiles.add(inputFile.getName());
}
replacedertThat(Lists.newArrayList(inputFiles)).containsExactly("BUILD", "Z").inOrder();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testCreatePackage() throws Exception {
Path buildFile = scratch.file("/pkgname/BUILD", "# empty build file ");
Package pkg = packages.createPackage("pkgname", RootedPath.toRootedPath(root, buildFile));
replacedertThat(pkg.getName()).isEqualTo("pkgname");
replacedertThat(Sets.newHashSet(pkg.getTargets(Rule.clreplaced))).isEmpty();
}
19
View Complete Implementation : FilesystemValueCheckerTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPropagatesRuntimeExceptions() throws Exception {
Collection<SkyKey> values = ImmutableList.of(FileValue.key(RootedPath.toRootedPath(Root.fromPath(pkgRoot), PathFragment.create("foo"))));
driver.evaluate(values, EVALUATION_OPTIONS);
FilesystemValueChecker checker = new FilesystemValueChecker(null, null);
replacedertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker));
fs.statThrowsRuntimeException = true;
RuntimeException e = replacedertThrows(RuntimeException.clreplaced, () -> getDirtyFilesystemKeys(evaluator, checker));
replacedertThat(e).hasMessageThat().isEqualTo("bork");
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPrefixBetweenRules2() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/fruit/kiwi/BUILD", "genrule(name='kiwi1', srcs=[], outs=['a/b'], cmd='')", "genrule(name='kiwi2', srcs=[], outs=['a'], cmd='')");
packages.createPackage("fruit/kiwi", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("output file 'a' of rule 'kiwi2' conflicts " + "with output file 'a/b' of rule 'kiwi1'");
}
19
View Complete Implementation : LocalRepositoryLookupFunctionTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testLocalRepository_MainWorkspace_NotFound() throws Exception {
// Do not add a local_repository to WORKSPACE.
scratch.overwriteFile("WORKSPACE", "");
scratch.deleteFile("WORKSPACE");
scratch.file("local/repo/WORKSPACE");
scratch.file("local/repo/BUILD");
LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory(RootedPath.toRootedPath(Root.fromPath(rootDirectory), PathFragment.create("local/repo")));
replacedertThat(repositoryLookupValue).isNotNull();
// In this case, the repository should be MAIN as we can't find any local_repository rules.
replacedertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN);
replacedertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT);
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testDefaultDeprecationOverriding() throws Exception {
String msg = "I am completely operational, and all my circuits are functioning perfectly.";
String deceive = "OMG PONIES!";
Path file = scratch.file("/foo/BUILD", "package(default_deprecation = \"" + deceive + "\")", "sh_library(name = 'bar', srcs=['b'], deprecation = \"" + msg + "\")");
Package pkg = packages.eval("foo", RootedPath.toRootedPath(root, file));
Rule fooRule = (Rule) pkg.getTarget("bar");
String deprAttr = attributes(fooRule).get("deprecation", com.google.devtools.build.lib.packages.Type.STRING);
replacedertThat(deprAttr).isEqualTo(msg);
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
// TODO(bazel-team): This is really a test for GlobCache.
@Test
public void testRecursiveGlob() throws Exception {
emptyFile("/rg/a.cc");
emptyFile("/rg/foo/bar.cc");
emptyFile("/rg/foo/foo.cc");
emptyFile("/rg/foo/wiz/bam.cc");
emptyFile("/rg/foo/wiz/bum.cc");
emptyFile("/rg/foo/wiz/quid/gav.cc");
Path file = scratch.file("/rg/BUILD", "cc_library(name = 'ri', srcs = glob(['**/*.cc']))", "cc_library(name = 're', srcs = glob(['*.cc'], exclude=['**/*.c']))");
Package pkg = packages.eval("rg", RootedPath.toRootedPath(root, file));
events.replacedertNoWarningsOrErrors();
replacedertEvaluates(pkg, ImmutableList.of("BUILD", "a.cc", "foo", "foo/bar.cc", "foo/foo.cc", "foo/wiz", "foo/wiz/bam.cc", "foo/wiz/bum.cc", "foo/wiz/quid", "foo/wiz/quid/gav.cc"), "**");
replacedertEvaluates(pkg, ImmutableList.of("a.cc", "foo/bar.cc", "foo/foo.cc", "foo/wiz/bam.cc", "foo/wiz/bum.cc", "foo/wiz/quid/gav.cc"), "**/*.cc");
replacedertEvaluates(pkg, ImmutableList.of("foo/bar.cc", "foo/wiz/bam.cc", "foo/wiz/bum.cc"), "**/b*.cc");
replacedertEvaluates(pkg, ImmutableList.of("foo/bar.cc", "foo/foo.cc", "foo/wiz/bam.cc", "foo/wiz/bum.cc", "foo/wiz/quid/gav.cc"), "**/*/*.cc");
replacedertEvaluates(pkg, ImmutableList.of("foo/wiz/quid/gav.cc"), "foo/**/quid/*.cc");
replacedertEvaluates(pkg, Collections.<String>emptyList(), ImmutableList.of("*.cc", "*/*.cc", "*/*/*.cc"), ImmutableList.of("**/*.cc"));
replacedertEvaluates(pkg, Collections.<String>emptyList(), ImmutableList.of("**/*.cc"), ImmutableList.of("**/*.cc"));
replacedertEvaluates(pkg, Collections.<String>emptyList(), ImmutableList.of("**/*.cc"), ImmutableList.of("*.cc", "*/*.cc", "*/*/*.cc", "*/*/*/*.cc"));
replacedertEvaluates(pkg, Collections.<String>emptyList(), ImmutableList.of("**"), ImmutableList.of("*", "*/*", "*/*/*", "*/*/*/*"));
replacedertEvaluates(pkg, ImmutableList.of("foo/bar.cc", "foo/foo.cc", "foo/wiz/bam.cc", "foo/wiz/bum.cc", "foo/wiz/quid/gav.cc"), ImmutableList.of("**/*.cc"), ImmutableList.of("*.cc"));
replacedertEvaluates(pkg, ImmutableList.of("a.cc", "foo/wiz/bam.cc", "foo/wiz/bum.cc", "foo/wiz/quid/gav.cc"), ImmutableList.of("**/*.cc"), ImmutableList.of("*/*.cc"));
replacedertEvaluates(pkg, ImmutableList.of("a.cc", "foo/bar.cc", "foo/foo.cc", "foo/wiz/quid/gav.cc"), ImmutableList.of("**/*.cc"), ImmutableList.of("**/wiz/*.cc"));
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testColonInExportsFilesTargetName() throws Exception {
events.setFailFast(false);
Path path = scratch.file("/googledata/cafe/BUILD", "exports_files(['houseads/house_ads:ca-aol_parenting_html'])");
Package pkg = packages.createPackage("googledata/cafe", RootedPath.toRootedPath(root, path));
events.replacedertContainsError("target names may not contain ':'");
replacedertThat(pkg.getTargets(FileTarget.clreplaced).toString()).doesNotContain("houseads/house_ads:ca-aol_parenting_html");
replacedertThat(pkg.containsErrors()).isTrue();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPrefixWithinSameRule1() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/fruit/orange/BUILD", "genrule(name='orange', srcs=[], outs=['a', 'a/b'], cmd='')");
packages.createPackage("fruit/orange", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("rule 'orange' has conflicting output files 'a/b' and 'a");
}
19
View Complete Implementation : RuleClassTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
private Package.Builder createDummyPackageBuilder() {
return packageFactory.newPackageBuilder(PackageIdentifier.createInMainRepo(TEST_PACKAGE_NAME), "TESTING", StarlarkSemantics.DEFAULT_SEMANTICS).setFilename(RootedPath.toRootedPath(root, testBuildfilePath));
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testDefaultTestonlyPropagation() throws Exception {
Path file = scratch.file("/foo/BUILD", "package(default_testonly = 1)", "sh_library(name = 'foo', srcs=['b'])", "sh_library(name = 'bar', srcs=['b'], testonly = 0)");
Package pkg = packages.eval("foo", RootedPath.toRootedPath(root, file));
Rule fooRule = (Rule) pkg.getTarget("foo");
replacedertThat(attributes(fooRule).get("testonly", com.google.devtools.build.lib.packages.Type.BOOLEAN)).isTrue();
Rule barRule = (Rule) pkg.getTarget("bar");
replacedertThat(attributes(barRule).get("testonly", com.google.devtools.build.lib.packages.Type.BOOLEAN)).isFalse();
}
19
View Complete Implementation : PackageFactoryTestBase.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
protected void expectEvalError(String expectedError, String... content) throws Exception {
events.setFailFast(false);
Path file = scratch.file("pkg/BUILD", content);
Package pkg = packages.eval("pkg", RootedPath.toRootedPath(root, file));
replacedertWithMessage("Expected evaluation error, but none was not reported").that(pkg.containsErrors()).isTrue();
events.replacedertContainsError(expectedError);
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
// Was: Regression test for bug "Rules declared after an error in
// a package should be considered 'in error'".
// Then: Regression test for bug "Why aren't ERRORS considered
// fatal?*"
// Now: Regression test for: execution should stop at the first EvalException;
// all rules created prior to the exception error are marked in error.
@Test
public void testAllRulesInErrantPackageAreInError() throws Exception {
events.setFailFast(false);
Path path = scratch.file("/error/BUILD", "genrule(name = 'rule1',", " cmd = ':',", " outs = ['out.1'])", "list = ['bad']", // dynamic error
"x = 1//0", "genrule(name = 'rule2',", " cmd = ':',", " outs = list)");
Package pkg = packages.createPackage("error", RootedPath.toRootedPath(root, path));
events.replacedertContainsError("division by zero");
replacedertThat(pkg.containsErrors()).isTrue();
// rule1 would be fine but is still marked as in error:
replacedertThat(pkg.getRule("rule1").containsErrors()).isTrue();
// rule2's genrule is never executed.
Rule rule2 = pkg.getRule("rule2");
replacedertThat(rule2).isNull();
}
19
View Complete Implementation : GlobFunctionTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testGlobWithoutWildcards() throws Exception {
String pattern = "foo/bar/wiz/file";
replacedertGlobMatches(pattern, "foo/bar/wiz/file");
// Ensure that the glob depends on the FileValue and not on the DirectoryListingValue.
pkgPath.getRelative("foo/bar/wiz/file").delete();
// Nothing has been invalidated yet, so the cached result is returned.
replacedertGlobMatches(pattern, "foo/bar/wiz/file");
if (alwaysUseDirListing()) {
differencer.invalidate(ImmutableList.of(FileStateValue.key(RootedPath.toRootedPath(Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz/file")))));
// The result should not rely on the FileStateValue, so it's still a cache hit.
replacedertGlobMatches(pattern, "foo/bar/wiz/file");
differencer.invalidate(ImmutableList.of(DirectoryListingStateValue.key(RootedPath.toRootedPath(Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz")))));
// This should have invalidated the glob result.
replacedertGlobMatches(pattern);
} else {
differencer.invalidate(ImmutableList.of(DirectoryListingStateValue.key(RootedPath.toRootedPath(Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz")))));
// The result should not rely on the DirectoryListingValue, so it's still a cache hit.
replacedertGlobMatches(pattern, "foo/bar/wiz/file");
differencer.invalidate(ImmutableList.of(FileStateValue.key(RootedPath.toRootedPath(Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz/file")))));
// This should have invalidated the glob result.
replacedertGlobMatches(pattern);
}
}
19
View Complete Implementation : PackageLookupFunction.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
private PackageLookupValue computeWorkspacePackageLookupValue(Environment env, ImmutableList<Root> packagePathEntries) throws PackageLookupFunctionException, InterruptedException {
PackageLookupValue resultForWorkspaceDotBazel = getPackageLookupValue(env, packagePathEntries, LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER, BuildFileName.WORKSPACE_DOT_BAZEL);
if (resultForWorkspaceDotBazel == null) {
return null;
}
if (resultForWorkspaceDotBazel.packageExists()) {
return resultForWorkspaceDotBazel;
}
PackageLookupValue resultForWorkspace = getPackageLookupValue(env, packagePathEntries, LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER, BuildFileName.WORKSPACE);
if (resultForWorkspace == null) {
return null;
}
if (resultForWorkspace.packageExists()) {
return resultForWorkspace;
}
// Fall back on the last package path entry if there were any and nothing else worked.
// TODO(kchodorow): get rid of this, the semantics are wrong (successful package lookup should
// mean the package exists). a bunch of tests need to be rewritten first though.
if (packagePathEntries.isEmpty()) {
return PackageLookupValue.NO_BUILD_FILE_VALUE;
}
Root lastPackagePath = packagePathEntries.get(packagePathEntries.size() - 1);
FileValue lastPackagePackagePathFileValue = getFileValue(RootedPath.toRootedPath(lastPackagePath, PathFragment.EMPTY_FRAGMENT), env, LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER);
if (lastPackagePackagePathFileValue == null) {
return null;
}
return lastPackagePackagePathFileValue.exists() ? PackageLookupValue.success(lastPackagePath, BuildFileName.WORKSPACE) : PackageLookupValue.NO_BUILD_FILE_VALUE;
}
19
View Complete Implementation : LocalRepositoryLookupFunctionTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testNoPath() throws Exception {
LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory(RootedPath.toRootedPath(Root.fromPath(rootDirectory), PathFragment.EMPTY_FRAGMENT));
replacedertThat(repositoryLookupValue).isNotNull();
replacedertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN);
replacedertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT);
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testNoRuleName() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/badrulename/BUILD", "cc_library()");
Package pkg = packages.createPackage("badrulename", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("cc_library rule has no 'name' attribute");
replacedertThat(pkg.containsErrors()).isTrue();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPackageFunctionInExternalRepository() throws Exception {
Path buildFile = scratch.file("/external/a/b/BUILD", "genrule(name='c', srcs=[], outs=['o'], cmd=repository_name() + ' ' + package_name())");
Package pkg = packages.createPackage(PackageIdentifier.create("@a", PathFragment.create("b")), RootedPath.toRootedPath(root, buildFile), events.reporter());
Rule c = pkg.getRule("c");
replacedertThat(AggregatingAttributeMapper.of(c).get("cmd", Type.STRING)).isEqualTo("@a b");
}
19
View Complete Implementation : PackageLookupValue.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
/**
* For a successful package lookup, returns the {@link RootedPath} for the build file that defines
* the package.
*/
public RootedPath getRootedPath(PackageIdentifier packageIdentifier) {
return RootedPath.toRootedPath(getRoot(), getBuildFileName().getBuildFileFragment(packageIdentifier));
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testConflictingRuleDoesNotUpdatePackage() throws Exception {
events.setFailFast(false);
// In this test, rule2's outputs conflict with rule1, so rule2 is rejected.
// However, we must check that neither rule2, nor any of its inputs or
// outputs is a member of the package, and that the conflicting output file
// "out2" still has rule1 as its getGeneratingRule().
Path path = scratch.file("/conflict/BUILD", "genrule(name = 'rule1',", " cmd = '',", " srcs = ['in1', 'in2'],", " outs = ['out1', 'out2'])", "genrule(name = 'rule2',", " cmd = '',", " srcs = ['in3', 'in4'],", " outs = ['out3', 'out2'])");
Package pkg = packages.createPackage("conflict", RootedPath.toRootedPath(root, path));
events.replacedertContainsError("generated file 'out2' in rule 'rule2' " + "conflicts with existing generated file from rule 'rule1'");
replacedertThat(pkg.containsErrors()).isTrue();
replacedertThat(pkg.getRule("rule2")).isNull();
// Ensure that rule2's "out2" didn't overwrite rule1's:
replacedertThat(((OutputFile) pkg.getTarget("out2")).getGeneratingRule()).isSameInstanceAs(pkg.getRule("rule1"));
// None of rule2, its inputs, or its outputs should belong to pkg:
List<Target> found = new ArrayList<>();
for (String targetName : ImmutableList.of("rule2", "in3", "in4", "out3")) {
try {
found.add(pkg.getTarget(targetName));
// No fail() here: if there's no exception, we add the name to a list
// and we check below that it's empty.
} catch (NoSuchTargetException e) {
/* good! */
}
}
replacedertThat(found).isEmpty();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPackageConstantInExternalRepositoryIsForbidden() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/external/a/b/BUILD", "genrule(name='c', srcs=[], outs=['ao'], cmd=REPOSITORY_NAME)");
packages.createPackage(PackageIdentifier.create("@a", PathFragment.create("b")), RootedPath.toRootedPath(root, buildFile), events.reporter());
events.replacedertContainsError("The value 'REPOSITORY_NAME' has been removed");
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testTestSuitesImplicitlyDependOnAllRulesInPackage() throws Exception {
Path path = scratch.file("/x/BUILD", "java_test(name='j')", "test_suite(name='t1')", "test_suite(name='t2', tests=['//foo'])", "test_suite(name='t3', tests=['//foo'])", "cc_test(name='c')");
Package pkg = packages.createPackage("x", RootedPath.toRootedPath(root, path));
// Things to note:
// - the t1 refers to both :j and :c, even though :c is a forward reference.
// - $implicit_tests is empty unless tests=[]
replacedertThat(attributes(pkg.getRule("t1")).get("$implicit_tests", BuildType.LABEL_LIST)).containsExactlyElementsIn(Sets.newHashSet(Label.parseAbsolute("//x:c", ImmutableMap.of()), Label.parseAbsolute("//x:j", ImmutableMap.of())));
replacedertThat(attributes(pkg.getRule("t2")).get("$implicit_tests", BuildType.LABEL_LIST)).isEmpty();
replacedertThat(attributes(pkg.getRule("t3")).get("$implicit_tests", BuildType.LABEL_LIST)).isEmpty();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPackageFeatures() throws Exception {
Path file = scratch.file("/a/BUILD", "sh_library(name='before')", "package(features=['b', 'c'])", "sh_library(name='after')");
Package pkg = packages.eval("a", RootedPath.toRootedPath(root, file));
replacedertThat(pkg.getFeatures()).containsExactly("b", "c");
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testTransientErrorsInGlobbing() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/e/BUILD", "sh_library(name = 'e', data = glob(['*.txt']))");
Path parentDir = buildFile.getParentDirectory();
scratch.file("/e/data.txt");
throwOnReaddir = parentDir;
replacedertThrows(NoSuchPackageException.clreplaced, () -> packages.createPackage("e", RootedPath.toRootedPath(root, buildFile)));
events.setFailFast(true);
throwOnReaddir = null;
Package pkg = packages.createPackage("e", RootedPath.toRootedPath(root, buildFile));
replacedertThat(pkg.containsErrors()).isFalse();
replacedertThat(pkg.getRule("e")).isNotNull();
List<?> globList = (List) pkg.getRule("e").getAttributeContainer().getAttr("data");
replacedertThat(globList).containsExactly(Label.parseAbsolute("//e:data.txt", ImmutableMap.of()));
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testDuplicatedDependencies() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/has_dupe/BUILD", "cc_library(name='dep')", "cc_library(name='has_dupe', deps=[':dep', ':dep'])");
Package pkg = packages.createPackage("has_dupe", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("Label '//has_dupe:dep' is duplicated in the 'deps' " + "attribute of rule 'has_dupe'");
replacedertThat(pkg.containsErrors()).isTrue();
replacedertThat(pkg.getRule("has_dupe")).isNotNull();
replacedertThat(pkg.getRule("dep")).isNotNull();
replacedertThat(pkg.getRule("has_dupe").containsErrors()).isTrue();
// because all rules in an
replacedertThat(pkg.getRule("dep").containsErrors()).isTrue();
// errant package are
// themselves errant.
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testHelpfulErrorForMissingExportsFiles() throws Exception {
Path path = scratch.file("/x/BUILD", "cc_library(name='x', srcs=['x.cc'])");
scratch.file("/x/x.cc");
scratch.file("/x/y.cc");
scratch.file("/x/dir/dummy");
Package pkg = packages.createPackage("x", RootedPath.toRootedPath(root, path));
// existing and mentioned.
replacedertThat(pkg.getTarget("x.cc")).isNotNull();
NoSuchTargetException e = replacedertThrows(NoSuchTargetException.clreplaced, () -> pkg.getTarget("y.cc"));
replacedertThat(e).hasMessageThat().isEqualTo("no such target '//x:y.cc': " + "target 'y.cc' not declared in package 'x'; " + "however, a source file of this name exists. " + "(Perhaps add 'exports_files([\"y.cc\"])' to x/BUILD?) " + "defined by /x/BUILD");
e = replacedertThrows(NoSuchTargetException.clreplaced, () -> pkg.getTarget("z.cc"));
replacedertThat(e).hasMessageThat().isEqualTo("no such target '//x:z.cc': " + "target 'z.cc' not declared in package 'x' (did you mean 'x.cc'?) " + "defined by /x/BUILD");
e = replacedertThrows(NoSuchTargetException.clreplaced, () -> pkg.getTarget("dir"));
replacedertThat(e).hasMessageThat().isEqualTo("no such target '//x:dir': target 'dir' not declared in package 'x'; " + "however, a source directory of this name exists. " + "(Perhaps add 'exports_files([\"dir\"])' to x/BUILD, " + "or define a filegroup?) defined by /x/BUILD");
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testBadRuleName() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/badrulename/BUILD", "cc_library(name = 3)");
Package pkg = packages.createPackage("badrulename", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("cc_library 'name' attribute must be a string");
replacedertThat(pkg.containsErrors()).isTrue();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testGlobDirectoryExclusion() throws Exception {
emptyFile("/fruit/data/apple");
emptyFile("/fruit/data/pear");
emptyFile("/fruit/data/berry/black");
emptyFile("/fruit/data/berry/blue");
Path file = scratch.file("/fruit/BUILD", "cc_library(name = 'yes', srcs = glob(['data/*']))", "cc_library(name = 'no', srcs = glob(['data/*'], exclude_directories=0))");
Package pkg = packages.eval("fruit", RootedPath.toRootedPath(root, file));
events.replacedertNoWarningsOrErrors();
List<Label> yesFiles = attributes(pkg.getRule("yes")).get("srcs", BuildType.LABEL_LIST);
List<Label> noFiles = attributes(pkg.getRule("no")).get("srcs", BuildType.LABEL_LIST);
replacedertThat(yesFiles).containsExactly(Label.parseAbsolute("@//fruit:data/apple", ImmutableMap.of()), Label.parseAbsolute("@//fruit:data/pear", ImmutableMap.of()));
replacedertThat(noFiles).containsExactly(Label.parseAbsolute("@//fruit:data/apple", ImmutableMap.of()), Label.parseAbsolute("@//fruit:data/pear", ImmutableMap.of()), Label.parseAbsolute("@//fruit:data/berry", ImmutableMap.of()));
}
19
View Complete Implementation : PackageFactoryTestBase.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
protected com.google.devtools.build.lib.packages.Package expectEvalSuccess(String... content) throws InterruptedException, IOException, NoSuchPackageException {
Path file = scratch.file("pkg/BUILD", content);
Package pkg = packages.eval("pkg", RootedPath.toRootedPath(root, file));
replacedertThat(pkg.containsErrors()).isFalse();
return pkg;
}
19
View Complete Implementation : FileFunction.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
private static RootedPath getChild(RootedPath parentRootedPath, String baseName) {
return RootedPath.toRootedPath(parentRootedPath.getRoot(), parentRootedPath.getRootRelativePath().getChild(baseName));
}
19
View Complete Implementation : PackageFactoryTestBase.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
private Package buildPackageWithGlob(String globCallExpression) throws Exception {
scratch.deleteFile("/dummypackage/BUILD");
Path file = scratch.file("/dummypackage/BUILD", "x = " + globCallExpression);
return packages.eval("dummypackage", RootedPath.toRootedPath(root, file));
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testDuplicateRuleName() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/duplicaterulename/BUILD", "proto_library(name = 'spellcheck_proto',", " srcs = ['spellcheck.proto'],", " cc_api_version = 2)", // conflict error stops execution
"cc_library(name = 'spellcheck_proto')", // not reached
"x = 1//0");
Package pkg = packages.createPackage("duplicaterulename", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("cc_library rule 'spellcheck_proto' in package 'duplicaterulename' conflicts with existing" + " proto_library rule");
events.replacedertDoesNotContainEvent("division by zero");
replacedertThat(pkg.containsErrors()).isTrue();
}
19
View Complete Implementation : AbstractCollectPackagesUnderDirectoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
private RootedPath rootedPath(String relativePath) {
return RootedPath.toRootedPath(root, PathFragment.create(relativePath));
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPrefixWithinSameRule2() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/fruit/orange/BUILD", "genrule(name='orange', srcs=[], outs=['a/b', 'a'], cmd='')");
packages.createPackage("fruit/orange", RootedPath.toRootedPath(root, buildFile));
events.replacedertContainsError("rule 'orange' has conflicting output files 'a' and 'a/b");
}
19
View Complete Implementation : FilesystemValueCheckerTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testFileWithIOExceptionNotConsideredDirty() throws Exception {
Path path = fs.getPath("/testroot/foo");
path.getParentDirectory().createDirectory();
path.createSymbolicLink(PathFragment.create("bar"));
fs.readlinkThrowsIoException = true;
SkyKey fileKey = FileStateValue.key(RootedPath.toRootedPath(Root.fromPath(pkgRoot), PathFragment.create("foo")));
EvaluationResult<SkyValue> result = driver.evaluate(ImmutableList.of(fileKey), EVALUATION_OPTIONS);
replacedertThat(result.hasError()).isTrue();
fs.readlinkThrowsIoException = false;
FilesystemValueChecker checker = new FilesystemValueChecker(null, null);
Diff diff = getDirtyFilesystemKeys(evaluator, checker);
replacedertThat(diff.changedKeysWithoutNewValues()).isEmpty();
replacedertThat(diff.changedKeysWithNewValues()).isEmpty();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testBadPackageName() throws Exception {
NoSuchPackageException e = replacedertThrows(NoSuchPackageException.clreplaced, () -> packages.createPackage("not even a legal/.../label", RootedPath.toRootedPath(root, emptyBuildFile("not even a legal/.../label"))));
replacedertThat(e).hasMessageThat().contains("no such package 'not even a legal/.../label': " + "illegal package name: 'not even a legal/.../label' ");
}
19
View Complete Implementation : LocalRepositoryLookupFunctionTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testLocalRepository() throws Exception {
scratch.overwriteFile("WORKSPACE", "local_repository(name='local', path='local/repo')");
scratch.file("local/repo/WORKSPACE");
scratch.file("local/repo/BUILD");
LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory(RootedPath.toRootedPath(Root.fromPath(rootDirectory), PathFragment.create("local/repo")));
replacedertThat(repositoryLookupValue).isNotNull();
replacedertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local");
replacedertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("local/repo"));
}
19
View Complete Implementation : RepositoryFunction.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
/**
* Adds the repository's directory to the graph and, if it's a symlink, resolves it to an actual
* directory.
*/
@Nullable
protected static FileValue getRepositoryDirectory(Path repositoryDirectory, Environment env) throws RepositoryFunctionException, InterruptedException {
SkyKey outputDirectoryKey = FileValue.key(RootedPath.toRootedPath(Root.fromPath(repositoryDirectory), PathFragment.EMPTY_FRAGMENT));
FileValue value;
try {
value = (FileValue) env.getValueOrThrow(outputDirectoryKey, IOException.clreplaced);
} catch (IOException e) {
throw new RepositoryFunctionException(new IOException("Could not access " + repositoryDirectory + ": " + e.getMessage()), Transience.PERSISTENT);
}
return value;
}
19
View Complete Implementation : LocalRepositoryLookupFunctionTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testActualPackage() throws Exception {
scratch.file("some/path/BUILD");
LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory(RootedPath.toRootedPath(Root.fromPath(rootDirectory), PathFragment.create("some/path")));
replacedertThat(repositoryLookupValue).isNotNull();
replacedertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN);
replacedertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT);
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testDefaultDeprecationPropagation() throws Exception {
String msg = "I am completely operational, and all my circuits are functioning perfectly.";
Path file = scratch.file("/foo/BUILD", "package(default_deprecation = \"" + msg + "\")", "sh_library(name = 'bar', srcs=['b'])");
Package pkg = packages.eval("foo", RootedPath.toRootedPath(root, file));
Rule fooRule = (Rule) pkg.getTarget("bar");
String deprAttr = attributes(fooRule).get("deprecation", com.google.devtools.build.lib.packages.Type.STRING);
replacedertThat(deprAttr).isEqualTo(msg);
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testBuildFileTargetExists() throws Exception {
Path buildFile = scratch.file("/foo/BUILD", "");
Package pkg = packages.createPackage("foo", RootedPath.toRootedPath(root, buildFile));
Target target = pkg.getTarget("BUILD");
replacedertThat(target.getName()).isEqualTo("BUILD");
// Test that it's memoized:
replacedertThat(pkg.getTarget("BUILD")).isSameInstanceAs(target);
}
19
View Complete Implementation : RepositoryFunction.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
public static RootedPath getRootedPathFromLabel(Label label, Environment env) throws InterruptedException, EvalException {
// Look for package.
if (label.getPackageIdentifier().getRepository().isDefault()) {
try {
label = Label.create(label.getPackageIdentifier().makeAbsolute(), label.getName());
} catch (LabelSyntaxException e) {
// Can't happen because the input label is valid
throw new replacedertionError(e);
}
}
SkyKey pkgSkyKey = PackageLookupValue.key(label.getPackageIdentifier());
PackageLookupValue pkgLookupValue = (PackageLookupValue) env.getValue(pkgSkyKey);
if (pkgLookupValue == null) {
throw RepositoryFunction.restart();
}
if (!pkgLookupValue.packageExists()) {
String message = pkgLookupValue.getErrorMsg();
if (pkgLookupValue == PackageLookupValue.NO_BUILD_FILE_VALUE) {
message = PackageLookupFunction.explainNoBuildFileValue(label.getPackageIdentifier(), env);
}
throw new EvalException(Location.BUILTIN, "Unable to load package for " + label + ": " + message);
}
// And now for the file
Root packageRoot = pkgLookupValue.getRoot();
return RootedPath.toRootedPath(packageRoot, label.toPathFragment());
}
19
View Complete Implementation : ASTFileLookupFunction.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
Label fileLabel = (Label) skyKey.argument();
// Determine whether the package designated by fileLabel exists.
// TODO(bazel-team): After --incompatible_disallow_load_labels_to_cross_package_boundaries is
// removed and the new behavior is unconditional, we can instead safely replacedume the package
// exists and preplaced in the Root in the SkyKey and therefore this dep can be removed.
SkyKey pkgSkyKey = PackageLookupValue.key(fileLabel.getPackageIdentifier());
PackageLookupValue pkgLookupValue = null;
try {
pkgLookupValue = (PackageLookupValue) env.getValueOrThrow(pkgSkyKey, BuildFileNotFoundException.clreplaced, InconsistentFilesystemException.clreplaced);
} catch (BuildFileNotFoundException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(e), Transience.PERSISTENT);
} catch (InconsistentFilesystemException e) {
throw new ASTLookupFunctionException(e, Transience.PERSISTENT);
}
if (pkgLookupValue == null) {
return null;
}
if (!pkgLookupValue.packageExists()) {
return ASTFileLookupValue.forBadPackage(fileLabel, pkgLookupValue.getErrorMsg());
}
// Determine whether the file designated by fileLabel exists.
Root packageRoot = pkgLookupValue.getRoot();
RootedPath rootedPath = RootedPath.toRootedPath(packageRoot, fileLabel.toPathFragment());
SkyKey fileSkyKey = FileValue.key(rootedPath);
FileValue fileValue = null;
try {
fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.clreplaced);
} catch (InconsistentFilesystemException e) {
throw new ASTLookupFunctionException(e, Transience.PERSISTENT);
} catch (IOException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(e), Transience.PERSISTENT);
}
if (fileValue == null) {
return null;
}
if (!fileValue.exists()) {
return ASTFileLookupValue.forMissingFile(fileLabel);
}
if (!fileValue.isFile()) {
return ASTFileLookupValue.forBadFile(fileLabel);
}
StarlarkSemantics starlarkSemantics = PrecomputedValue.STARLARK_SEMANTICS.get(env);
if (starlarkSemantics == null) {
return null;
}
// Both the package and the file exist; load and parse the file.
Path path = rootedPath.asPath();
StarlarkFile file = null;
try {
byte[] bytes = FileSystemUtils.readWithKnownFileSize(path, fileValue.getSize());
ParserInput input = ParserInput.create(bytes, path.toString());
file = StarlarkFile.parseWithDigest(input, path.getDigest());
} catch (IOException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(e), Transience.TRANSIENT);
}
// validate (and soon, compile)
ImmutableMap<String, Object> predeclared = ruleClreplacedProvider.getEnvironment();
ValidationEnvironment.validateFile(file, Module.createForBuiltins(predeclared), starlarkSemantics, /*isBuildFile=*/
false);
// TODO(adonovan): fail if !ok()?
Event.replayEventsOn(env.getListener(), file.errors());
return ASTFileLookupValue.withFile(file);
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testDuplicateRuleIsNotAddedToPackage() throws Exception {
events.setFailFast(false);
Path path = scratch.file("/dup/BUILD", "proto_library(name = 'dup_proto',", " srcs = ['dup.proto'],", " cc_api_version = 2)", "", "cc_library(name = 'dup_proto',", " srcs = ['dup.pb.cc', 'dup.pb.h'])");
Package pkg = packages.createPackage("dup", RootedPath.toRootedPath(root, path));
events.replacedertContainsError("cc_library rule 'dup_proto' in package 'dup' " + "conflicts with existing proto_library rule");
replacedertThat(pkg.containsErrors()).isTrue();
Rule dupProto = pkg.getRule("dup_proto");
// Check that the first rule of the given name "wins", and that each of the
// "winning" rule's outputs is a member of the package.
replacedertThat(dupProto.getRuleClreplaced()).isEqualTo("proto_library");
for (OutputFile out : dupProto.getOutputFiles()) {
replacedertThat(pkg.getTargets(FileTarget.clreplaced)).contains(out);
}
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testNativeModuleIsDisabled() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/pkg/BUILD", "native.cc_library(name='bar')");
Package pkg = packages.createPackage("pkg", RootedPath.toRootedPath(root, buildFile));
replacedertThat(pkg.containsErrors()).isTrue();
}
19
View Complete Implementation : PackageFactoryTest.java
Copyright Apache License 2.0
Author : bazelbuild
Copyright Apache License 2.0
Author : bazelbuild
@Test
public void testPackageNameFunction() throws Exception {
Path buildFile = scratch.file("/pina/BUILD", "cc_library(name=package_name() + '-colada')");
Package pkg = packages.createPackage("pina", RootedPath.toRootedPath(root, buildFile));
events.replacedertNoWarningsOrErrors();
replacedertThat(pkg.containsErrors()).isFalse();
replacedertThat(pkg.getRule("pina-colada")).isNotNull();
replacedertThat(pkg.getRule("pina-colada").containsErrors()).isFalse();
replacedertThat(Sets.newHashSet(pkg.getTargets(Rule.clreplaced)).size()).isSameInstanceAs(1);
}