use of com.facebook.buck.distributed.thrift.BuckVersion 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.distributed.thrift.BuckVersion in project buck by facebook.
the class BuckVersionUtil method createFromLocalBinary.
public static BuckVersion createFromLocalBinary(Path localBuckBinary) throws IOException {
byte[] data = Files.readAllBytes(localBuckBinary);
String hash = Hashing.sha1().newHasher().putBytes(data).hash().toString();
FileInfo buckBinary = new FileInfo();
buckBinary.setContent(data);
buckBinary.setContentHash(hash);
BuckVersion buckVersion = new BuckVersion();
buckVersion.setType(BuckVersionType.DEVELOPMENT);
buckVersion.setDevelopmentVersion(buckBinary);
return buckVersion;
}
use of com.facebook.buck.distributed.thrift.BuckVersion in project buck by facebook.
the class BuckVersionUtilTest method testCreatingDev.
@Test
public void testCreatingDev() throws IOException {
Path binFolder = temporaryFolder.newFolder("source");
Path binary = binFolder.resolve("buck.binary");
byte[] binaryData = "Sample binary data".getBytes();
Files.write(binary, binaryData);
BuckVersion buckVersion = BuckVersionUtil.createFromLocalBinary(binary);
Assert.assertEquals(BuckVersionType.DEVELOPMENT, buckVersion.getType());
Assert.assertArrayEquals(binaryData, buckVersion.getDevelopmentVersion().getContent());
Assert.assertEquals("8ffb80f59032d8e7647a5e4d0196cc7360a8eb2b", buckVersion.getDevelopmentVersion().getContentHash());
}
use of com.facebook.buck.distributed.thrift.BuckVersion in project buck by facebook.
the class BuckVersionUtilTest method testCreatingFromGit.
@Test
public void testCreatingFromGit() {
String gitHash = "My lovely random hash";
BuckVersion buckVersion = BuckVersionUtil.createFromGitHash(gitHash);
Assert.assertEquals(BuckVersionType.GIT, buckVersion.getType());
Assert.assertEquals(gitHash, buckVersion.getGitHash());
}
use of com.facebook.buck.distributed.thrift.BuckVersion in project buck by facebook.
the class BuckVersionUtil method createFromGitHash.
public static BuckVersion createFromGitHash(String gitHash) {
BuckVersion buckVersion = new BuckVersion();
buckVersion.setType(BuckVersionType.GIT);
buckVersion.setGitHash(gitHash);
return buckVersion;
}
Aggregations