diff options
author | slan <slan@chromium.org> | 2016-02-29 13:58:52 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-29 22:01:13 +0000 |
commit | 287cfad015cb201cb5af305baf35784320e0abdf (patch) | |
tree | 4bce73757fa761a635ce91b18412d430e0998dc1 /chromecast | |
parent | 7379fed63e678ad056fe00a5471c5caac559aeee (diff) | |
download | chromium_src-287cfad015cb201cb5af305baf35784320e0abdf.zip chromium_src-287cfad015cb201cb5af305baf35784320e0abdf.tar.gz chromium_src-287cfad015cb201cb5af305baf35784320e0abdf.tar.bz2 |
[Chromecast] Clean up //chromecast/base:cast_version.
Replaces (most of the) dummy values used to create version.h with
correct values taken from the environment.
BUG=None
Review URL: https://codereview.chromium.org/1727273004
Cr-Commit-Position: refs/heads/master@{#378283}
Diffstat (limited to 'chromecast')
-rw-r--r-- | chromecast/base/BUILD.gn | 63 | ||||
-rwxr-xr-x | chromecast/tools/build/generate_cast_version_params.py | 72 |
2 files changed, 125 insertions, 10 deletions
diff --git a/chromecast/base/BUILD.gn b/chromecast/base/BUILD.gn index 2723b854..fec43ac 100644 --- a/chromecast/base/BUILD.gn +++ b/chromecast/base/BUILD.gn @@ -10,6 +10,19 @@ if (is_android) { import("//build/config/android/rules.gni") } +declare_args() { + # Denotes the type of Cast product. This is #defined as CAST_PRODUCT_TYPE in + # version.h. This is an integer in the range [0-4]. + cast_product_type = 0 + + # If true, IS_CAST_DEBUG_BUILD() will evaluate to 1 in version.h. Otherwise, + # it will evaluate to 0. Overriding this when is_debug=false is useful for + # doing engineering builds. + cast_is_debug = is_debug +} + +assert(cast_product_type >= 0 && cast_product_type <= 4) + # GYP target: chromecast.gyp:cast_base source_set("base") { sources = [ @@ -119,22 +132,52 @@ source_set("cast_sys_info") { } } +# This target runs a script which generates a file containing key-value pairs. +# //build/util/version.py will parse this file, creating "version.h". This +# target shall only be depended upon by ":cast_version". +action("generate_cast_version_params") { + visibility = [ ":cast_version_action" ] + + script = "//chromecast/tools/build/generate_cast_version_params.py" + + params_file = "$root_gen_dir/cast_version_params" + outputs = [ + params_file, + ] + + args = [ + "-o", + rebase_path(params_file), + "-p", + "$cast_product_type", + ] + + if (cast_is_debug) { + args += [ "-d" ] + } + + if (chromecast_branding != "public") { + args += [ + "-r", + rebase_path("//chromecast/internal/build/cast_build_release"), + ] + } +} + process_version("cast_version") { template_file = "version.h.in" output = "$target_gen_dir/version.h" + + params_file = get_target_outputs(":generate_cast_version_params") + deps = [ + ":generate_cast_version_params", + ] + extra_args = [ "-e", "VERSION_FULL=\"%s.%s.%s.%s\"%(MAJOR,MINOR,BUILD,PATCH)", - - # TODO(slan): Populate the fields below with real values - "-e", - "CAST_BUILD_INCREMENTAL=20150608.181153", - "-e", - "CAST_BUILD_RELEASE=1.15", - "-e", - "CAST_IS_DEBUG_BUILD=1", - "-e", - "CAST_PRODUCT_TYPE=0", + "-f", + rebase_path(params_file[0]), ] } diff --git a/chromecast/tools/build/generate_cast_version_params.py b/chromecast/tools/build/generate_cast_version_params.py new file mode 100755 index 0000000..3302f56 --- /dev/null +++ b/chromecast/tools/build/generate_cast_version_params.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import optparse +import os +import re +import sys +import time + +from subprocess import call + +BUILD_NUM_KEY = 'CAST_BUILD_INCREMENTAL' +CAST_PRODUCT_KEY = 'CAST_PRODUCT_TYPE' +IS_DEBUG_KEY = 'CAST_IS_DEBUG_BUILD' +RELEASE_NUM_KEY = 'CAST_BUILD_RELEASE' + + +def main(argv): + parser = optparse.OptionParser('usage: %prog [options]') + parser.add_option('-o', '--output-file', action='store', dest='output_file', + help='Output path for the key-value file.') + parser.add_option('-d', '--debug', action='store_true', dest='is_debug', + default=False, help='Build is Cast debug mode.') + parser.add_option('-p', '--product-type', action='store', dest='product_type', + help='The Cast product type.') + parser.add_option('-r', '--release-path', action='store', dest='release_path', + default=None, + help='The path to a file with the Cast Release version.') + + (options, _) = parser.parse_args(argv) + if not options.output_file: + parser.error('Output file not provided.') + if not options.product_type: + parser.error('Product type not provided') + + params = {} + + # The Cast automated build system will set this parameter in the build + # environment. If it has not been set, this build is likely being done + # on a developer's machine. If so, set a dummy string based on the date. + dummy_incremental = time.strftime('%Y%m%d.%H%M%S') + params[BUILD_NUM_KEY] = os.environ.get(BUILD_NUM_KEY, dummy_incremental) + + # If this is an internal build, the Cast Release version will be stored in a + # file. Read and validate the value in this file. If the file is not present, + # this is likely a public build. If so, create a dummy release version. + version = 'eng.' + os.environ.get('USER', '') + if options.release_path: + with open(options.release_path, 'r') as f: + version = f.read().strip() + if not re.compile('^[0-9]*\.[0-9]*$').match(version): + sys.exit( + 'Cast version file is corrupt: {}'.format(options.release_path)) + + params[RELEASE_NUM_KEY] = version + + # If -d has been passed, this is a Cast debug build. + params[IS_DEBUG_KEY] = '1' if options.is_debug else '0' + + # Store the Cast Product Type. + params[CAST_PRODUCT_KEY] = str(options.product_type) + + # Write the key-value pairs to file. + with open(options.output_file, 'w') as f: + for key, val in params.items(): + f.write('{}={}\n'.format(key,val)) + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) |