Make builds reproducible (#7866)
Summary: Closes https://github.com/facebook/rocksdb/issues/7035 Changed how build_version.cc was generated: - Included the GIT tag/branch in the build_version file - Changed the "Build Date" to be: - If the GIT branch is "clean" (no changes), the date of the last git commit - If the branch is not clean, the current date - Added APIs to access the "build information", rather than accessing the strings directly. The build_version.cc file is now regenerated whenever the library objects are rebuilt. Verified that the built files remain the same size across builds on a "clean build" and the same information is reported by sst_dump --version Pull Request resolved: https://github.com/facebook/rocksdb/pull/7866 Reviewed By: pdillinger Differential Revision: D26086565 Pulled By: mrambacher fbshipit-source-id: 6fcbe47f6033989d5cf26a0ccb6dfdd9dd239d7fmain
parent
c696f27432
commit
0a9a05ae12
@ -1,5 +1,71 @@ |
||||
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
#include "build_version.h" |
||||
const char* rocksdb_build_git_sha = "rocksdb_build_git_sha:@@GIT_SHA@@"; |
||||
const char* rocksdb_build_git_date = "rocksdb_build_git_date:@@GIT_DATE_TIME@@"; |
||||
const char* rocksdb_build_compile_date = __DATE__; |
||||
|
||||
#include <memory> |
||||
|
||||
#include "rocksdb/version.h" |
||||
#include "util/string_util.h" |
||||
|
||||
// The build script may replace these values with real values based
|
||||
// on whether or not GIT is available and the platform settings
|
||||
static const std::string rocksdb_build_git_sha = "rocksdb_build_git_sha:@GIT_SHA@"; |
||||
static const std::string rocksdb_build_git_tag = "rocksdb_build_git_tag:@GIT_TAG@"; |
||||
#define HAS_GIT_CHANGES @GIT_MOD@ |
||||
#if HAS_GIT_CHANGES == 0 |
||||
// If HAS_GIT_CHANGES is 0, the GIT date is used.
|
||||
// Use the time the branch/tag was last modified
|
||||
static const std::string rocksdb_build_date = "rocksdb_build_date:@GIT_DATE@"; |
||||
#else |
||||
// If HAS_GIT_CHANGES is > 0, the branch/tag has modifications.
|
||||
// Use the time the build was created.
|
||||
static const std::string rocksdb_build_date = "rocksdb_build_date:@BUILD_DATE@"; |
||||
#endif |
||||
|
||||
namespace ROCKSDB_NAMESPACE { |
||||
static void AddProperty(std::unordered_map<std::string, std::string> *props, const std::string& name) { |
||||
size_t colon = name.find(":"); |
||||
if (colon != std::string::npos && colon > 0 && colon < name.length() - 1) { |
||||
// If we found a "@:", then this property was a build-time substitution that failed. Skip it
|
||||
size_t at = name.find("@", colon); |
||||
if (at != colon + 1) { |
||||
// Everything before the colon is the name, after is the value
|
||||
(*props)[name.substr(0, colon)] = name.substr(colon + 1); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static std::unordered_map<std::string, std::string>* LoadPropertiesSet() { |
||||
auto * properties = new std::unordered_map<std::string, std::string>(); |
||||
AddProperty(properties, rocksdb_build_git_sha); |
||||
AddProperty(properties, rocksdb_build_git_tag); |
||||
AddProperty(properties, rocksdb_build_date); |
||||
return properties; |
||||
} |
||||
|
||||
const std::unordered_map<std::string, std::string>& GetRocksBuildProperties() { |
||||
static std::unique_ptr<std::unordered_map<std::string, std::string>> props(LoadPropertiesSet()); |
||||
return *props; |
||||
} |
||||
|
||||
std::string GetRocksVersionAsString(bool with_patch) { |
||||
std::string version = ToString(ROCKSDB_MAJOR) + "." + ToString(ROCKSDB_MINOR); |
||||
if (with_patch) { |
||||
return version + "." + ToString(ROCKSDB_PATCH); |
||||
} else { |
||||
return version; |
||||
} |
||||
} |
||||
|
||||
std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) { |
||||
std::string info = program + " (RocksDB) " + GetRocksVersionAsString(true); |
||||
if (verbose) { |
||||
for (const auto& it : GetRocksBuildProperties()) { |
||||
info.append("\n "); |
||||
info.append(it.first); |
||||
info.append(": "); |
||||
info.append(it.second); |
||||
} |
||||
} |
||||
return info; |
||||
} |
||||
} // namespace ROCKSDB_NAMESPACE
|
||||
|
||||
|
@ -1,15 +0,0 @@ |
||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under both the GPLv2 (found in the
|
||||
// COPYING file in the root directory) and Apache 2.0 License
|
||||
// (found in the LICENSE.Apache file in the root directory).
|
||||
//
|
||||
#pragma once |
||||
#if !defined(IOS_CROSS_COMPILE) |
||||
// if we compile with Xcode, we don't run build_detect_version, so we don't
|
||||
// generate these variables
|
||||
// this variable tells us about the git revision
|
||||
extern const char* rocksdb_build_git_sha; |
||||
|
||||
// Date on which the code was compiled:
|
||||
extern const char* rocksdb_build_compile_date; |
||||
#endif |
Loading…
Reference in new issue