Search in sources :

Example 76 with BuckConfig

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

the class DistBuildState method load.

public static DistBuildState load(// e.g. the slave's .buckconfig
Optional<BuckConfig> localBuckConfig, BuildJobState jobState, Cell rootCell, KnownBuildRuleTypesFactory knownBuildRuleTypesFactory) throws IOException {
    ProjectFilesystem rootCellFilesystem = rootCell.getFilesystem();
    ImmutableMap.Builder<Path, BuckConfig> cellConfigs = ImmutableMap.builder();
    ImmutableMap.Builder<Path, ProjectFilesystem> cellFilesystems = ImmutableMap.builder();
    ImmutableMap.Builder<Integer, Path> cellIndex = ImmutableMap.builder();
    Path sandboxPath = rootCellFilesystem.getRootPath().resolve(rootCellFilesystem.getBuckPaths().getRemoteSandboxDir());
    rootCellFilesystem.mkdirs(sandboxPath);
    Path uniqueBuildRoot = Files.createTempDirectory(sandboxPath, "build");
    for (Map.Entry<Integer, BuildJobStateCell> remoteCellEntry : jobState.getCells().entrySet()) {
        BuildJobStateCell remoteCell = remoteCellEntry.getValue();
        Path cellRoot = uniqueBuildRoot.resolve(remoteCell.getNameHint());
        Files.createDirectories(cellRoot);
        Config config = createConfig(remoteCell.getConfig(), localBuckConfig);
        ProjectFilesystem projectFilesystem = new ProjectFilesystem(cellRoot, config);
        BuckConfig buckConfig = createBuckConfig(config, projectFilesystem, remoteCell.getConfig());
        cellConfigs.put(cellRoot, buckConfig);
        cellFilesystems.put(cellRoot, projectFilesystem);
        cellIndex.put(remoteCellEntry.getKey(), cellRoot);
    }
    CellProvider cellProvider = CellProvider.createForDistributedBuild(cellConfigs.build(), cellFilesystems.build(), knownBuildRuleTypesFactory);
    ImmutableBiMap<Integer, Cell> cells = ImmutableBiMap.copyOf(Maps.transformValues(cellIndex.build(), cellProvider::getCellByPath));
    return new DistBuildState(jobState, cells);
}
Also used : Path(java.nio.file.Path) CellProvider(com.facebook.buck.rules.CellProvider) Config(com.facebook.buck.config.Config) BuckConfig(com.facebook.buck.cli.BuckConfig) RawConfig(com.facebook.buck.config.RawConfig) BuildJobStateBuckConfig(com.facebook.buck.distributed.thrift.BuildJobStateBuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) BuildJobStateCell(com.facebook.buck.distributed.thrift.BuildJobStateCell) BuckConfig(com.facebook.buck.cli.BuckConfig) BuildJobStateBuckConfig(com.facebook.buck.distributed.thrift.BuildJobStateBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.facebook.buck.rules.Cell) BuildJobStateCell(com.facebook.buck.distributed.thrift.BuildJobStateCell)

Example 77 with BuckConfig

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

the class CxxPlatformUtils method getDefaultPlatform.

public static CxxPlatform getDefaultPlatform(Path root) throws IOException {
    Config rawConfig = Configs.createDefaultConfig(root);
    BuckConfig buckConfig = new BuckConfig(rawConfig, new ProjectFilesystem(root), Architecture.detect(), Platform.detect(), ImmutableMap.of(), new DefaultCellPathResolver(root, rawConfig));
    return DefaultCxxPlatforms.build(Platform.detect(), new ProjectFilesystem(root), new CxxBuckConfig(buckConfig));
}
Also used : DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Config(com.facebook.buck.config.Config) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 78 with BuckConfig

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

the class CxxPlatformsTest method unknownDefaultPlatformSetInConfigFallsBackToSystemDefault.

@Test
public void unknownDefaultPlatformSetInConfigFallsBackToSystemDefault() {
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("default_platform", "borland_cxx_452"));
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(sections).build();
    assertThat(CxxPlatforms.getConfigDefaultCxxPlatform(new CxxBuckConfig(buckConfig), ImmutableMap.of(), CxxPlatformUtils.DEFAULT_PLATFORM), equalTo(CxxPlatformUtils.DEFAULT_PLATFORM));
}
Also used : FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 79 with BuckConfig

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

the class RageConfigTest method testEmpty.

@Test
public void testEmpty() {
    BuckConfig buckConfig = FakeBuckConfig.builder().build();
    RageConfig config = RageConfig.of(buckConfig);
    assertThat(config.getReportUploadPath(), Matchers.equalTo(RageConfig.UPLOAD_PATH));
    assertThat(config.getFrontendConfig().get().tryCreatingClientSideSlb(clock, eventBus, threadFactory), Matchers.equalTo(Optional.empty()));
}
Also used : FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Test(org.junit.Test)

Example 80 with BuckConfig

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

the class CellTest method shouldApplyCellConfigOverrides.

@Test
public void shouldApplyCellConfigOverrides() throws IOException, InterruptedException {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path root = vfs.getPath("/opt/local/");
    Path cell1Root = root.resolve("repo1");
    Files.createDirectories(cell1Root);
    Path cell2Root = root.resolve("repo2");
    Files.createDirectories(cell2Root);
    Path cell3Root = root.resolve("repo3");
    Files.createDirectories(cell3Root);
    ProjectFilesystem filesystem1 = new ProjectFilesystem(cell1Root.toAbsolutePath());
    ProjectFilesystem filesystem2 = new ProjectFilesystem(cell2Root.toAbsolutePath());
    ProjectFilesystem filesystem3 = new ProjectFilesystem(cell3Root.toAbsolutePath());
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem1).setSections("[repositories]", "second = " + cell2Root.toString(), "third = " + cell3Root.toString()).build();
    Files.write(cell2Root.resolve(".buckconfig"), ImmutableList.of("[repositories]", "third = " + cell3Root.toString()), StandardCharsets.UTF_8);
    Cell cell1 = new TestCellBuilder().setBuckConfig(config).setFilesystem(filesystem1).setCellConfigOverride(CellConfig.builder().put(RelativeCellName.fromComponents("second"), "test", "value", "cell2").put(CellConfig.ALL_CELLS_OVERRIDE, "test", "common_value", "all").build()).build();
    BuildTarget target = BuildTargetFactory.newInstance(filesystem2, "//does/not:matter");
    Cell cell2 = cell1.getCell(target);
    assertThat(cell2.getBuckConfig().getValue("test", "value"), Matchers.equalTo(Optional.of("cell2")));
    BuildTarget target3 = BuildTargetFactory.newInstance(filesystem3, "//does/not:matter");
    Cell cell3 = cell1.getCell(target3);
    assertThat(cell3.getBuckConfig().getValue("test", "common_value"), Matchers.equalTo(Optional.of("all")));
}
Also used : Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) FileSystem(java.nio.file.FileSystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) 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