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;
}
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;
}
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;
}
}
}
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);
}
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;
}
Aggregations