use of com.facebook.buck.rules.TargetNodeFactory 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.TargetNodeFactory in project buck by facebook.
the class GenruleDescriptionTest method testImplicitDepsAreAddedCorrectly.
@Test
public void testImplicitDepsAreAddedCorrectly() throws Exception {
Description<GenruleDescription.Arg> genruleDescription = new GenruleDescription();
Map<String, Object> instance = ImmutableMap.of("srcs", ImmutableList.of(":baz", "//biz:baz"), "out", "AndroidManifest.xml", "cmd", "$(exe //bin:executable) $(location :arg)");
ProjectFilesystem projectFilesystem = new AllExistingProjectFilesystem();
ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance()));
ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder();
ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder();
GenruleDescription.Arg constructorArg = genruleDescription.createUnpopulatedConstructorArg();
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
marshaller.populate(createCellRoots(projectFilesystem), projectFilesystem, buildTarget, constructorArg, declaredDeps, visibilityPatterns, instance);
TargetNode<GenruleDescription.Arg, ?> targetNode = new TargetNodeFactory(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())).create(Hashing.sha1().hashString(buildTarget.getFullyQualifiedName(), UTF_8), genruleDescription, constructorArg, projectFilesystem, buildTarget, declaredDeps.build(), visibilityPatterns.build(), createCellRoots(projectFilesystem));
assertEquals("SourcePaths and targets from cmd string should be extracted as extra deps.", ImmutableSet.of("//foo:baz", "//biz:baz", "//bin:executable", "//foo:arg"), targetNode.getExtraDeps().stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
}
use of com.facebook.buck.rules.TargetNodeFactory in project buck by facebook.
the class DistBuildStateTest method createDefaultCodec.
public static DistBuildTargetGraphCodec createDefaultCodec(final Cell cell, final Optional<Parser> parser) {
// NOPMD confused by lambda
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
Function<? super TargetNode<?, ?>, ? extends Map<String, Object>> nodeToRawNode;
if (parser.isPresent()) {
nodeToRawNode = (Function<TargetNode<?, ?>, Map<String, Object>>) input -> {
try {
return parser.get().getRawTargetNode(eventBus, cell.getCell(input.getBuildTarget()), false, MoreExecutors.listeningDecorator(MoreExecutors.newDirectExecutorService()), input);
} catch (BuildFileParseException e) {
throw new RuntimeException(e);
}
};
} else {
nodeToRawNode = Functions.constant(ImmutableMap.<String, Object>of());
}
DistBuildTypeCoercerFactory typeCoercerFactory = new DistBuildTypeCoercerFactory(objectMapper);
ParserTargetNodeFactory<TargetNode<?, ?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory.createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory));
return new DistBuildTargetGraphCodec(objectMapper, parserTargetNodeFactory, nodeToRawNode, ImmutableSet.of());
}
use of com.facebook.buck.rules.TargetNodeFactory in project buck by facebook.
the class DistBuildSlaveExecutor method createGraphCodec.
private DistBuildTargetGraphCodec createGraphCodec() {
DistBuildTypeCoercerFactory typeCoercerFactory = new DistBuildTypeCoercerFactory(args.getObjectMapper());
ParserTargetNodeFactory<TargetNode<?, ?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory.createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory));
DistBuildTargetGraphCodec targetGraphCodec = new DistBuildTargetGraphCodec(args.getObjectMapper(), parserTargetNodeFactory, new Function<TargetNode<?, ?>, Map<String, Object>>() {
@Nullable
@Override
public Map<String, Object> apply(TargetNode<?, ?> input) {
try {
return args.getParser().getRawTargetNode(args.getBuckEventBus(), args.getRootCell().getCell(input.getBuildTarget()), /* enableProfiling */
false, args.getExecutorService(), input);
} catch (BuildFileParseException e) {
throw new RuntimeException(e);
}
}
}, new HashSet<>(args.getState().getRemoteState().getTopLevelTargets()));
return targetGraphCodec;
}
use of com.facebook.buck.rules.TargetNodeFactory in project buck by facebook.
the class OwnersReportTest method createTargetNode.
private TargetNode<?, ?> createTargetNode(BuildTarget buildTarget, ImmutableSet<Path> inputs) {
Description<FakeRuleDescription.FakeArg> description = new FakeRuleDescription();
FakeRuleDescription.FakeArg arg = description.createUnpopulatedConstructorArg();
arg.inputs = inputs;
try {
return new TargetNodeFactory(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())).create(Hashing.sha1().hashString(buildTarget.getFullyQualifiedName(), UTF_8), description, arg, filesystem, buildTarget, ImmutableSet.of(), ImmutableSet.of(), createCellRoots(filesystem));
} catch (NoSuchBuildTargetException e) {
throw new RuntimeException(e);
}
}
Aggregations