use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class ParserTest method whenSymlinksForbiddenThenParseFailsOnSymlinkInSources.
@Test
public void whenSymlinksForbiddenThenParseFailsOnSymlinkInSources() throws Exception {
// This test depends on creating symbolic links which we cannot do on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
thrown.expect(HumanReadableException.class);
thrown.expectMessage("Target //foo:lib contains input files under a path which contains a symbolic link (" + "{foo/bar=bar}). To resolve this, use separate rules and declare dependencies instead of " + "using symbolic links.");
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[project]", "allow_symlinks = forbid").build();
cell = new TestCellBuilder().setBuckConfig(config).setFilesystem(filesystem).build();
tempDir.newFolder("bar");
tempDir.newFile("bar/Bar.java");
tempDir.newFolder("foo");
Path rootPath = tempDir.getRoot().toRealPath();
Files.createSymbolicLink(rootPath.resolve("foo/bar"), rootPath.resolve("bar"));
Path testBuckFile = rootPath.resolve("foo").resolve("BUCK");
Files.write(testBuckFile, "java_library(name = 'lib', srcs=glob(['bar/*.java']))\n".getBytes(UTF_8));
BuildTarget libTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
Iterable<BuildTarget> buildTargets = ImmutableList.of(libTarget);
parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargets);
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class ParserTest method whenAllRulesAreRequestedWithDifferingCellsThenRulesAreParsedOnce.
@Test
public void whenAllRulesAreRequestedWithDifferingCellsThenRulesAreParsedOnce() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
assertEquals("Should have parsed once.", 1, counter.calls);
Path newTempDir = Files.createTempDirectory("junit-temp-path").toRealPath();
Files.createFile(newTempDir.resolve("bar.py"));
ProjectFilesystem newFilesystem = new ProjectFilesystem(newTempDir);
BuckConfig config = FakeBuckConfig.builder().setFilesystem(newFilesystem).setSections(ImmutableMap.of(ParserConfig.BUILDFILE_SECTION_NAME, ImmutableMap.of(ParserConfig.INCLUDES_PROPERTY_NAME, "//bar.py"))).build();
Cell cell = new TestCellBuilder().setFilesystem(newFilesystem).setBuckConfig(config).build();
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
assertEquals("Should not have invalidated cache.", 1, counter.calls);
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class ParserTest method whenNotifiedOfContainedFileAddCachedAncestorsAreInvalidatedWithoutBoundaryChecks.
@Test
public void whenNotifiedOfContainedFileAddCachedAncestorsAreInvalidatedWithoutBoundaryChecks() throws Exception {
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[buildfile]", "includes = //java/com/facebook/defaultIncludeFile", "[project]", "check_package_boundary = false", "temp_files = ''").build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
Path testAncestorBuildFile = tempDir.newFile("java/BUCK").toRealPath();
Files.write(testAncestorBuildFile, "java_library(name = 'root')\n".getBytes(UTF_8));
// Call parseBuildFile to populate the cache.
getRawTargetNodes(parser, eventBus, cell, false, executorService, testAncestorBuildFile);
// Process event.
WatchEvent<Path> event = createPathEvent(Paths.get("java/com/facebook/SomeClass.java"), StandardWatchEventKinds.ENTRY_CREATE);
parser.onFileSystemChange(event);
// Call parseBuildFile to request cached rules.
getRawTargetNodes(parser, eventBus, cell, false, executorService, testAncestorBuildFile);
// Test that the second parseBuildFile call repopulated the cache.
assertEquals("Should have invalidated cache.", 2, counter.calls);
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class ParserTest method defaultFlavorsInArgsOverrideDefaultsFromConfig.
@Test
public void defaultFlavorsInArgsOverrideDefaultsFromConfig() throws Exception {
// We depend on Xcode platforms for this test.
assumeTrue(Platform.detect() == Platform.MACOS);
Path buckFile = cellRoot.resolve("lib/BUCK");
Files.createDirectories(buckFile.getParent());
Files.write(buckFile, ("cxx_library(" + " name = 'lib', " + " srcs=glob(['*.c']), " + " defaults={'platform':'macosx-x86_64'}" + ")").getBytes(UTF_8));
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(ImmutableMap.of("defaults.cxx_library", ImmutableMap.of("platform", "iphoneos-arm64", "type", "shared"))).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
ImmutableSet<BuildTarget> result = parser.buildTargetGraphForTargetNodeSpecs(eventBus, cell, false, executorService, ImmutableList.of(AbstractBuildTargetSpec.from(BuildTarget.builder(cellRoot, "//lib", "lib").build())), /* ignoreBuckAutodepsFiles */
false, ParserConfig.ApplyDefaultFlavorsMode.ENABLED).getBuildTargets();
assertThat(result, hasItems(BuildTarget.builder(cellRoot, "//lib", "lib").addFlavors(InternalFlavor.of("macosx-x86_64"), InternalFlavor.of("shared")).build()));
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class BuildFileSpecTest method recursiveVsNonRecursive.
@Test
public void recursiveVsNonRecursive() throws IOException, InterruptedException {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
Path buildFile = Paths.get("a", "BUCK");
filesystem.mkdirs(buildFile.getParent());
filesystem.touch(buildFile);
Path nestedBuildFile = Paths.get("a", "b", "BUCK");
filesystem.mkdirs(nestedBuildFile.getParent());
filesystem.touch(nestedBuildFile);
// Test a non-recursive spec.
BuildFileSpec nonRecursiveSpec = BuildFileSpec.fromPath(buildFile.getParent(), filesystem.getRootPath());
ImmutableSet<Path> expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
ImmutableSet<Path> actualBuildFiles = nonRecursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.FILESYSTEM_CRAWL);
assertEquals(expectedBuildFiles, actualBuildFiles);
// Test a recursive spec.
BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile), filesystem.resolve(nestedBuildFile));
actualBuildFiles = recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.FILESYSTEM_CRAWL);
assertEquals(expectedBuildFiles, actualBuildFiles);
}
Aggregations