Search in sources :

Example 16 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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 17 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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 18 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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 19 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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 20 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder 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

TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)50 Cell (com.facebook.buck.rules.Cell)39 Test (org.junit.Test)39 Path (java.nio.file.Path)31 BuckConfig (com.facebook.buck.cli.BuckConfig)29 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)29 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)18 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 BuildTarget (com.facebook.buck.model.BuildTarget)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 Before (org.junit.Before)8 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)7 ParserConfig (com.facebook.buck.parser.ParserConfig)7 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)6 TestConsole (com.facebook.buck.testutil.TestConsole)6 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)5 Config (com.facebook.buck.config.Config)5 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)5 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)5