OLD | NEW |
1 #!/usr/bin/python2.6 | 1 #!/usr/bin/python2.6 |
2 | 2 |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # | 7 # |
8 # Xcode supports build variable substitutions and CPP; sadly, that doesn't work | 8 # Xcode supports build variable substitutions and CPP; sadly, that doesn't work |
9 # because: | 9 # because: |
10 # | 10 # |
(...skipping 13 matching lines...) Expand all Loading... |
24 import os | 24 import os |
25 from os import environ as env | 25 from os import environ as env |
26 import plistlib | 26 import plistlib |
27 import re | 27 import re |
28 import subprocess | 28 import subprocess |
29 import sys | 29 import sys |
30 import tempfile | 30 import tempfile |
31 | 31 |
32 TOP = os.path.join(env['SRCROOT'], '..') | 32 TOP = os.path.join(env['SRCROOT'], '..') |
33 | 33 |
| 34 sys.path.insert(0, os.path.join(TOP, "build/util")) |
| 35 import lastchange |
| 36 |
34 | 37 |
35 def _GetOutput(args): | 38 def _GetOutput(args): |
36 """Runs a subprocess and waits for termination. Returns (stdout, returncode) | 39 """Runs a subprocess and waits for termination. Returns (stdout, returncode) |
37 of the process. stderr is attached to the parent.""" | 40 of the process. stderr is attached to the parent.""" |
38 proc = subprocess.Popen(args, stdout=subprocess.PIPE) | 41 proc = subprocess.Popen(args, stdout=subprocess.PIPE) |
39 (stdout, stderr) = proc.communicate() | 42 (stdout, stderr) = proc.communicate() |
40 return (stdout, proc.returncode) | 43 return (stdout, proc.returncode) |
41 | 44 |
42 | 45 |
43 def _GetOutputNoError(args): | 46 def _GetOutputNoError(args): |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 # enough to find out with "lsregister -dump). | 94 # enough to find out with "lsregister -dump). |
92 # http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html | 95 # http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html |
93 # BUILD will always be an increasing value, so BUILD_PATH gives us something | 96 # BUILD will always be an increasing value, so BUILD_PATH gives us something |
94 # unique that meetings what LS wants. | 97 # unique that meetings what LS wants. |
95 plist['CFBundleVersion'] = bundle_version | 98 plist['CFBundleVersion'] = bundle_version |
96 | 99 |
97 # Return with no error. | 100 # Return with no error. |
98 return True | 101 return True |
99 | 102 |
100 | 103 |
101 def _GetSCMInfo(): | |
102 """Returns a 2-Tuple of (scm_path, scm_revision) for the SVN information.""" | |
103 # Attempt to get both the SVN revision number and the branch (or trunk). | |
104 scm_revision = None | |
105 scm_path = None | |
106 | |
107 # First attempt to get the SVN revision number and path. | |
108 (stdout, retval) = _GetOutputNoError(['svn', 'info', TOP]) | |
109 if not retval: | |
110 match = re.search('^Revision: ([0-9]+)$', stdout, re.MULTILINE) | |
111 if match: | |
112 scm_revision = match.group(1) | |
113 | |
114 match = re.search('^Repository Root: (.+)$', stdout, re.MULTILINE) | |
115 if match: | |
116 svn_repo_root = match.group(1) | |
117 | |
118 match = re.search('^URL: (.+)$', stdout, re.MULTILINE) | |
119 if match: | |
120 svn_url = match.group(1) | |
121 | |
122 # If there's both a repo root and a URL, find the branch path. | |
123 if svn_repo_root and svn_url and svn_url.startswith(svn_repo_root): | |
124 # Grab the path to the source root in the Subversion repository by taking | |
125 # the URL to the source root directory and the repository root, and | |
126 # removing the latter from the former. This ensures that scm_path will | |
127 # contain a useful path regardless of the Subversion server, mirror, and | |
128 # authentication scheme in use. | |
129 scm_path = svn_url[len(svn_repo_root):] | |
130 | |
131 # If the desired information was found via SVN, return it now. | |
132 if scm_revision != None and scm_path != None: | |
133 return (scm_path, scm_revision) | |
134 | |
135 # If a SVN revision number couldn't be found, try getting it through git. | |
136 (stdout, retval) = _GetOutputNoError(['git', 'log', '-1', | |
137 '--grep=git-svn-id', '--format=%b']) | |
138 # Extract both the last changed SVN revision and the branch path (see block | |
139 # comment above). | |
140 # git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85528 0039d316-1c4b... | |
141 if not retval: | |
142 match = re.search(r'git-svn-id: .*/(chrome|svn)(/.*)@([0-9]+)', stdout, | |
143 re.MULTILINE) | |
144 if match: | |
145 scm_path = match.group(2) | |
146 scm_revision = match.group(3) | |
147 | |
148 # Finally, return the results (which could be None on error). | |
149 return (scm_path, scm_revision) | |
150 | |
151 | |
152 def _DoSVNKeys(plist, add_keys): | 104 def _DoSVNKeys(plist, add_keys): |
153 """Adds the SVN information, visible in about:version, to property list. If | 105 """Adds the SVN information, visible in about:version, to property list. If |
154 |add_keys| is True, it will insert the keys, otherwise it will remove them.""" | 106 |add_keys| is True, it will insert the keys, otherwise it will remove them.""" |
155 (scm_path, scm_revision) = None, None | 107 scm_path, scm_revision = None, None |
156 if add_keys: | 108 if add_keys: |
157 (scm_path, scm_revision) = _GetSCMInfo() | 109 version_info = lastchange.FetchVersionInfo(default_lastchange=None) |
| 110 scm_path, scm_revision = version_info.url, version_info.revision |
158 | 111 |
159 # See if the operation failed. | 112 # See if the operation failed. |
160 _RemoveKeys(plist, 'SVNRevision') | 113 _RemoveKeys(plist, 'SVNRevision') |
161 if scm_revision != None: | 114 if scm_revision != None: |
162 plist['SVNRevision'] = scm_revision | 115 plist['SVNRevision'] = scm_revision |
163 elif add_keys: | 116 elif add_keys: |
164 print >>sys.stderr, 'Could not determine svn revision. This may be OK.' | 117 print >>sys.stderr, 'Could not determine svn revision. This may be OK.' |
165 | 118 |
166 if scm_path != None: | 119 if scm_path != None: |
167 plist['SVNPath'] = scm_path | 120 plist['SVNPath'] = scm_path |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 # Info.plist will work perfectly well in any plist format, but traditionally | 264 # Info.plist will work perfectly well in any plist format, but traditionally |
312 # applications use xml1 for this, so convert it to ensure that it's valid. | 265 # applications use xml1 for this, so convert it to ensure that it's valid. |
313 proc = subprocess.Popen(['plutil', '-convert', 'xml1', '-o', DEST_INFO_PLIST, | 266 proc = subprocess.Popen(['plutil', '-convert', 'xml1', '-o', DEST_INFO_PLIST, |
314 temp_info_plist.name]) | 267 temp_info_plist.name]) |
315 proc.wait() | 268 proc.wait() |
316 return proc.returncode | 269 return proc.returncode |
317 | 270 |
318 | 271 |
319 if __name__ == '__main__': | 272 if __name__ == '__main__': |
320 sys.exit(Main(sys.argv[1:])) | 273 sys.exit(Main(sys.argv[1:])) |
OLD | NEW |