aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Eric Fellheimer <felly@google.com>2015-08-12 15:02:24 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-08-12 15:24:46 +0000
commit4c5eb0ff6540f7e90fbad3a04053699840163477 (patch)
tree4998c967994d309890347a90caeff055a37f7845 /src/main/java/com/google/devtools/build/lib
parentf4b07dbdb4bf5d4ae2b743d50f8e43ff49770987 (diff)
Allow runtime introspection of a content hash of the Blaze binary and all embedded binaries.
-- MOS_MIGRATED_REVID=100476182
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java34
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java10
3 files changed, 41 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java b/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java
index f08cf7d4dd..1140754ed5 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java
@@ -16,6 +16,8 @@ package com.google.devtools.build.lib.analysis;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.hash.HashCode;
+import com.google.common.hash.Hashing;
import com.google.devtools.build.lib.Constants;
import com.google.devtools.build.lib.actions.Root;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -57,20 +59,23 @@ public final class BlazeDirectories {
@VisibleForTesting
static final String DEFAULT_EXEC_ROOT = "default-exec-root";
- private final Path installBase; // Where Blaze gets unpacked
- private final Path workspace; // Workspace root and server CWD
- private final Path outputBase; // The root of the temp and output trees
- private final Path execRoot; // the root of all build actions
+ private final Path installBase; // Where Blaze gets unpacked
+ private final HashCode installMD5; // The content hash of everything in installBase
+ private final Path workspace; // Workspace root and server CWD
+ private final Path outputBase; // The root of the temp and output trees
+ private final Path execRoot; // the root of all build actions
// These two are kept to avoid creating new objects every time they are accessed. This showed up
// in a profiler.
private final Path outputPath;
private final Path localOutputPath;
- public BlazeDirectories(Path installBase, Path outputBase, @Nullable Path workspace) {
+ public BlazeDirectories(Path installBase, Path outputBase, @Nullable Path workspace,
+ @Nullable String installMD5) {
this.installBase = installBase;
this.workspace = workspace;
this.outputBase = outputBase;
+ this.installMD5 = installMD5 == null ? null : checkMD5(HashCode.fromString(installMD5));
boolean useDefaultExecRootName = this.workspace == null || this.workspace.isRootDirectory();
if (useDefaultExecRootName) {
// TODO(bazel-team): if workspace is null execRoot should be null, but at the moment there is
@@ -86,6 +91,17 @@ public final class BlazeDirectories {
this.localOutputPath = outputBase.getRelative(BlazeDirectories.RELATIVE_OUTPUT_PATH);
}
+ private static HashCode checkMD5(HashCode hash) {
+ Preconditions.checkArgument(hash.bits() == Hashing.md5().bits(),
+ "Hash '%s' has %s bits", hash, hash.bits());
+ return hash;
+ }
+
+ @VisibleForTesting
+ public BlazeDirectories(Path installBase, Path outputBase, @Nullable Path workspace) {
+ this(installBase, outputBase, workspace, null);
+ }
+
/**
* Returns the Filesystem that all of our directories belong to. Handy for
* resolving absolute paths.
@@ -183,4 +199,12 @@ public final class BlazeDirectories {
public Root getBuildDataDirectory() {
return Root.asDerivedRoot(getExecRoot(), getOutputPath());
}
+
+ /**
+ * Returns the MD5 content hash of the blaze binary (includes deploy JAR, embedded binaries, and
+ * anything else that ends up in the install_base).
+ */
+ public HashCode getInstallMD5() {
+ return installMD5;
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
index 8225fce736..3a4f3e1d90 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
@@ -1469,7 +1469,8 @@ public final class BlazeRuntime {
}
BlazeDirectories directories =
- new BlazeDirectories(installBasePath, outputBasePath, workspaceDirectoryPath);
+ new BlazeDirectories(installBasePath, outputBasePath, workspaceDirectoryPath,
+ startupOptions.installMD5);
Clock clock = BlazeClock.instance();
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
index 120ab946ed..59119ddcf0 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
@@ -82,6 +82,16 @@ public class BlazeServerStartupOptions extends OptionsBase {
help = "This launcher option is intended for use only by tests.")
public PathFragment installBase;
+ /*
+ * The installation MD5 - a content hash of the blaze binary (includes the Blaze deploy JAR and
+ * any other embedded binaries - anything that ends up in the install_base).
+ */
+ @Option(name = "install_md5",
+ defaultValue = "", // NOTE: purely decorative! See class docstring.
+ category = "hidden",
+ help = "This launcher option is intended for use only by tests.")
+ public String installMD5;
+
/* Note: The help string in this option applies to the client code; not
* the server code. The server code will only accept a non-empty path; it's
* the responsibility of the client to compute a proper default if