use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class Environment method computeTransitiveContentHashCode.
private static String computeTransitiveContentHashCode(@Nullable String baseHashCode, Map<String, Extension> importedExtensions) {
// Calculate a new hash from the hash of the loaded Extension-s.
Fingerprint fingerprint = new Fingerprint();
if (baseHashCode != null) {
fingerprint.addString(Preconditions.checkNotNull(baseHashCode));
}
TreeSet<String> importStrings = new TreeSet<>(importedExtensions.keySet());
for (String importString : importStrings) {
fingerprint.addString(importedExtensions.get(importString).getTransitiveContentHashCode());
}
return fingerprint.hexDigestAndReset();
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class CrosstoolConfigurationLoader method getCrosstoolProtofromBuildFile.
private static CrosstoolProto getCrosstoolProtofromBuildFile(ConfigurationEnvironment env, Label crosstoolTop) throws InterruptedException {
Target target;
try {
target = env.getTarget(crosstoolTop);
} catch (NoSuchThingException e) {
// Should have beeen evaluated by RedirectChaser
throw new IllegalStateException(e);
}
if (!(target instanceof Rule)) {
return null;
}
Rule rule = (Rule) target;
if (!(rule.getRuleClass().equals("cc_toolchain_suite")) || !rule.isAttributeValueExplicitlySpecified("proto")) {
return null;
}
final String contents = NonconfigurableAttributeMapper.of(rule).get("proto", Type.STRING);
byte[] md5 = new Fingerprint().addBytes(contents.getBytes(UTF_8)).digestAndReset();
return new CrosstoolProto(md5, "cc_toolchain_suite rule " + crosstoolTop.toString()) {
@Override
public String getContents() throws IOException {
return contents;
}
};
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class CppCompileAction method computeKey.
@Override
public String computeKey() {
Fingerprint f = new Fingerprint();
f.addUUID(actionClassId);
f.addStringMap(getEnvironment());
f.addStringMap(executionInfo);
// For the argv part of the cache key, ignore all compiler flags that explicitly denote module
// file (.pcm) inputs. Depending on input discovery, some of the unused ones are removed from
// the command line. However, these actually don't have an influence on the compile itself and
// so ignoring them for the cache key calculation does not affect correctness. The compile
// itself is fully determined by the input source files and module maps.
// A better long-term solution would be to make the compiler to find them automatically and
// never hand in the .pcm files explicitly on the command line in the first place.
f.addStrings(cppCompileCommandLine.getArgv(getInternalOutputFile(), null));
/*
* getArgv() above captures all changes which affect the compilation
* command and hence the contents of the object file. But we need to
* also make sure that we reexecute the action if any of the fields
* that affect whether validateIncludes() will report an error or warning
* have changed, otherwise we might miss some errors.
*/
f.addPaths(context.getDeclaredIncludeDirs());
f.addPaths(context.getDeclaredIncludeWarnDirs());
for (Artifact declaredIncludeSrc : context.getDeclaredIncludeSrcs()) {
f.addPath(declaredIncludeSrc.getExecPath());
}
// mark the boundary between input types
f.addInt(0);
for (Artifact input : getMandatoryInputs()) {
f.addPath(input.getExecPath());
}
f.addInt(0);
for (Artifact input : prunableInputs) {
f.addPath(input.getExecPath());
}
return f.hexDigestAndReset();
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class DigestUtils method fromEnv.
/**
* @param env A collection of (String, String) pairs.
* @return an order-independent digest of the given set of pairs.
*/
public static Md5Digest fromEnv(Map<String, String> env) {
byte[] result = new byte[Md5Digest.MD5_SIZE];
Fingerprint fp = new Fingerprint();
for (Map.Entry<String, String> entry : env.entrySet()) {
fp.addString(entry.getKey());
fp.addString(entry.getValue());
xorWith(result, fp.digestAndReset());
}
return new Md5Digest(result);
}
use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.
the class DigestUtils method fromMetadata.
/**
* @param mdMap A collection of (execPath, Metadata) pairs. Values may be null.
* @return an <b>order-independent</b> digest from the given "set" of (path, metadata) pairs.
*/
public static Md5Digest fromMetadata(Map<String, Metadata> mdMap) {
byte[] result = new byte[Md5Digest.MD5_SIZE];
// Profiling showed that MD5 engine instantiation was a hotspot, so create one instance for
// this computation to amortize its cost.
Fingerprint fp = new Fingerprint();
for (Map.Entry<String, Metadata> entry : mdMap.entrySet()) {
xorWith(result, getDigest(fp, entry.getKey(), entry.getValue()));
}
return new Md5Digest(result);
}
Aggregations