use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class PackageFunctionTest method testGlobWithExternalSymlink.
/**
* Tests that a symlink to a file outside of the package root is handled consistently. If the
* default behavior of Bazel was changed from {@code
* ExternalFileAction#DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS} to {@code
* ExternalFileAction#ASSUME_NON_EXISTENT_AND_IMMUTABLE_FOR_EXTERNAL_PATHS} then foo/link.sh
* should no longer appear in the srcs of //foo:foo. However, either way the srcs should be the
* same independent of the evaluation being incremental or clean.
*/
@Test
public void testGlobWithExternalSymlink() throws Exception {
scratch.file("foo/BUILD", "sh_library(name = 'foo', srcs = glob(['*.sh']))", "sh_library(name = 'bar', srcs = glob(['link.sh']))", "sh_library(name = 'baz', srcs = glob(['subdir_link/*.txt']))");
scratch.file("foo/ordinary.sh");
Path externalTarget = scratch.file("../ops/target.txt");
FileSystemUtils.ensureSymbolicLink(scratch.resolve("foo/link.sh"), externalTarget);
FileSystemUtils.ensureSymbolicLink(scratch.resolve("foo/subdir_link"), externalTarget.getParentDirectory());
preparePackageLoading(rootDirectory);
SkyKey fooKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
PackageValue fooValue = validPackage(fooKey);
assertSrcs(fooValue, "foo", "//foo:link.sh", "//foo:ordinary.sh");
assertSrcs(fooValue, "bar", "//foo:link.sh");
assertSrcs(fooValue, "baz", "//foo:subdir_link/target.txt");
scratch.overwriteFile("foo/BUILD", "sh_library(name = 'foo', srcs = glob(['*.sh'])) #comment", "sh_library(name = 'bar', srcs = glob(['link.sh']))", "sh_library(name = 'baz', srcs = glob(['subdir_link/*.txt']))");
getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, ModifiedFileSet.builder().modify(new PathFragment("foo/BUILD")).build(), rootDirectory);
PackageValue fooValue2 = validPackage(fooKey);
assertThat(fooValue2).isNotEqualTo(fooValue);
assertSrcs(fooValue2, "foo", "//foo:link.sh", "//foo:ordinary.sh");
assertSrcs(fooValue2, "bar", "//foo:link.sh");
assertSrcs(fooValue2, "baz", "//foo:subdir_link/target.txt");
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class PackageFunctionTest method testBadWorkspaceFile.
@Test
public void testBadWorkspaceFile() throws Exception {
Path workspacePath = scratch.overwriteFile("WORKSPACE", "junk");
SkyKey skyKey = PackageValue.key(PackageIdentifier.createInMainRepo("external"));
getSkyframeExecutor().invalidate(Predicates.equalTo(com.google.devtools.build.lib.skyframe.FileStateValue.key(RootedPath.toRootedPath(workspacePath.getParentDirectory(), new PathFragment(workspacePath.getBaseName())))));
reporter.removeHandler(failFastHandler);
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
false, reporter);
assertFalse(result.hasError());
assertTrue(result.get(skyKey).getPackage().containsErrors());
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class TargetMarkerFunctionTest method testLabelCrossingSubpackageBoundary.
/** Regression test for b/12545745 */
@Test
public void testLabelCrossingSubpackageBoundary() throws Exception {
scratch.file("a/b/c/foo.sh", "echo 'FOO'");
scratch.file("a/BUILD", "sh_library(name = 'foo', srcs = ['b/c/foo.sh'])");
String labelName = "//a:b/c/foo.sh";
scratch.file("a/b/BUILD");
ModifiedFileSet subpackageBuildFile = ModifiedFileSet.builder().modify(new PathFragment("a/b/BUILD")).build();
skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, subpackageBuildFile, rootDirectory);
NoSuchTargetException exn = (NoSuchTargetException) getErrorFromTargetValue(labelName);
// In the presence of b/12545745, the error message is different and comes from the
// PackageFunction.
assertThat(exn.getMessage()).contains("Label '//a:b/c/foo.sh' crosses boundary of subpackage 'a/b'");
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class SkyframeLabelVisitorTest method testSubpackageBoundaryAdd.
// Indirectly tests that there are dependencies between packages and their subpackages.
@Test
public void testSubpackageBoundaryAdd() throws Exception {
scratch.file("x/BUILD", "sh_library(name = 'x', deps = ['//x:y/z'])", "sh_library(name = 'y/z')");
assertLabelsVisited(ImmutableSet.of("//x:x", "//x:y/z"), ImmutableSet.of("//x:x"), !EXPECT_ERROR, !KEEP_GOING);
scratch.file("x/y/BUILD", "sh_library(name = 'z')");
syncPackages(ModifiedFileSet.builder().modify(new PathFragment("x/y")).modify(new PathFragment("x/y/BUILD")).build());
// expect errors
reporter.removeHandler(failFastHandler);
assertLabelsVisitedWithErrors(ImmutableSet.of("//x:x"), ImmutableSet.of("//x:x"));
assertContainsEvent("Label '//x:y/z' crosses boundary of subpackage 'x/y'");
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class TimestampBuilderTestCase method createDerivedArtifact.
Artifact createDerivedArtifact(FileSystem fs, String name) {
Path execRoot = fs.getPath(TestUtils.tmpDir());
PathFragment execPath = new PathFragment("out").getRelative(name);
Path path = execRoot.getRelative(execPath);
return new Artifact(path, Root.asDerivedRoot(execRoot, execRoot.getRelative("out")), execPath, ALL_OWNER);
}
Aggregations