use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method whenSymlinksAreInReadOnlyPathsCachingIsNotDisabled.
@Test
public void whenSymlinksAreInReadOnlyPathsCachingIsNotDisabled() throws Exception {
// This test depends on creating symbolic links which we cannot do on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
Path rootPath = tempDir.getRoot().toRealPath();
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[project]", "read_only_paths = " + rootPath.resolve("foo")).build();
cell = new TestCellBuilder().setBuckConfig(config).setFilesystem(filesystem).build();
tempDir.newFolder("bar");
tempDir.newFile("bar/Bar.java");
tempDir.newFolder("foo");
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);
DaemonicParserState permState = parser.getPermState();
for (BuildTarget target : buildTargets) {
assertTrue(permState.getOrCreateNodeCache(TargetNode.class).lookupComputedNode(cell, target).isPresent());
}
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method whenUnrelatedBuckConfigEntryChangesThenCachedRulesAreNotInvalidated.
@Test
public void whenUnrelatedBuckConfigEntryChangesThenCachedRulesAreNotInvalidated() throws Exception {
Path buckFile = cellRoot.resolve("BUCK");
Files.write(buckFile, Joiner.on("").join(ImmutableList.of("read_config('foo', 'bar')\n", "genrule(name = 'cake', out = 'file.txt', cmd = 'touch $OUT')\n")).getBytes(UTF_8));
BuckConfig config = FakeBuckConfig.builder().setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "value", "dead", "beef"))).setFilesystem(filesystem).build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Call filterAllTargetsInProject to request cached rules.
config = FakeBuckConfig.builder().setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "value", "dead", "beef different"))).setFilesystem(filesystem).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Test that the second parseBuildFile call repopulated the cache.
assertEquals("Should not have invalidated.", 1, counter.calls);
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method defaultFlavorsInConfigAppliedToTarget.
@Test
public void defaultFlavorsInConfigAppliedToTarget() 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']) " + ")").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("iphoneos-arm64"), InternalFlavor.of("shared")).build()));
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method readConfigReadsConfig.
@Test
public void readConfigReadsConfig() throws Exception {
Path buckFile = cellRoot.resolve("BUCK");
BuildTarget buildTarget = BuildTarget.of(UnflavoredBuildTarget.of(filesystem.getRootPath(), Optional.empty(), "//", "cake"));
Files.write(buckFile, Joiner.on("").join(ImmutableList.of("genrule(\n" + "name = 'cake',\n" + "out = read_config('foo', 'bar', 'default') + '.txt',\n" + "cmd = 'touch $OUT'\n" + ")\n")).getBytes(UTF_8));
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
TargetNode<GenruleDescription.Arg, ?> node = parser.getTargetNode(eventBus, cell, false, executorService, buildTarget).castArg(GenruleDescription.Arg.class).get();
assertThat(node.getConstructorArg().out, is(equalTo("default.txt")));
config = FakeBuckConfig.builder().setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "value"))).setFilesystem(filesystem).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
node = parser.getTargetNode(eventBus, cell, false, executorService, buildTarget).castArg(GenruleDescription.Arg.class).get();
assertThat(node.getConstructorArg().out, is(equalTo("value.txt")));
config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "other value"))).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
node = parser.getTargetNode(eventBus, cell, false, executorService, buildTarget).castArg(GenruleDescription.Arg.class).get();
assertThat(node.getConstructorArg().out, is(equalTo("other value.txt")));
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method whenUnrelatedEnvChangesThenCachedRulesAreNotInvalidated.
@Test
public void whenUnrelatedEnvChangesThenCachedRulesAreNotInvalidated() throws Exception {
Path buckFile = cellRoot.resolve("BUCK");
Files.write(buckFile, Joiner.on("").join(ImmutableList.of("import os\n", "os.getenv('FOO')\n", "genrule(name = 'cake', out = 'file.txt', cmd = 'touch $OUT')\n")).getBytes(UTF_8));
BuckConfig config = FakeBuckConfig.builder().setEnvironment(ImmutableMap.<String, String>builder().putAll(System.getenv()).put("FOO", "value").put("BAR", "something").build()).setFilesystem(filesystem).build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Call filterAllTargetsInProject to request cached rules.
config = FakeBuckConfig.builder().setEnvironment(ImmutableMap.<String, String>builder().putAll(System.getenv()).put("FOO", "value").put("BAR", "something else").build()).setFilesystem(filesystem).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Test that the second parseBuildFile call repopulated the cache.
assertEquals("Should not have invalidated.", 1, counter.calls);
}
Aggregations