Search in sources :

Example 6 with HashCode

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());
}
Also used : Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 7 with HashCode

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;
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) HumanReadableException(com.facebook.buck.util.HumanReadableException) IOException(java.io.IOException)

Example 8 with HashCode

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);
}
Also used : HashCode(com.google.common.hash.HashCode) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 9 with HashCode

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));
    }
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode)

Example 10 with HashCode

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;
}
Also used : HashCode(com.google.common.hash.HashCode)

Aggregations

HashCode (com.google.common.hash.HashCode)120 Path (java.nio.file.Path)40 Test (org.junit.Test)39 BuildTarget (com.facebook.buck.model.BuildTarget)19 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)13 IOException (java.io.IOException)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 PathSourcePath (com.facebook.buck.rules.PathSourcePath)11 FileHashCache (com.facebook.buck.util.cache.FileHashCache)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)10 Hasher (com.google.common.hash.Hasher)9 Map (java.util.Map)9 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)7 SourcePath (com.facebook.buck.rules.SourcePath)7 File (java.io.File)7 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5