diff options
author | mmoss@chromium.org <mmoss@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-28 19:41:23 +0000 |
---|---|---|
committer | mmoss@chromium.org <mmoss@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-28 19:41:23 +0000 |
commit | b730318b9494f04b8519def4bbf576f2da092eee (patch) | |
tree | e5cfd98cea7717a3456bfa93fd4e2445292aa66e | |
parent | 3a69f0af0b98c8373fd6b5997ce37efd31baa8dd (diff) | |
download | chromium_src-b730318b9494f04b8519def4bbf576f2da092eee.zip chromium_src-b730318b9494f04b8519def4bbf576f2da092eee.tar.gz chromium_src-b730318b9494f04b8519def4bbf576f2da092eee.tar.bz2 |
Add default version information and ability to output to stdout.
This is useful for getting general build version information, such as needed
for Linux packaging.
Review URL: http://codereview.chromium.org/115842
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17096 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | chrome/tools/build/version.py | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/chrome/tools/build/version.py b/chrome/tools/build/version.py index f582395..03abeb7 100755 --- a/chrome/tools/build/version.py +++ b/chrome/tools/build/version.py @@ -1,4 +1,4 @@ -#/usr/bin/env python +#!/usr/bin/env python # Copyright (c) 2009 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. @@ -153,17 +153,21 @@ def main(argv=None): if argv is None: argv = sys.argv - short_options = 'f:h' + short_options = 'f:i:o:h' long_options = ['file=', 'help'] helpstr = """\ -Usage: version.py [-h] [-f FILE] INFILE OUTFILE +Usage: version.py [-h] [-f FILE] [[-i] FILE] [[-o] FILE] -f FILE, --file=FILE Read variables from FILE. + -i FILE, --input=FILE Read strings to substitute from FILE. + -o FILE, --output=FILE Write substituted strings to FILE. -h, --help Print this help and exit. """ variable_files = [] + in_file = None + out_file = None try: try: @@ -173,13 +177,20 @@ Usage: version.py [-h] [-f FILE] INFILE OUTFILE for o, a in opts: if o in ('-f', '--file'): variable_files.append(a) + elif o in ('-i', '--input'): + in_file = a + elif o in ('-o', '--output'): + out_file = a elif o in ('-h', '--help'): print helpstr return 0 - try: - in_file, out_file = args - except ValueError: - msg = 'Incorrect number of arguments: %r' % args + while len(args) and (in_file is None or out_file is None): + if in_file is None: + in_file = args.pop(0) + elif out_file is None: + out_file = args.pop(0) + if args: + msg = 'Unexpected arguments: %r' % args raise Usage(msg) except Usage, err: sys.stderr.write(err.msg) @@ -188,9 +199,24 @@ Usage: version.py [-h] [-f FILE] INFILE OUTFILE values = fetch_values(variable_files) - contents = subst_contents(in_file, values) - write_if_changed(out_file, contents) + if in_file: + contents = subst_contents(in_file, values) + else: + # Generate a default set of version information. + contents = """MAJOR=%(MAJOR)s +MINOR=%(MINOR)s +BUILD=%(BUILD)s +PATCH=%(PATCH)s +LASTCHANGE=%(LASTCHANGE)s +OFFICIAL_BUILD=%(OFFICIAL_BUILD)s +""" % values + + + if out_file: + write_if_changed(out_file, contents) + else: + print contents return 0 |