avoid assuming build number is a 32-bit integer

The install logging currently assumes that the build number is a 32-bit
integer and prints an error when that doesn't hold true. However, that's
only a convention used by Google builds.

From build/core/version_defaults.mk:

    ifeq "" "$(BUILD_NUMBER)"
      # BUILD_NUMBER should be set to the source control value that
      # represents the current state of the source code.  E.g., a
      # perforce changelist number or a git hash.  Can be an arbitrary string
      # (to allow for source control that uses something other than numbers),
      # but must be a single word and a valid file name.
      #
      # If no BUILD_NUMBER is set, create a useful "I am an engineering build
      # from this date/time" value.  Make it start with a non-digit so that
      # anyone trying to parse it as an integer will probably get "0".
      BUILD_NUMBER := eng.$(shell echo $${USER:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)
    endif

Change-Id: I8e7cec0618783f69545ba76d0dce2bbc1681784c
This commit is contained in:
Daniel Micay
2017-06-23 08:33:24 -04:00
parent 5efe2bca22
commit a29d8d69d2

View File

@@ -66,18 +66,14 @@ static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
static std::condition_variable finish_log_temperature;
// This function parses and returns the build.version.incremental
static int parse_build_number(const std::string& str) {
static std::string parse_build_number(const std::string& str) {
size_t pos = str.find('=');
if (pos != std::string::npos) {
std::string num_string = android::base::Trim(str.substr(pos+1));
int build_number;
if (android::base::ParseInt(num_string.c_str(), &build_number, 0)) {
return build_number;
}
return android::base::Trim(str.substr(pos+1));
}
LOG(ERROR) << "Failed to parse build number in " << str;
return -1;
return "";
}
bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata) {
@@ -114,14 +110,14 @@ static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::stri
for (const std::string& line : lines) {
std::string str = android::base::Trim(line);
if (android::base::StartsWith(str, "pre-build-incremental")) {
int source_build = parse_build_number(str);
if (source_build != -1) {
log_buffer->push_back(android::base::StringPrintf("source_build: %d", source_build));
std::string source_build = parse_build_number(str);
if (!source_build.empty()) {
log_buffer->push_back("source_build: " + source_build);
}
} else if (android::base::StartsWith(str, "post-build-incremental")) {
int target_build = parse_build_number(str);
if (target_build != -1) {
log_buffer->push_back(android::base::StringPrintf("target_build: %d", target_build));
std::string target_build = parse_build_number(str);
if (!target_build.empty()) {
log_buffer->push_back("target_build: " + target_build);
}
}
}