Search in sources :

Example 71 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserTest method whenNotifiedOfContainedFileAddCachedAncestorsAreInvalidatedWithoutBoundaryChecks.

@Test
public void whenNotifiedOfContainedFileAddCachedAncestorsAreInvalidatedWithoutBoundaryChecks() throws Exception {
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[buildfile]", "includes = //java/com/facebook/defaultIncludeFile", "[project]", "check_package_boundary = false", "temp_files = ''").build();
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    Path testAncestorBuildFile = tempDir.newFile("java/BUCK").toRealPath();
    Files.write(testAncestorBuildFile, "java_library(name = 'root')\n".getBytes(UTF_8));
    // Call parseBuildFile to populate the cache.
    getRawTargetNodes(parser, eventBus, cell, false, executorService, testAncestorBuildFile);
    // Process event.
    WatchEvent<Path> event = createPathEvent(Paths.get("java/com/facebook/SomeClass.java"), StandardWatchEventKinds.ENTRY_CREATE);
    parser.onFileSystemChange(event);
    // Call parseBuildFile to request cached rules.
    getRawTargetNodes(parser, eventBus, cell, false, executorService, testAncestorBuildFile);
    // Test that the second parseBuildFile call repopulated the cache.
    assertEquals("Should have invalidated cache.", 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) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 72 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserTest method defaultFlavorsInArgsOverrideDefaultsFromConfig.

@Test
public void defaultFlavorsInArgsOverrideDefaultsFromConfig() 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']), " + "  defaults={'platform':'macosx-x86_64'}" + ")").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("macosx-x86_64"), 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 73 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserTest method whenAllRulesAreRequestedWithDifferingIncludesThenRulesAreParsedTwice.

@Test
public void whenAllRulesAreRequestedWithDifferingIncludesThenRulesAreParsedTwice() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(ImmutableMap.of(ParserConfig.BUILDFILE_SECTION_NAME, ImmutableMap.of(ParserConfig.INCLUDES_PROPERTY_NAME, "//bar.py"))).build();
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    assertEquals("Should have invalidated cache.", 2, counter.calls);
}
Also used : 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 74 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserTest method whenBuckConfigEntryRemovedThenCachedRulesAreInvalidated.

@Test
public void whenBuckConfigEntryRemovedThenCachedRulesAreInvalidated() 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"))).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).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) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 75 with BuckConfig

use of com.facebook.buck.cli.BuckConfig in project buck by facebook.

the class ParserTest method whenEnvironmentNotChangedThenCacheRulesAreNotInvalidated.

@Test
public void whenEnvironmentNotChangedThenCacheRulesAreNotInvalidated() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setEnvironment(ImmutableMap.of("Some Key", "Some Value", "PATH", System.getenv("PATH"))).build();
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    // Call filterAllTargetsInProject to populate the cache.
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    // Call filterAllTargetsInProject to request cached rules with identical environment.
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    // Test that the second parseBuildFile call repopulated the cache.
    assertEquals("Should not have invalidated cache.", 1, counter.calls);
}
Also used : 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)

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