Search in sources :

Example 26 with BuckConfig

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

Example 27 with BuckConfig

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);
}
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) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 28 with BuckConfig

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()));
}
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) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 29 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 30 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)

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