Search in sources :

Example 31 with BuckConfig

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")));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) GenruleDescription(com.facebook.buck.shell.GenruleDescription) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 32 with BuckConfig

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);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 33 with BuckConfig

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);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 34 with BuckConfig

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());
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Config(com.facebook.buck.config.Config) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Before(org.junit.Before)

Example 35 with BuckConfig

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);
}
Also used : Path(java.nio.file.Path) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) BeforeExperiment(com.google.caliper.BeforeExperiment)

Aggregations

BuckConfig (com.facebook.buck.cli.BuckConfig)98 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)89 Test (org.junit.Test)74 Path (java.nio.file.Path)46 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)37 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)29 PathSourcePath (com.facebook.buck.rules.PathSourcePath)27 Cell (com.facebook.buck.rules.Cell)22 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)17 ImmutableMap (com.google.common.collect.ImmutableMap)17 Config (com.facebook.buck.config.Config)15 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)14 BuildTarget (com.facebook.buck.model.BuildTarget)12 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)9 ParserConfig (com.facebook.buck.parser.ParserConfig)8 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)7 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)7 TestConsole (com.facebook.buck.testutil.TestConsole)7 Optional (java.util.Optional)7 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)6