diff options
Diffstat (limited to 'src/main')
4 files changed, 51 insertions, 11 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index ffcbf00447..c19f300de1 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -140,6 +140,10 @@ struct GlobalVariables { // Absolute path of the blaze binary string binary_path; + + // MD5 hash of the Blaze binary (includes deploy.jar, extracted binaries, and + // anything else that ends up under the install_base). + string install_md5; }; static GlobalVariables *globals; @@ -198,8 +202,7 @@ class GetInstallKeyFileProcessor : public devtools_ijar::ZipExtractorProcessor { // 'install_base_key' contained as a ZIP entry in the Blaze binary); as a side // effect, it also populates the extracted_binaries global variable. static string GetInstallBase(const string &root, const string &self_path) { - string install_base_key; - GetInstallKeyFileProcessor processor(&install_base_key); + GetInstallKeyFileProcessor processor(&globals->install_md5); std::unique_ptr<devtools_ijar::ZipExtractor> extractor( devtools_ijar::ZipExtractor::Create(self_path.c_str(), &processor)); if (extractor.get() == NULL) { @@ -212,11 +215,11 @@ static string GetInstallBase(const string &root, const string &self_path) { "\nFailed to extract install_base_key: %s", extractor->GetError()); } - if (install_base_key.empty()) { + if (globals->install_md5.empty()) { die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "\nFailed to find install_base_key's in zip file"); } - return root + "/" + install_base_key; + return root + "/" + globals->install_md5; } // Escapes colons by replacing them with '_C' and underscores by replacing them @@ -312,6 +315,7 @@ static vector<string> GetArgumentArray() { } result.push_back("--install_base=" + blaze::ConvertPath(globals->options.install_base)); + result.push_back("--install_md5=" + globals->install_md5); result.push_back("--output_base=" + blaze::ConvertPath(globals->options.output_base)); result.push_back("--workspace_directory=" + @@ -1348,7 +1352,8 @@ static void ComputeBaseDirectories(const string &self_path) { globals->options.install_base = GetInstallBase(install_user_root, self_path); } else { - // We call GetInstallBase anyway to populate extracted_binaries. + // We call GetInstallBase anyway to populate extracted_binaries and + // install_md5. GetInstallBase("", self_path); } 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 |