Search in sources :

Example 21 with Cell

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

the class IntraCellIntegrationTest method shouldTreatCellBoundariesAsVisibilityBoundariesToo.

@SuppressWarnings("PMD.EmptyCatchBlock")
@Test
public void shouldTreatCellBoundariesAsVisibilityBoundariesToo() throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "intracell/visibility", tmp);
    workspace.setUp();
    // We don't need to do a build. It's enough to just parse these things.
    Cell cell = workspace.asCell();
    TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
    // This parses cleanly
    parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(cell.getFilesystem(), "//just-a-directory:rule")));
    Cell childCell = cell.getCell(BuildTargetFactory.newInstance(workspace.getDestPath().resolve("child-repo"), "//:child-target"));
    try {
        // Whereas, because visibility is limited to the same cell, this won't.
        parser.buildTargetGraph(BuckEventBusFactory.newInstance(), childCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(childCell.getFilesystem(), "//:child-target")));
        fail("Didn't expect parsing to work because of visibility");
    } catch (HumanReadableException e) {
    // This is expected
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) HumanReadableException(com.facebook.buck.util.HumanReadableException) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Cell(com.facebook.buck.rules.Cell) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ParserConfig(com.facebook.buck.parser.ParserConfig) Parser(com.facebook.buck.parser.Parser) Test(org.junit.Test)

Example 22 with Cell

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

the class DistBuildFileHashesIntegrationTest method createDistBuildFileHashes.

private DistBuildFileHashes createDistBuildFileHashes(TargetGraph targetGraph, Cell rootCell) throws IOException {
    ActionGraphCache cache = new ActionGraphCache(new BroadcastEventListener());
    ActionGraphAndResolver actionGraphAndResolver = cache.getActionGraph(BuckEventBusFactory.newInstance(), true, false, targetGraph, KEY_SEED);
    BuildRuleResolver ruleResolver = actionGraphAndResolver.getResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    DistBuildCellIndexer cellIndexer = new DistBuildCellIndexer(rootCell);
    ImmutableList.Builder<ProjectFileHashCache> allCaches = ImmutableList.builder();
    allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(rootCell.getFilesystem()));
    for (Path cellPath : rootCell.getKnownRoots()) {
        Cell cell = rootCell.getCell(cellPath);
        allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(cell.getFilesystem()));
    }
    allCaches.addAll(DefaultFileHashCache.createOsRootDirectoriesCaches());
    StackedFileHashCache stackedCache = new StackedFileHashCache(allCaches.build());
    return new DistBuildFileHashes(actionGraphAndResolver.getActionGraph(), sourcePathResolver, ruleFinder, stackedCache, cellIndexer, MoreExecutors.newDirectExecutorService(), /* keySeed */
    KEY_SEED, rootCell);
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) Cell(com.facebook.buck.rules.Cell)

Example 23 with Cell

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

the class DistBuildStateTest method throwsOnPlatformMismatch.

@Test
public void throwsOnPlatformMismatch() throws IOException, InterruptedException {
    ProjectFilesystem filesystem = createJavaOnlyFilesystem("/opt/buck");
    Config config = new Config(ConfigBuilder.rawFromLines());
    BuckConfig buckConfig = new BuckConfig(config, filesystem, Architecture.MIPSEL, Platform.UNKNOWN, ImmutableMap.<String, String>builder().putAll(System.getenv()).put("envKey", "envValue").build(), new DefaultCellPathResolver(filesystem.getRootPath(), config));
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(buckConfig).build();
    BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(cell), emptyActionGraph(), createDefaultCodec(cell, Optional.empty()), createTargetGraph(filesystem), ImmutableSet.of(BuildTargetFactory.newInstance(filesystem.getRootPath(), "//:dummy")));
    expectedException.expect(IllegalStateException.class);
    DistBuildState.load(Optional.empty(), dump, cell, knownBuildRuleTypesFactory);
}
Also used : DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Config(com.facebook.buck.config.Config) ParserConfig(com.facebook.buck.parser.ParserConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 24 with Cell

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

the class DistBuildStateTest method emptyActionGraph.

private DistBuildFileHashes emptyActionGraph() throws IOException, InterruptedException {
    ActionGraph actionGraph = new ActionGraph(ImmutableList.of());
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ProjectFilesystem projectFilesystem = createJavaOnlyFilesystem("/opt/buck");
    Cell rootCell = new TestCellBuilder().setFilesystem(projectFilesystem).setBuckConfig(FakeBuckConfig.builder().build()).build();
    return new DistBuildFileHashes(actionGraph, sourcePathResolver, ruleFinder, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem))), Functions.constant(0), MoreExecutors.newDirectExecutorService(), /* keySeed */
    0, rootCell);
}
Also used : ActionGraph(com.facebook.buck.rules.ActionGraph) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Cell(com.facebook.buck.rules.Cell) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder)

Example 25 with Cell

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

the class DistBuildStateTest method worksCrossCell.

@Test
public void worksCrossCell() throws IOException, InterruptedException {
    ProjectFilesystem parentFs = createJavaOnlyFilesystem("/saving");
    Path cell1Root = parentFs.resolve("cell1");
    Path cell2Root = parentFs.resolve("cell2");
    parentFs.mkdirs(cell1Root);
    parentFs.mkdirs(cell2Root);
    ProjectFilesystem cell1Filesystem = new ProjectFilesystem(cell1Root);
    ProjectFilesystem cell2Filesystem = new ProjectFilesystem(cell2Root);
    Config config = new Config(ConfigBuilder.rawFromLines("[cache]", "repository=somerepo", "[repositories]", "cell2 = " + cell2Root.toString()));
    BuckConfig buckConfig = new BuckConfig(config, cell1Filesystem, Architecture.detect(), Platform.detect(), ImmutableMap.<String, String>builder().putAll(System.getenv()).put("envKey", "envValue").build(), new DefaultCellPathResolver(cell1Root, config));
    Cell rootCellWhenSaving = new TestCellBuilder().setFilesystem(cell1Filesystem).setBuckConfig(buckConfig).build();
    BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCellWhenSaving), emptyActionGraph(), createDefaultCodec(rootCellWhenSaving, Optional.empty()), createCrossCellTargetGraph(cell1Filesystem, cell2Filesystem), ImmutableSet.of(BuildTargetFactory.newInstance(cell1Filesystem.getRootPath(), "//:dummy")));
    Cell rootCellWhenLoading = new TestCellBuilder().setFilesystem(createJavaOnlyFilesystem("/loading")).build();
    Config localConfig = new Config(ConfigBuilder.rawFromLines("[cache]", "slb_server_pool=http://someserver:8080"));
    BuckConfig localBuckConfig = new BuckConfig(localConfig, cell1Filesystem, Architecture.detect(), Platform.detect(), ImmutableMap.<String, String>builder().putAll(System.getenv()).put("envKey", "envValue").build(), new DefaultCellPathResolver(cell1Root, localConfig));
    DistBuildState distributedBuildState = DistBuildState.load(Optional.of(localBuckConfig), dump, rootCellWhenLoading, knownBuildRuleTypesFactory);
    ImmutableMap<Integer, Cell> cells = distributedBuildState.getCells();
    assertThat(cells, Matchers.aMapWithSize(2));
    BuckConfig rootCellBuckConfig = cells.get(0).getBuckConfig();
    Optional<ImmutableMap<String, String>> cacheSection = rootCellBuckConfig.getSection("cache");
    assertTrue(cacheSection.isPresent());
    assertTrue(cacheSection.get().containsKey("repository"));
    assertThat(cacheSection.get().get("repository"), Matchers.equalTo("somerepo"));
    assertThat(cacheSection.get().get("slb_server_pool"), Matchers.equalTo("http://someserver:8080"));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) Config(com.facebook.buck.config.Config) ParserConfig(com.facebook.buck.parser.ParserConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) 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