aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/bazel
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-07-23 02:22:20 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-23 02:23:16 -0700
commit49212c43c1aef61319d69760ca79151636988b68 (patch)
tree4bd061bad83b44cc955a6a858a4e1e5f86e1a0b7 /src/main/java/com/google/devtools/build/lib/bazel
parent6b5df97308d5ce60e801f9872d6b354db5164fe6 (diff)
resolved file: include the hash of the output tree
When reporting about the repository rules that were called, also report a hash of the tree the rule generated. This allows, at least after the fact, to verify that a repository rule actually produced the correct code. Note that equality of the output hash is not a guarantee for reproducible builds, as certain properties of the output tree, in particular owner, are ignored. Still it is a good check to detect wrong use of a repository rule. Change-Id: Ic56509f8e0d0b4be9ce3335ade280f983fe77e6d PiperOrigin-RevId: 205631855
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/bazel')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java27
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java4
2 files changed, 19 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
index 2087f3cd00..47801f3cfb 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
@@ -21,6 +21,8 @@ import com.google.devtools.build.lib.packages.Info;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Runtime;
+import com.google.devtools.build.lib.vfs.Path;
+import java.io.IOException;
import java.util.Map;
/**
@@ -31,6 +33,7 @@ public class RepositoryResolvedEvent implements ProgressLike {
public static final String ORIGINAL_ATTRIBUTES = "original_attributes";
public static final String RULE_CLASS = "rule_class";
public static final String ATTRIBUTES = "attributes";
+ public static final String OUTPUT_TREE_HASH = "output_tree_hash";
public static final String REPOSITORIES = "repositories";
/**
@@ -47,7 +50,7 @@ public class RepositoryResolvedEvent implements ProgressLike {
*/
private final Object resolvedInformation;
- public RepositoryResolvedEvent(Rule rule, Info attrs, Object result) {
+ public RepositoryResolvedEvent(Rule rule, Info attrs, Path outputDirectory, Object result) {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
String originalClass =
@@ -69,25 +72,27 @@ public class RepositoryResolvedEvent implements ProgressLike {
ImmutableMap<String, Object> origAttr = origAttrBuilder.build();
builder.put(ORIGINAL_ATTRIBUTES, origAttr);
+ ImmutableMap.Builder<String, Object> repositoryBuilder =
+ ImmutableMap.<String, Object>builder().put(RULE_CLASS, originalClass);
+
+ try {
+ repositoryBuilder.put(OUTPUT_TREE_HASH, outputDirectory.getDirectoryDigest());
+ } catch (IOException e) {
+ // Digest not available, but we still have to report that a repository rule
+ // was invoked. So we can do nothing, but ignore the event.
+ }
+
if (result == Runtime.NONE) {
// Rule claims to be already reproducible, so wants to be called as is.
builder.put(
REPOSITORIES,
- ImmutableList.<Object>of(
- ImmutableMap.<String, Object>builder()
- .put(RULE_CLASS, originalClass)
- .put(ATTRIBUTES, origAttr)
- .build()));
+ ImmutableList.<Object>of(repositoryBuilder.put(ATTRIBUTES, origAttr).build()));
} else if (result instanceof Map) {
// Rule claims that the returned (probably changed) arguments are a reproducible
// version of itself.
builder.put(
REPOSITORIES,
- ImmutableList.<Object>of(
- ImmutableMap.<String, Object>builder()
- .put(RULE_CLASS, originalClass)
- .put(ATTRIBUTES, result)
- .build()));
+ ImmutableList.<Object>of(repositoryBuilder.put(ATTRIBUTES, result).build()));
} else {
// TODO(aehlig): handle strings specially to allow encodings of the former
// values to be accepted as well.
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java
index 4c3611ba8d..a4131bdbc2 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java
@@ -106,7 +106,9 @@ public class SkylarkRepositoryFunction extends RepositoryFunction {
.handle(Event.info("Repository rule '" + rule.getName() + "' returned: " + retValue));
}
env.getListener()
- .post(new RepositoryResolvedEvent(rule, skylarkRepositoryContext.getAttr(), retValue));
+ .post(
+ new RepositoryResolvedEvent(
+ rule, skylarkRepositoryContext.getAttr(), outputDirectory, retValue));
} catch (EvalException e) {
if (e.getCause() instanceof RepositoryMissingDependencyException) {
// A dependency is missing, cleanup and returns null