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);
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserTest method whenEnvAddedThenCachedRulesAreInvalidated.
@Test
public void whenEnvAddedThenCachedRulesAreInvalidated() 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().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().setFilesystem(filesystem).setEnvironment(ImmutableMap.<String, String>builder().putAll(System.getenv()).put("FOO", "other value").build()).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 have invalidated.", 2, counter.calls);
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class OCamlIntegrationTest method checkOcamlIsConfigured.
@Before
public void checkOcamlIsConfigured() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "ocaml", tmp);
workspace.setUp();
ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
Config rawConfig = Configs.createDefaultConfig(filesystem.getRootPath());
BuckConfig buckConfig = new BuckConfig(rawConfig, filesystem, Architecture.detect(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new DefaultCellPathResolver(filesystem.getRootPath(), rawConfig));
OcamlBuckConfig ocamlBuckConfig = new OcamlBuckConfig(buckConfig, DefaultCxxPlatforms.build(Platform.detect(), filesystem, new CxxBuckConfig(buckConfig)));
assumeTrue(ocamlBuckConfig.getOcamlCompiler().isPresent());
assumeTrue(ocamlBuckConfig.getOcamlBytecodeCompiler().isPresent());
assumeTrue(ocamlBuckConfig.getOcamlDepTool().isPresent());
assumeTrue(ocamlBuckConfig.getYaccCompiler().isPresent());
assumeTrue(ocamlBuckConfig.getLexCompiler().isPresent());
}
use of com.facebook.buck.cli.BuckConfig in project buck by facebook.
the class ParserBenchmark method setUpBenchmark.
@BeforeExperiment
public void setUpBenchmark() throws Exception {
tempDir.before();
Path root = tempDir.getRoot();
Files.createDirectories(root);
filesystem = new ProjectFilesystem(root);
Path fbJavaRoot = root.resolve(root.resolve("java/com/facebook"));
Files.createDirectories(fbJavaRoot);
for (int i = 0; i < targetCount; i++) {
Path targetRoot = fbJavaRoot.resolve(String.format("target_%d", i));
Files.createDirectories(targetRoot);
Path buckFile = targetRoot.resolve("BUCK");
Files.createFile(buckFile);
Files.write(buckFile, ("java_library(name = 'foo', srcs = ['A.java'])\n" + "genrule(name = 'baz', out = '')\n").getBytes("UTF-8"));
Path javaFile = targetRoot.resolve("A.java");
Files.createFile(javaFile);
Files.write(javaFile, String.format("package com.facebook.target_%d; class A {}", i).getBytes("UTF-8"));
}
ImmutableMap.Builder<String, ImmutableMap<String, String>> configSectionsBuilder = ImmutableMap.builder();
if (threadCount > 1) {
configSectionsBuilder.put("project", ImmutableMap.of("parallel_parsing", "true", "parsing_threads", Integer.toString(threadCount)));
}
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(configSectionsBuilder.build()).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
eventBus = BuckEventBusFactory.newInstance();
executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount));
DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(typeCoercerFactory);
parser = new Parser(new BroadcastEventListener(), config.getView(ParserConfig.class), typeCoercerFactory, marshaller);
}
Aggregations