Search in sources :

Example 21 with BuckConfig

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

the class KotlinBuckConfigTest method testFindsKotlinCompilerInConfigWithRelativePath.

@Test
public void testFindsKotlinCompilerInConfigWithRelativePath() throws HumanReadableException, IOException {
    // Get faux kotlinc binary location in project
    Path kotlinCompiler = workspace.resolve("bin").resolve("kotlinc");
    MoreFiles.makeExecutable(kotlinCompiler);
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.resolve("."));
    BuckConfig buckConfig = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(ImmutableMap.of("kotlin", ImmutableMap.of("compiler", "bin/kotlinc"))).build();
    KotlinBuckConfig kotlinBuckConfig = new KotlinBuckConfig(buckConfig);
    String command = kotlinBuckConfig.getKotlinCompiler().get().getCommandPrefix(null).get(0);
    assertEquals(command, kotlinCompiler.toString());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 22 with BuckConfig

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

the class KotlinBuckConfigTest method testFindsKotlinRuntimeInConfigWithAbsolutePath.

@Test
public void testFindsKotlinRuntimeInConfigWithAbsolutePath() throws HumanReadableException, IOException {
    Path kotlinRuntime = workspace.resolve("lib").resolve("kotlin-runtime.jar");
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(ImmutableMap.of("kotlin", ImmutableMap.of("runtime_jar", kotlinRuntime.toString()))).setEnvironment(ImmutableMap.of("KOTLIN_HOME", workspace.getPath(".").normalize().toString())).build();
    KotlinBuckConfig kotlinBuckConfig = new KotlinBuckConfig(buckConfig);
    Path runtimeJar = kotlinBuckConfig.getPathToRuntimeJar().getRight();
    assertEquals(runtimeJar.toString(), kotlinRuntime.toString());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Test(org.junit.Test)

Example 23 with BuckConfig

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

the class KotlinBuckConfigTest method testFindsKotlinCompilerInHome.

@Test
public void testFindsKotlinCompilerInHome() throws HumanReadableException, IOException {
    // Get faux kotlinc binary location in project
    Path kotlinCompiler = workspace.resolve("bin").resolve("kotlinc");
    MoreFiles.makeExecutable(kotlinCompiler);
    BuckConfig buckConfig = FakeBuckConfig.builder().setEnvironment(ImmutableMap.of("KOTLIN_HOME", workspace.getPath(".").normalize().toString())).build();
    KotlinBuckConfig kotlinBuckConfig = new KotlinBuckConfig(buckConfig);
    String command = kotlinBuckConfig.getKotlinCompiler().get().getCommandPrefix(null).get(0);
    assertEquals(command, kotlinCompiler.toString());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Test(org.junit.Test)

Example 24 with BuckConfig

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

the class ParserTest method whenEnvChangesThenCachedRulesAreInvalidated.

@Test
public void whenEnvChangesThenCachedRulesAreInvalidated() 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").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().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 25 with BuckConfig

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

the class ParserTest method whenBuckConfigAddedThenCachedRulesAreInvalidated.

@Test
public void whenBuckConfigAddedThenCachedRulesAreInvalidated() 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().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).setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "other value"))).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)

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