Search in sources :

Example 1 with TargetGraphAndBuildTargets

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

the class TargetsCommand method buildTargetGraphAndTargets.

private TargetGraphAndBuildTargets buildTargetGraphAndTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException, VersionException {
    ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
    boolean ignoreBuckAutodepsFiles = false;
    // Parse the entire action graph, or (if targets are specified), only the specified targets and
    // their dependencies. If we're detecting test changes we need the whole graph as tests are not
    // dependencies.
    TargetGraphAndBuildTargets targetGraphAndBuildTargets;
    if (getArguments().isEmpty() || isDetectTestChanges()) {
        targetGraphAndBuildTargets = TargetGraphAndBuildTargets.builder().setBuildTargets(ImmutableSet.of()).setTargetGraph(params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get(""), params.getCell().getRoot()))), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode()).getTargetGraph()).build();
    } else {
        targetGraphAndBuildTargets = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode());
    }
    return params.getBuckConfig().getTargetsVersions() ? toVersionedTargetGraph(params, targetGraphAndBuildTargets) : targetGraphAndBuildTargets;
}
Also used : ParserConfig(com.facebook.buck.parser.ParserConfig) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets)

Example 2 with TargetGraphAndBuildTargets

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

the class FetchCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    if (getArguments().isEmpty()) {
        params.getBuckEventBus().post(ConsoleEvent.severe("Must specify at least one build target to fetch."));
        return 1;
    }
    // Post the build started event, setting it to the Parser recorded start time if appropriate.
    BuildEvent.Started started = BuildEvent.started(getArguments());
    if (params.getParser().getParseStartTime().isPresent()) {
        params.getBuckEventBus().post(started, params.getParser().getParseStartTime().get());
    } else {
        params.getBuckEventBus().post(started);
    }
    FetchTargetNodeToBuildRuleTransformer ruleGenerator = createFetchTransformer(params);
    int exitCode;
    try (CommandThreadManager pool = new CommandThreadManager("Fetch", getConcurrencyLimit(params.getBuckConfig()))) {
        ActionGraphAndResolver actionGraphAndResolver;
        ImmutableSet<BuildTarget> buildTargets;
        try {
            ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
            TargetGraphAndBuildTargets result = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), /* ignoreBuckAutodepsFiles */
            false, parserConfig.getDefaultFlavorsMode());
            if (params.getBuckConfig().getBuildVersions()) {
                result = toVersionedTargetGraph(params, result);
            }
            actionGraphAndResolver = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), ruleGenerator, result.getTargetGraph()));
            buildTargets = ruleGenerator.getDownloadableTargets();
        } catch (BuildTargetException | BuildFileParseException | VersionException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
        LocalCachingBuildEngineDelegate localCachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
        try (RuleKeyCacheScope<RuleKey> ruleKeyCacheScope = getDefaultRuleKeyCacheScope(params, new RuleKeyCacheRecycler.SettingsAffectingCache(params.getBuckConfig().getKeySeed(), actionGraphAndResolver.getActionGraph()));
            Build build = createBuild(params.getBuckConfig(), actionGraphAndResolver.getActionGraph(), actionGraphAndResolver.getResolver(), params.getCell(), params.getAndroidPlatformTargetSupplier(), new CachingBuildEngine(localCachingBuildEngineDelegate, pool.getExecutor(), pool.getExecutor(), new DefaultStepRunner(), getBuildEngineMode().orElse(cachingBuildEngineBuckConfig.getBuildEngineMode()), cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> localCachingBuildEngineDelegate.getFileHashCache(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), ruleKeyCacheScope.getCache())), params.getArtifactCacheFactory().newInstance(), params.getConsole(), params.getBuckEventBus(), Optional.empty(), params.getPersistentWorkerPools(), params.getPlatform(), params.getEnvironment(), params.getObjectMapper(), params.getClock(), Optional.empty(), Optional.empty(), params.getExecutors())) {
            exitCode = build.executeAndPrintFailuresToEventBus(buildTargets, isKeepGoing(), params.getBuckEventBus(), params.getConsole(), getPathToBuildReport(params.getBuckConfig()));
        }
    }
    params.getBuckEventBus().post(BuildEvent.finished(started, exitCode));
    return exitCode;
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) RuleKey(com.facebook.buck.rules.RuleKey) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) BuildEvent(com.facebook.buck.rules.BuildEvent) BuildTarget(com.facebook.buck.model.BuildTarget) Build(com.facebook.buck.command.Build) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) RuleKeyCacheRecycler(com.facebook.buck.rules.keys.RuleKeyCacheRecycler) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) VersionException(com.facebook.buck.versions.VersionException) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig)

Example 3 with TargetGraphAndBuildTargets

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

the class BuildCommand method executeDistributedBuild.

private int executeDistributedBuild(final CommandRunnerParams params, ActionAndTargetGraphs graphs, final WeightedListeningExecutorService executorService) throws IOException, InterruptedException {
    // Distributed builds serialize and send the unversioned target graph,
    // and then deserialize and version remotely.
    TargetGraphAndBuildTargets targetGraphAndBuildTargets = graphs.unversionedTargetGraph;
    ProjectFilesystem filesystem = params.getCell().getFilesystem();
    FileHashCache fileHashCache = params.getFileHashCache();
    DistBuildTypeCoercerFactory typeCoercerFactory = new DistBuildTypeCoercerFactory(params.getObjectMapper());
    ParserTargetNodeFactory<TargetNode<?, ?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory.createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory));
    DistBuildTargetGraphCodec targetGraphCodec = new DistBuildTargetGraphCodec(params.getObjectMapper(), parserTargetNodeFactory, new Function<TargetNode<?, ?>, Map<String, Object>>() {

        @Nullable
        @Override
        public Map<String, Object> apply(TargetNode<?, ?> input) {
            try {
                return params.getParser().getRawTargetNode(params.getBuckEventBus(), params.getCell().getCell(input.getBuildTarget()), false, /* enableProfiling */
                executorService, input);
            } catch (BuildFileParseException e) {
                throw new RuntimeException(e);
            }
        }
    }, targetGraphAndBuildTargets.getBuildTargets().stream().map(t -> t.getFullyQualifiedName()).collect(Collectors.toSet()));
    BuildJobState jobState = computeDistributedBuildJobState(targetGraphCodec, params, targetGraphAndBuildTargets, graphs.actionGraph, executorService);
    if (distributedBuildStateFile != null) {
        Path stateDumpPath = Paths.get(distributedBuildStateFile);
        BuildJobStateSerializer.serialize(jobState, filesystem.newFileOutputStream(stateDumpPath));
        return 0;
    } else {
        BuckVersion buckVersion = getBuckVersion();
        Preconditions.checkArgument(params.getInvocationInfo().isPresent());
        try (DistBuildService service = DistBuildFactory.newDistBuildService(params);
            DistBuildLogStateTracker distBuildLogStateTracker = DistBuildFactory.newDistBuildLogStateTracker(params.getInvocationInfo().get().getLogDirectoryPath(), filesystem)) {
            DistBuildClientExecutor build = new DistBuildClientExecutor(jobState, service, distBuildLogStateTracker, 1000, /* millisBetweenStatusPoll */
            buckVersion);
            int exitCode = build.executeAndPrintFailuresToEventBus(executorService, filesystem, fileHashCache, params.getBuckEventBus());
            // TODO(shivanker): Add a flag to disable building, and only fetch from the cache.
            if (exitCode == 0) {
                exitCode = executeLocalBuild(params, graphs.actionGraph, executorService);
            }
            return exitCode;
        }
    }
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) FileHashCache(com.facebook.buck.util.cache.FileHashCache) TargetNode(com.facebook.buck.rules.TargetNode) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) DistBuildService(com.facebook.buck.distributed.DistBuildService) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckVersion(com.facebook.buck.distributed.thrift.BuckVersion) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) DefaultParserTargetNodeFactory(com.facebook.buck.parser.DefaultParserTargetNodeFactory) ParserTargetNodeFactory(com.facebook.buck.parser.ParserTargetNodeFactory) DistBuildClientExecutor(com.facebook.buck.distributed.DistBuildClientExecutor) DistBuildTargetGraphCodec(com.facebook.buck.distributed.DistBuildTargetGraphCodec) DistBuildLogStateTracker(com.facebook.buck.distributed.DistBuildLogStateTracker) DistBuildTypeCoercerFactory(com.facebook.buck.distributed.DistBuildTypeCoercerFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) Nullable(javax.annotation.Nullable)

Example 4 with TargetGraphAndBuildTargets

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

the class BuildCommand method createGraphs.

private ActionAndTargetGraphs createGraphs(CommandRunnerParams params, WeightedListeningExecutorService executorService) throws ActionGraphCreationException, IOException, InterruptedException {
    TargetGraphAndBuildTargets unversionedTargetGraph = createUnversionedTargetGraph(params, executorService);
    Optional<TargetGraphAndBuildTargets> versionedTargetGraph = Optional.empty();
    try {
        if (params.getBuckConfig().getBuildVersions()) {
            versionedTargetGraph = Optional.of(toVersionedTargetGraph(params, unversionedTargetGraph));
        }
    } catch (VersionException e) {
        throw new ActionGraphCreationException(MoreExceptions.getHumanReadableOrLocalizedMessage(e));
    }
    TargetGraphAndBuildTargets targetGraphForLocalBuild = getTargetGraphForLocalBuild(unversionedTargetGraph, versionedTargetGraph);
    checkSingleBuildTargetSpecifiedForOutBuildMode(targetGraphForLocalBuild);
    ActionGraphAndResolver actionGraph = createActionGraphAndResolver(params, targetGraphForLocalBuild);
    return new ActionAndTargetGraphs(unversionedTargetGraph, versionedTargetGraph, actionGraph);
}
Also used : ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) VersionException(com.facebook.buck.versions.VersionException)

Example 5 with TargetGraphAndBuildTargets

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

the class DistBuildSlaveExecutor method createTargetGraph.

private TargetGraph createTargetGraph() throws IOException, InterruptedException {
    if (targetGraph != null) {
        return targetGraph;
    }
    DistBuildTargetGraphCodec codec = createGraphCodec();
    TargetGraphAndBuildTargets targetGraphAndBuildTargets = Preconditions.checkNotNull(codec.createTargetGraph(args.getState().getRemoteState().getTargetGraph(), Functions.forMap(args.getState().getCells())));
    try {
        if (args.getRemoteRootCellConfig().getBuildVersions()) {
            targetGraph = args.getVersionedTargetGraphCache().toVersionedTargetGraph(args.getBuckEventBus(), args.getRemoteRootCellConfig(), targetGraphAndBuildTargets).getTargetGraph();
        } else {
            targetGraph = targetGraphAndBuildTargets.getTargetGraph();
        }
    } catch (VersionException e) {
        throw new RuntimeException(e);
    }
    return targetGraph;
}
Also used : TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) VersionException(com.facebook.buck.versions.VersionException)

Aggregations

TargetGraphAndBuildTargets (com.facebook.buck.rules.TargetGraphAndBuildTargets)17 Test (org.junit.Test)7 BuildTarget (com.facebook.buck.model.BuildTarget)5 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)4 ParserConfig (com.facebook.buck.parser.ParserConfig)4 TargetNode (com.facebook.buck.rules.TargetNode)4 BuildTargetException (com.facebook.buck.model.BuildTargetException)3 ActionGraphAndResolver (com.facebook.buck.rules.ActionGraphAndResolver)3 TargetGraph (com.facebook.buck.rules.TargetGraph)3 VersionException (com.facebook.buck.versions.VersionException)3 Build (com.facebook.buck.command.Build)2 BuildEvent (com.facebook.buck.rules.BuildEvent)2 CachingBuildEngine (com.facebook.buck.rules.CachingBuildEngine)2 CachingBuildEngineBuckConfig (com.facebook.buck.rules.CachingBuildEngineBuckConfig)2 LocalCachingBuildEngineDelegate (com.facebook.buck.rules.LocalCachingBuildEngineDelegate)2 RuleKey (com.facebook.buck.rules.RuleKey)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 RuleKeyCacheRecycler (com.facebook.buck.rules.keys.RuleKeyCacheRecycler)2 RuleKeyFactoryManager (com.facebook.buck.rules.keys.RuleKeyFactoryManager)2