Search in sources :

Example 31 with Cell

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

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

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class ParserTest method resolveTargetSpecsPreservesOrder.

@Test
public void resolveTargetSpecsPreservesOrder() throws Exception {
    BuildTarget foo = BuildTargetFactory.newInstance(filesystem, "//foo:foo");
    Path buckFile = cellRoot.resolve("foo/BUCK");
    Files.createDirectories(buckFile.getParent());
    Files.write(buckFile, "genrule(name='foo', out='foo', cmd='foo')".getBytes(UTF_8));
    BuildTarget bar = BuildTargetFactory.newInstance(filesystem, "//bar:bar");
    buckFile = cellRoot.resolve("bar/BUCK");
    Files.createDirectories(buckFile.getParent());
    Files.write(buckFile, "genrule(name='bar', out='bar', cmd='bar')".getBytes(UTF_8));
    ImmutableList<ImmutableSet<BuildTarget>> targets = parser.resolveTargetSpecs(eventBus, cell, false, executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("bar"), cell.getRoot())), TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("foo"), cell.getRoot()))), SpeculativeParsing.of(true), ParserConfig.ApplyDefaultFlavorsMode.ENABLED);
    assertThat(targets, equalTo(ImmutableList.of(ImmutableSet.of(bar), ImmutableSet.of(foo))));
    targets = parser.resolveTargetSpecs(eventBus, cell, false, executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("foo"), cell.getRoot())), TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get("bar"), cell.getRoot()))), SpeculativeParsing.of(true), ParserConfig.ApplyDefaultFlavorsMode.ENABLED);
    assertThat(targets, equalTo(ImmutableList.of(ImmutableSet.of(foo), ImmutableSet.of(bar))));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) GenruleDescription(com.facebook.buck.shell.GenruleDescription) Arrays(java.util.Arrays) ObjectMappers(com.facebook.buck.util.ObjectMappers) TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) InternalFlavor(com.facebook.buck.model.InternalFlavor) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuckConfig(com.facebook.buck.cli.BuckConfig) FluentIterable(com.google.common.collect.FluentIterable) After(org.junit.After) Map(java.util.Map) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ParseBuckFileEvent(com.facebook.buck.json.ParseBuckFileEvent) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) Parameterized(org.junit.runners.Parameterized) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Collection(java.util.Collection) BuildTargetException(com.facebook.buck.model.BuildTargetException) Platform(com.facebook.buck.util.environment.Platform) BuildTarget(com.facebook.buck.model.BuildTarget) Executors(java.util.concurrent.Executors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) Predicate(com.google.common.base.Predicate) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Assume.assumeTrue(org.junit.Assume.assumeTrue) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Matchers.containsString(org.hamcrest.Matchers.containsString) SortedMap(java.util.SortedMap) Joiner(com.google.common.base.Joiner) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BuckEventBus(com.facebook.buck.event.BuckEventBus) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) RunWith(org.junit.runner.RunWith) WatchEventsForTests(com.facebook.buck.testutil.WatchEventsForTests) UTF_8(com.google.common.base.Charsets.UTF_8) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) BuildRule(com.facebook.buck.rules.BuildRule) StandardWatchEventKinds(java.nio.file.StandardWatchEventKinds) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) Subscribe(com.google.common.eventbus.Subscribe) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ExpectedException(org.junit.rules.ExpectedException) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) MoreCollectors(com.facebook.buck.util.MoreCollectors) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) DEFAULT_BUILD_FILE_NAME(com.facebook.buck.parser.ParserConfig.DEFAULT_BUILD_FILE_NAME) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) HashCode(com.google.common.hash.HashCode) TargetNode(com.facebook.buck.rules.TargetNode) WatchEvent(java.nio.file.WatchEvent) WatchEventsForTests.createPathEvent(com.facebook.buck.testutil.WatchEventsForTests.createPathEvent) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) MorePaths(com.facebook.buck.io.MorePaths) Rule(org.junit.Rule) Paths(java.nio.file.Paths) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Test(org.junit.Test)

Example 34 with Cell

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class ParsePipelineTest method exceptionOnMalformedRawNode.

@Test
public void exceptionOnMalformedRawNode() throws Exception {
    try (Fixture fixture = createMultiThreadedFixture("pipeline_test")) {
        Cell cell = fixture.getCell();
        Path rootBuildFilePath = cell.getFilesystem().resolve("BUCK");
        fixture.getRawNodeParsePipelineCache().putComputedNodeIfNotPresent(cell, rootBuildFilePath, ImmutableSet.of(ImmutableMap.of("name", (Object) "bar")));
        expectedException.expect(IllegalStateException.class);
        expectedException.expectMessage("malformed raw data");
        fixture.getTargetNodeParsePipeline().getAllNodes(cell, rootBuildFilePath);
    }
}
Also used : Path(java.nio.file.Path) Cell(com.facebook.buck.rules.Cell) Test(org.junit.Test)

Example 35 with Cell

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class ParsePipelineTest method recoversAfterSyntaxError.

@Test
public void recoversAfterSyntaxError() throws Exception {
    try (Fixture fixture = createSynchronousExecutionFixture("syntax_error")) {
        final Cell cell = fixture.getCell();
        try {
            fixture.getTargetNodeParsePipeline().getNode(cell, BuildTargetFactory.newInstance(cell.getFilesystem(), "//error:error"));
            Assert.fail("Expected BuildFileParseException");
        } catch (BuildFileParseException e) {
            assertThat(e.getMessage(), containsString("crash!"));
        }
        fixture.getTargetNodeParsePipeline().getNode(cell, BuildTargetFactory.newInstance(cell.getFilesystem(), "//correct:correct"));
    }
}
Also used : Cell(com.facebook.buck.rules.Cell) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Test(org.junit.Test)

Aggregations

Cell (com.facebook.buck.rules.Cell)87 Test (org.junit.Test)57 Path (java.nio.file.Path)46 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)41 BuildTarget (com.facebook.buck.model.BuildTarget)25 BuckConfig (com.facebook.buck.cli.BuckConfig)24 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)22 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 ImmutableSet (com.google.common.collect.ImmutableSet)14 BuckEventBus (com.facebook.buck.event.BuckEventBus)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)11 ParserConfig (com.facebook.buck.parser.ParserConfig)11 IOException (java.io.IOException)11 Map (java.util.Map)11 TargetNode (com.facebook.buck.rules.TargetNode)10 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)10 ImmutableList (com.google.common.collect.ImmutableList)10