summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsgk@google.com <sgk@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 16:08:16 +0000
committersgk@google.com <sgk@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 16:08:16 +0000
commit198d68d6d03f911613416739963482f6fde00255 (patch)
tree33895386517610bc231ae5e7385138e086709d06
parentec520c71074e4cddc9da53076daa52d67cb80d33 (diff)
downloadchromium_src-198d68d6d03f911613416739963482f6fde00255.zip
chromium_src-198d68d6d03f911613416739963482f6fde00255.tar.gz
chromium_src-198d68d6d03f911613416739963482f6fde00255.tar.bz2
Fetch last change (revision) info in a separate action that can run
every build, instead of having it occur as a side effect of updating some other target for which we want to use normal up-to-date checks. BUG=none TEST=none Review URL: http://codereview.chromium.org/118192 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17634 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base.gyp11
-rw-r--r--build/all.gyp1
-rw-r--r--build/util/build_util.gyp34
-rw-r--r--build/util/lastchange.py121
-rw-r--r--chrome/chrome.gyp30
-rwxr-xr-xchrome/tools/build/version.py54
6 files changed, 181 insertions, 70 deletions
diff --git a/base/base.gyp b/base/base.gyp
index a294726..b73415a 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -362,11 +362,13 @@
{
'action_name': 'linux_version',
'variables': {
+ 'lastchange_path':
+ '<(SHARED_INTERMEDIATE_DIR)/build/LASTCHANGE',
'version_py_path': '../chrome/tools/build/version.py',
'version_path': '../chrome/VERSION',
'template_input_path': 'file_version_info_linux.h.version',
'template_output_path':
- '<(SHARED_INTERMEDIATE_DIR)/base/file_version_info_linux.h',
+ '<(SHARED_INTERMEDIATE_DIR)/base/file_version_info_linux.h',
},
'conditions': [
[ 'branding == "Chrome"', {
@@ -385,22 +387,24 @@
'<(template_input_path)',
'<(version_path)',
'<(branding_path)',
+ '<(lastchange_path)',
],
'outputs': [
# Use a non-existant output so this action always runs and
# generates version information, e.g. to capture revision
# changes, which aren't captured by file dependencies.
- '<(SHARED_INTERMEDIATE_DIR)/base/file_version_info_linux.bogus',
+ '<(SHARED_INTERMEDIATE_DIR)/base/file_version_info_linux.always',
# And this is the real output, so that the build system knows
# what action generates it.
- '<(SHARED_INTERMEDIATE_DIR)/base/file_version_info_linux.h',
+ '<(template_output_path)',
],
'action': [
'python',
'<(version_py_path)',
'-f', '<(version_path)',
'-f', '<(branding_path)',
+ '-f', '<(lastchange_path)',
'<(template_input_path)',
'<(template_output_path)',
],
@@ -419,6 +423,7 @@
'idle_timer.cc',
],
'dependencies': [
+ '../build/util/build_util.gyp:lastchange',
'../build/linux/system.gyp:gtk',
'../build/linux/system.gyp:nss',
],
diff --git a/build/all.gyp b/build/all.gyp
index 202c2038..ffe041e 100644
--- a/build/all.gyp
+++ b/build/all.gyp
@@ -37,6 +37,7 @@
'../third_party/zlib/zlib.gyp:*',
'../webkit/tools/test_shell/test_shell.gyp:*',
'../webkit/webkit.gyp:*',
+ 'util/build_util.gyp:*',
'temp_gyp/googleurl.gyp:*',
],
'conditions': [
diff --git a/build/util/build_util.gyp b/build/util/build_util.gyp
new file mode 100644
index 0000000..0624ab5
--- /dev/null
+++ b/build/util/build_util.gyp
@@ -0,0 +1,34 @@
+# 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.
+
+{
+ 'includes': [
+ '../common.gypi',
+ ],
+ 'targets': [
+ {
+ 'target_name': 'lastchange',
+ 'type': 'none',
+ 'variables': {
+ 'lastchange_out_path': '<(SHARED_INTERMEDIATE_DIR)/build/LASTCHANGE',
+ },
+ 'actions': [
+ {
+ 'action_name': 'lastchange',
+ 'inputs': [
+ 'lastchange.py',
+ ],
+ 'outputs': [
+ '<(lastchange_out_path)',
+ '<(lastchange_out_path).always',
+ ],
+ 'action': [
+ 'python', '<@(_inputs)', '-o', '<(lastchange_out_path)',
+ ],
+ 'message': 'Extracting last change to <(lastchange_out_path)'
+ },
+ ],
+ },
+ ]
+}
diff --git a/build/util/lastchange.py b/build/util/lastchange.py
new file mode 100644
index 0000000..3bac762
--- /dev/null
+++ b/build/util/lastchange.py
@@ -0,0 +1,121 @@
+#!/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.
+
+"""
+lastchange.py -- Chromium revision fetching utility.
+"""
+
+import optparse
+import os
+import re
+import subprocess
+import sys
+
+
+def svn_fetch_revision():
+ """
+ Fetch the Subversion revision for the local tree.
+
+ Errors are swallowed.
+ """
+ try:
+ p = subprocess.Popen(['svn', 'info'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError:
+ # 'svn' is apparently either not installed or not executable.
+ return None
+ revision = None
+ if p:
+ svn_re = re.compile('^Revision:\s+(\S+)$', re.M)
+ m = svn_re.search(p.stdout.read())
+ if m:
+ revision = m.group(1)
+ return revision
+
+
+def git_fetch_id():
+ """
+ Fetch the GIT identifier for the local tree.
+
+ Errors are swallowed.
+ """
+ try:
+ p = subprocess.Popen(['git', 'log', '-1'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError:
+ # 'git' is apparently either not installed or not executable.
+ return None
+ id = None
+ if p:
+ git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M)
+ m = git_re.search(p.stdout.read())
+ if m:
+ id = m.group(1)
+ return id
+
+
+def fetch_change():
+ """
+ Returns the last change, from some appropriate revision control system.
+ """
+ change = svn_fetch_revision()
+ if not change and sys.platform in ('linux2',):
+ change = git_fetch_id()
+ if not change:
+ change = '0'
+ return change
+
+
+def write_if_changed(file_name, contents):
+ """
+ Writes the specified contents to the specified file_name
+ iff the contents are different than the current contents.
+ """
+ try:
+ old_contents = open(file_name, 'r').read()
+ except EnvironmentError:
+ pass
+ else:
+ if contents == old_contents:
+ return
+ os.unlink(file_name)
+ open(file_name, 'w').write(contents)
+
+
+def main(argv=None):
+ if argv is None:
+ argv = sys.argv
+
+ parser = optparse.OptionParser(usage="lastchange.py [-h] [[-o] FILE]")
+ parser.add_option("-o", "--output", metavar="FILE",
+ help="write last change to FILE")
+ opts, args = parser.parse_args(argv[1:])
+
+ out_file = opts.output
+
+ while len(args) and out_file is None:
+ if out_file is None:
+ out_file = args.pop(0)
+ if args:
+ sys.stderr.write('Unexpected arguments: %r\n\n' % args)
+ parser.print_help()
+ sys.exit(2)
+
+ change = fetch_change()
+
+ contents = "LASTCHANGE=%s\n" % change
+
+ if out_file:
+ write_if_changed(out_file, contents)
+ else:
+ sys.stdout.write(contents)
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 308f1e5..60e8f25 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -3677,6 +3677,7 @@
'chrome_resources',
'installer/installer.gyp:installer_util_strings',
'worker',
+ '../build/util/build_util.gyp:lastchange',
'../net/net.gyp:net_resources',
'../views/views.gyp:views',
'../webkit/webkit.gyp:webkit_resources',
@@ -3688,35 +3689,35 @@
'rule_name': 'win_version',
'extension': 'version',
'variables': {
- 'version_py': '../chrome/tools/build/version.py',
- 'VERSION': '../chrome/VERSION',
+ 'lastchange_path':
+ '<(SHARED_INTERMEDIATE_DIR)/build/LASTCHANGE',
+ 'version_py': 'tools/build/version.py',
+ 'version_path': 'VERSION',
'template_input_path': 'app/chrome_dll_version.rc.version',
- 'template_output_path':
- '<(grit_out_dir)/chrome_dll_version.rc',
+ 'template_output_path': '<(grit_out_dir)/chrome_dll_version.rc',
},
'conditions': [
[ 'branding == "Chrome"', {
'variables': {
- 'BRANDING':
- '../chrome/app/theme/google_chrome/BRANDING',
+ 'branding_path': 'app/theme/google_chrome/BRANDING',
},
}, { # else branding!="Chrome"
'variables': {
- 'BRANDING':
- '../chrome/app/theme/chromium/BRANDING',
+ 'branding_path': 'app/theme/chromium/BRANDING',
},
}],
],
'inputs': [
'<(template_input_path)',
- '<(VERSION)',
- '<(BRANDING)',
+ '<(version_path)',
+ '<(branding_path)',
+ '<(lastchange_path)',
],
'outputs': [
# Use a non-existant output so this action always runs and
# generates version information, e.g. to capture revision
# changes, which aren't captured by file dependencies.
- '<(grit_out_dir)/chrome_dll_version.bogus',
+ '<(grit_out_dir)/chrome_dll_version.always',
# And this is the real output, so that the build system knows
# what action generates it.
@@ -3725,13 +3726,14 @@
'action': [
'python',
'<(version_py)',
- '-f', '<(VERSION)',
- '-f', '<(BRANDING)',
+ '-f', '<(version_path)',
+ '-f', '<(branding_path)',
+ '-f', '<(lastchange_path)',
'<(template_input_path)',
'<(template_output_path)',
],
'process_outputs_as_sources': 1,
- 'message': 'Generating version information'
+ 'message': 'Generating version information in <(template_output_path)'
},
],
'sources': [
diff --git a/chrome/tools/build/version.py b/chrome/tools/build/version.py
index 03abeb7..b6bb820 100755
--- a/chrome/tools/build/version.py
+++ b/chrome/tools/build/version.py
@@ -19,50 +19,6 @@ class Usage(Exception):
self.msg = msg
-def svn_fetch_revision():
- """
- Fetch the Subversion revision for the local tree.
-
- Errors are swallowed.
- """
- try:
- p = subprocess.Popen(['svn', 'info'],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- except OSError:
- # 'svn' is apparently either not installed or not executable.
- return None
- revision = None
- if p:
- svn_re = re.compile('^Revision:\s+(\S+)$', re.M)
- m = svn_re.search(p.stdout.read())
- if m:
- revision = m.group(1)
- return revision
-
-
-def git_fetch_id():
- """
- Fetch the GIT identifier for the local tree.
-
- Errors are swallowed.
- """
- try:
- p = subprocess.Popen(['git', 'log', '-1'],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- except OSError:
- # 'git' is apparently either not installed or not executable.
- return None
- id = None
- if p:
- git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M)
- m = git_re.search(p.stdout.read())
- if m:
- id = m.group(1)
- return id
-
-
def fetch_values_from_file(values_dict, file_name):
"""
Fetches KEYWORD=VALUE settings from the specified file.
@@ -83,17 +39,10 @@ def fetch_values(file_list):
Returns a dictionary of values to be used for substitution, populating
the dictionary with KEYWORD=VALUE settings from the files in 'file_list'.
- Explicitly adds the following values from internal calculations:
+ Explicitly adds the following value from internal calculations:
- LASTCHANGE (the SVN revision, or GIT id of the local tree)
OFFICIAL_BUILD
"""
- change = svn_fetch_revision()
- if not change and sys.platform in ('linux2',):
- change = git_fetch_id()
- if not change:
- change = '0'
-
CHROME_BUILD_TYPE = os.environ.get('CHROME_BUILD_TYPE')
if CHROME_BUILD_TYPE == '_official':
official_build = '1'
@@ -101,7 +50,6 @@ def fetch_values(file_list):
official_build = '0'
values = dict(
- LASTCHANGE = change,
OFFICIAL_BUILD = official_build,
)