use of com.google.common.hash.Hasher in project buck by facebook.
the class DexProducedFromJavaLibrary method computeAbiKey.
@VisibleForTesting
static Sha1HashCode computeAbiKey(ImmutableSortedMap<String, HashCode> classNames) {
Hasher hasher = Hashing.sha1().newHasher();
for (Map.Entry<String, HashCode> entry : classNames.entrySet()) {
hasher.putUnencodedChars(entry.getKey());
hasher.putByte((byte) 0);
hasher.putUnencodedChars(entry.getValue().toString());
hasher.putByte((byte) 0);
}
return Sha1HashCode.fromHashCode(hasher.hash());
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class DefaultParserTargetGroupFactory method createTargetNode.
@Override
public TargetGroup createTargetNode(Cell cell, Path buildFile, BuildTarget target, Map<String, Object> rawNode, Function<PerfEventId, SimplePerfEvent.Scope> perfEventScope) {
Preconditions.checkArgument(!target.isFlavored());
UnflavoredBuildTarget unflavoredBuildTarget = target.withoutCell().getUnflavoredBuildTarget();
UnflavoredBuildTarget unflavoredBuildTargetFromRawData = RawNodeParsePipeline.parseBuildTargetFromRawRule(cell.getRoot(), rawNode, buildFile);
if (!unflavoredBuildTarget.equals(unflavoredBuildTargetFromRawData)) {
throw new IllegalStateException(String.format("Inconsistent internal state, target from data: %s, expected: %s, raw data: %s", unflavoredBuildTargetFromRawData, unflavoredBuildTarget, Joiner.on(',').withKeyValueSeparator("->").join(rawNode)));
}
BuildRuleType buildRuleType = parseBuildRuleTypeFromRawRule(cell, rawNode);
// Because of the way that the parser works, we know this can never return null.
Description<?> description = cell.getDescription(buildRuleType);
Cell targetCell = cell.getCell(target);
TargetGroupDescription.Arg constructorArg = (TargetGroupDescription.Arg) description.createUnpopulatedConstructorArg();
try {
ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder();
ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder();
try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("MarshalledConstructorArg"))) {
marshaller.populate(targetCell.getCellPathResolver(), targetCell.getFilesystem(), target, constructorArg, declaredDeps, visibilityPatterns, rawNode);
}
try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("CreatedTargetNode"))) {
Hasher hasher = Hashing.sha1().newHasher();
hasher.putString(BuckVersion.getVersion(), UTF_8);
JsonObjectHashing.hashJsonObject(hasher, rawNode);
TargetGroup node = new TargetGroup(constructorArg.targets, constructorArg.restrictOutboundVisibility, target);
return node;
}
} catch (ParamInfoException e) {
throw new HumanReadableException("%s: %s", target, e.getMessage());
}
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class ActionGraphCache method getTargetGraphHash.
private static HashCode getTargetGraphHash(TargetGraph targetGraph) {
Hasher hasher = Hashing.sha1().newHasher();
ImmutableSet<TargetNode<?, ?>> nodes = targetGraph.getNodes();
for (TargetNode<?, ?> targetNode : ImmutableSortedSet.copyOf(nodes)) {
hasher.putBytes(targetNode.getRawInputsHashCode().asBytes());
}
return hasher.hash();
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class Sha1HashCodeTest method testUpdate.
@Test
public void testUpdate() {
Hasher hasher1 = Hashing.sha1().newHasher();
Sha1HashCode sha1 = Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c");
Hasher hasher2 = sha1.update(hasher1);
assertSame(hasher1, hasher2);
HashCode expectedHash = Hashing.sha1().newHasher().putBytes(new byte[] { (byte) 0xa0, (byte) 0x02, (byte) 0xb3, (byte) 0x9a, (byte) 0xf2, (byte) 0x04, (byte) 0xcd, (byte) 0xfa, (byte) 0xa5, (byte) 0xfd, (byte) 0xb6, (byte) 0x78, (byte) 0x16, (byte) 0xb1, (byte) 0x38, (byte) 0x67, (byte) 0xc3, (byte) 0x2a, (byte) 0xc5, (byte) 0x2c }).hash();
HashCode observedHash = hasher1.hash();
assertEquals(expectedHash, observedHash);
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class HashInputJarsToDexStep method execute.
@Override
public StepExecutionResult execute(final ExecutionContext context) {
ImmutableList.Builder<Path> allInputs = ImmutableList.builder();
allInputs.addAll(primaryInputsToDex.get());
if (secondaryOutputToInputs.isPresent()) {
allInputs.addAll(secondaryOutputToInputs.get().get().values());
}
final Map<String, HashCode> classNamesToHashes = classNamesToHashesSupplier.get();
for (Path path : allInputs.build()) {
try {
final Hasher hasher = Hashing.sha1().newHasher();
new DefaultClasspathTraverser().traverse(new ClasspathTraversal(Collections.singleton(path), filesystem) {
@Override
public void visit(FileLike fileLike) throws IOException {
String className = fileLike.getRelativePath().replaceAll("\\.class$", "");
if (classNamesToHashes.containsKey(className)) {
HashCode classHash = Preconditions.checkNotNull(classNamesToHashes.get(className));
hasher.putBytes(classHash.asBytes());
}
}
});
dexInputsToHashes.put(path, Sha1HashCode.fromHashCode(hasher.hash()));
} catch (IOException e) {
context.logError(e, "Error hashing smart dex input: %s", path);
return StepExecutionResult.ERROR;
}
}
stepFinished = true;
return StepExecutionResult.SUCCESS;
}
Aggregations