Search in sources :

Example 11 with BuildJobState

use of com.facebook.buck.distributed.thrift.BuildJobState in project buck by facebook.

the class DistBuildStateTest method canReconstructGraphAndTopLevelBuildTargets.

@Test
public void canReconstructGraphAndTopLevelBuildTargets() throws Exception {
    ProjectWorkspace projectWorkspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_java_target", temporaryFolder);
    projectWorkspace.setUp();
    Cell cell = projectWorkspace.asCell();
    ProjectFilesystem projectFilesystem = cell.getFilesystem();
    projectFilesystem.mkdirs(projectFilesystem.getBuckPaths().getBuckOut());
    BuckConfig buckConfig = cell.getBuckConfig();
    TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
    Parser parser = new Parser(new BroadcastEventListener(), buckConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
    TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, /* enableProfiling */
    false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib1"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib2"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib3")));
    DistBuildTargetGraphCodec targetGraphCodec = createDefaultCodec(cell, Optional.of(parser));
    BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(cell), emptyActionGraph(), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib1"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib2")));
    Cell rootCellWhenLoading = new TestCellBuilder().setFilesystem(createJavaOnlyFilesystem("/loading")).build();
    DistBuildState distributedBuildState = DistBuildState.load(Optional.empty(), dump, rootCellWhenLoading, knownBuildRuleTypesFactory);
    ProjectFilesystem reconstructedCellFilesystem = distributedBuildState.getCells().get(0).getFilesystem();
    TargetGraph reconstructedGraph = distributedBuildState.createTargetGraph(targetGraphCodec).getTargetGraph();
    assertEquals(reconstructedGraph.getNodes().stream().map(targetNode -> targetNode.castArg(JavaLibraryDescription.Arg.class).get()).sorted().map(targetNode -> targetNode.getConstructorArg().srcs).collect(Collectors.toList()), Lists.newArrayList("A.java", "B.java", "C.java").stream().map(f -> reconstructedCellFilesystem.getPath(f)).map(p -> new PathSourcePath(reconstructedCellFilesystem, p)).map(ImmutableSortedSet::of).collect(Collectors.toList()));
}
Also used : BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ObjectMappers(com.facebook.buck.util.ObjectMappers) TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuckConfig(com.facebook.buck.cli.BuckConfig) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Platform(com.facebook.buck.util.environment.Platform) DefaultParserTargetNodeFactory(com.facebook.buck.parser.DefaultParserTargetNodeFactory) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) BuildTarget(com.facebook.buck.model.BuildTarget) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) KnownBuildRuleTypesFactory(com.facebook.buck.rules.KnownBuildRuleTypesFactory) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) BuckEventBus(com.facebook.buck.event.BuckEventBus) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) Config(com.facebook.buck.config.Config) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) Lists(com.google.common.collect.Lists) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ExpectedException(org.junit.rules.ExpectedException) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Functions(com.google.common.base.Functions) Parser(com.facebook.buck.parser.Parser) TargetNode(com.facebook.buck.rules.TargetNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) Architecture(com.facebook.buck.util.environment.Architecture) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ConfigBuilder(com.facebook.buck.config.ConfigBuilder) ParserTargetNodeFactory(com.facebook.buck.parser.ParserTargetNodeFactory) Rule(org.junit.Rule) TestConsole(com.facebook.buck.testutil.TestConsole) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Preconditions(com.google.common.base.Preconditions) Assert.assertEquals(org.junit.Assert.assertEquals) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Parser(com.facebook.buck.parser.Parser) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 12 with BuildJobState

use of com.facebook.buck.distributed.thrift.BuildJobState in project buck by facebook.

the class DistBuildService method uploadTargetGraph.

public ListenableFuture<Void> uploadTargetGraph(final BuildJobState buildJobStateArg, final StampedeId stampedeId, ListeningExecutorService executorService) {
    // TODO(shivanker): We shouldn't be doing this. Fix after we stop reading all files into memory.
    final BuildJobState buildJobState = buildJobStateArg.deepCopy();
    return executorService.submit(() -> {
        // Get rid of file contents from buildJobState
        for (BuildJobStateFileHashes cell : buildJobState.getFileHashes()) {
            if (!cell.isSetEntries()) {
                continue;
            }
            for (BuildJobStateFileHashEntry file : cell.getEntries()) {
                file.unsetContents();
            }
        }
        // Now serialize and send the whole buildJobState
        StoreBuildGraphRequest storeBuildGraphRequest = new StoreBuildGraphRequest();
        storeBuildGraphRequest.setStampedeId(stampedeId);
        storeBuildGraphRequest.setBuildGraph(BuildJobStateSerializer.serialize(buildJobState));
        FrontendRequest request = new FrontendRequest();
        request.setType(FrontendRequestType.STORE_BUILD_GRAPH);
        request.setStoreBuildGraphRequest(storeBuildGraphRequest);
        makeRequestChecked(request);
        // No response expected.
        return null;
    });
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) StoreBuildGraphRequest(com.facebook.buck.distributed.thrift.StoreBuildGraphRequest) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest)

Aggregations

BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)12 Test (org.junit.Test)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 BuckConfig (com.facebook.buck.cli.BuckConfig)6 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)6 ParserConfig (com.facebook.buck.parser.ParserConfig)6 Cell (com.facebook.buck.rules.Cell)6 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)6 Config (com.facebook.buck.config.Config)4 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)4 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)4 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4 Path (java.nio.file.Path)4 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)3 Parser (com.facebook.buck.parser.Parser)3 TargetGraph (com.facebook.buck.rules.TargetGraph)3 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)3 TypeCoercerFactory (com.facebook.buck.rules.coercer.TypeCoercerFactory)3 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)3