use of com.google.common.hash.HashCode in project buck by facebook.
the class TargetsCommand method hashNodeWithDependencies.
private void hashNodeWithDependencies(ImmutableMap<BuildTarget, HashCode> buildTargetHashes, Map<BuildTarget, HashCode> hashesWithTests, TargetNode<?, ?> node) {
HashCode nodeHashCode = getHashCodeOrThrow(buildTargetHashes, node.getBuildTarget());
Hasher hasher = Hashing.sha1().newHasher();
hasher.putBytes(nodeHashCode.asBytes());
Iterable<BuildTarget> dependentTargets = node.getDeps();
LOG.debug("Hashing target %s with dependent nodes %s", node, dependentTargets);
for (BuildTarget targetToHash : dependentTargets) {
HashCode dependencyHash = getHashCodeOrThrow(hashesWithTests, targetToHash);
hasher.putBytes(dependencyHash.asBytes());
}
if (isDetectTestChanges()) {
for (BuildTarget targetToHash : Preconditions.checkNotNull(TargetNodes.getTestTargetsForNode(node))) {
HashCode testNodeHashCode = getHashCodeOrThrow(buildTargetHashes, targetToHash);
hasher.putBytes(testNodeHashCode.asBytes());
}
}
hashesWithTests.put(node.getBuildTarget(), hasher.hash());
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class DownloadStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
BuckEventBus eventBus = context.getBuckEventBus();
try {
Path resolved = filesystem.resolve(output);
boolean success = downloader.fetch(eventBus, url, resolved);
if (!success) {
return StepExecutionResult.of(reportFailedDownload(eventBus));
}
HashCode readHash = Files.asByteSource(resolved.toFile()).hash(Hashing.sha1());
if (!sha1.equals(readHash)) {
eventBus.post(ConsoleEvent.severe("Unable to download %s (hashes do not match. Expected %s, saw %s)", url, sha1, readHash));
return StepExecutionResult.of(-1);
}
} catch (IOException e) {
return StepExecutionResult.of(reportFailedDownload(eventBus));
} catch (HumanReadableException e) {
eventBus.post(ConsoleEvent.severe(e.getHumanReadableErrorMessage(), e));
return StepExecutionResult.of(-1);
}
return StepExecutionResult.SUCCESS;
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class RemoteFileDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
HashCode sha1;
try {
sha1 = HashCode.fromString(args.sha1);
} catch (IllegalArgumentException e) {
throw new HumanReadableException(e, "%s when parsing sha1 of %s", e.getMessage(), params.getBuildTarget().getUnflavoredBuildTarget().getFullyQualifiedName());
}
String out = args.out.orElse(params.getBuildTarget().getShortNameAndFlavorPostfix());
RemoteFile.Type type = args.type.orElse(RemoteFile.Type.DATA);
if (type == RemoteFile.Type.EXECUTABLE) {
return new RemoteFileBinary(params, downloader, args.url, sha1, out, type);
}
return new RemoteFile(params, downloader, args.url, sha1, out, type);
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class MaterializerProjectFileHashCache method symlinkIntegrityCheck.
private void symlinkIntegrityCheck(BuildJobStateFileHashEntry fileHashEntry) throws IOException {
Path symlinkAbsPath = projectFilesystem.resolve(fileHashEntry.getPath().getPath());
HashCode expectedHash = HashCode.fromString(fileHashEntry.getHashCode());
Path symlinkRelPath = projectFilesystem.getPathRelativeToProjectRoot(symlinkAbsPath).get();
HashCode actualHash = delegate.get(symlinkRelPath);
if (!expectedHash.equals(actualHash)) {
throw new RuntimeException(String.format("Symlink [%s] had hashcode [%s] during scheduling, but [%s] during build.", symlinkAbsPath, expectedHash, actualHash));
}
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class RecordingProjectFileHashCache method get.
@Override
public HashCode get(ArchiveMemberPath relPath) throws IOException {
checkIsRelative(relPath.getArchivePath());
HashCode hashCode = delegate.get(relPath);
synchronized (this) {
if (!remoteFileHashes.containsAndAddPath(relPath)) {
record(relPath.getArchivePath(), Optional.of(relPath.getMemberPath().toString()), hashCode, new LinkedList<>());
}
}
return hashCode;
}
Aggregations