| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 | |
| 37 | 34 |
| 38 def _GetOutput(args): | 35 def _GetOutput(args): |
| 39 """Runs a subprocess and waits for termination. Returns (stdout, returncode) | 36 """Runs a subprocess and waits for termination. Returns (stdout, returncode) |
| 40 of the process. stderr is attached to the parent.""" | 37 of the process. stderr is attached to the parent.""" |
| 41 proc = subprocess.Popen(args, stdout=subprocess.PIPE) | 38 proc = subprocess.Popen(args, stdout=subprocess.PIPE) |
| 42 (stdout, stderr) = proc.communicate() | 39 (stdout, stderr) = proc.communicate() |
| 43 return (stdout, proc.returncode) | 40 return (stdout, proc.returncode) |
| 44 | 41 |
| 45 | 42 |
| 46 def _GetOutputNoError(args): | 43 def _GetOutputNoError(args): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 106 |
| 110 # Return with no error. | 107 # Return with no error. |
| 111 return True | 108 return True |
| 112 | 109 |
| 113 | 110 |
| 114 def _DoSCMKeys(plist, add_keys): | 111 def _DoSCMKeys(plist, add_keys): |
| 115 """Adds the SCM information, visible in about:version, to property list. If | 112 """Adds the SCM information, visible in about:version, to property list. If |
| 116 |add_keys| is True, it will insert the keys, otherwise it will remove them.""" | 113 |add_keys| is True, it will insert the keys, otherwise it will remove them.""" |
| 117 scm_revision = None | 114 scm_revision = None |
| 118 if add_keys: | 115 if add_keys: |
| 119 version_info = lastchange.FetchVersionInfo( | 116 # Pull in the Chrome revision number. |
| 120 default_lastchange=None, directory=TOP) | 117 VERSION_TOOL = os.path.join(TOP, 'chrome/tools/build/version.py') |
| 121 scm_revision = version_info.revision | 118 LASTCHANGE_FILE = os.path.join(TOP, 'build/util/LASTCHANGE') |
| 119 (stdout, retval) = _GetOutput([VERSION_TOOL, '-f', LASTCHANGE_FILE, '-t', |
| 120 '@LASTCHANGE@']) |
| 121 if retval: |
| 122 return False |
| 123 scm_revision = stdout.rstrip() |
| 122 | 124 |
| 123 # See if the operation failed. | 125 # See if the operation failed. |
| 124 _RemoveKeys(plist, 'SCMRevision') | 126 _RemoveKeys(plist, 'SCMRevision') |
| 125 if scm_revision != None: | 127 if scm_revision != None: |
| 126 plist['SCMRevision'] = scm_revision | 128 plist['SCMRevision'] = scm_revision |
| 127 elif add_keys: | 129 elif add_keys: |
| 128 print >>sys.stderr, 'Could not determine SCM revision. This may be OK.' | 130 print >>sys.stderr, 'Could not determine SCM revision. This may be OK.' |
| 129 | 131 |
| 130 # TODO(thakis): Remove this once m25 has reached stable. | 132 # TODO(thakis): Remove this once m25 has reached stable. |
| 131 _RemoveKeys(plist, 'SCMPath') | 133 _RemoveKeys(plist, 'SCMPath') |
| 134 return True |
| 132 | 135 |
| 133 | 136 |
| 134 def _DoPDFKeys(plist, add_keys): | 137 def _DoPDFKeys(plist, add_keys): |
| 135 """Adds PDF support to the document types list. If add_keys is True, it will | 138 """Adds PDF support to the document types list. If add_keys is True, it will |
| 136 add the type information dictionary. If it is False, it will remove it if | 139 add the type information dictionary. If it is False, it will remove it if |
| 137 present.""" | 140 present.""" |
| 138 | 141 |
| 139 PDF_FILE_EXTENSION = 'pdf' | 142 PDF_FILE_EXTENSION = 'pdf' |
| 140 | 143 |
| 141 def __AddPDFKeys(sub_plist): | 144 def __AddPDFKeys(sub_plist): |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 # Only add Keystone in Release builds. | 278 # Only add Keystone in Release builds. |
| 276 if options.use_keystone and env['CONFIGURATION'] == 'Release': | 279 if options.use_keystone and env['CONFIGURATION'] == 'Release': |
| 277 if options.bundle_identifier is None: | 280 if options.bundle_identifier is None: |
| 278 print >>sys.stderr, 'Use of Keystone requires the bundle id.' | 281 print >>sys.stderr, 'Use of Keystone requires the bundle id.' |
| 279 return 1 | 282 return 1 |
| 280 _AddKeystoneKeys(plist, options.bundle_identifier) | 283 _AddKeystoneKeys(plist, options.bundle_identifier) |
| 281 else: | 284 else: |
| 282 _RemoveKeystoneKeys(plist) | 285 _RemoveKeystoneKeys(plist) |
| 283 | 286 |
| 284 # Adds or removes any SCM keys. | 287 # Adds or removes any SCM keys. |
| 285 _DoSCMKeys(plist, options.add_scm_info) | 288 if not _DoSCMKeys(plist, options.add_scm_info): |
| 289 return 3 |
| 286 | 290 |
| 287 # Adds or removes the PDF file handler entry. | 291 # Adds or removes the PDF file handler entry. |
| 288 _DoPDFKeys(plist, options.add_pdf_support) | 292 _DoPDFKeys(plist, options.add_pdf_support) |
| 289 | 293 |
| 290 # Now that all keys have been mutated, rewrite the file. | 294 # Now that all keys have been mutated, rewrite the file. |
| 291 temp_info_plist = tempfile.NamedTemporaryFile() | 295 temp_info_plist = tempfile.NamedTemporaryFile() |
| 292 plistlib.writePlist(plist, temp_info_plist.name) | 296 plistlib.writePlist(plist, temp_info_plist.name) |
| 293 | 297 |
| 294 # Info.plist will work perfectly well in any plist format, but traditionally | 298 # Info.plist will work perfectly well in any plist format, but traditionally |
| 295 # applications use xml1 for this, so convert it to ensure that it's valid. | 299 # applications use xml1 for this, so convert it to ensure that it's valid. |
| 296 proc = subprocess.Popen(['plutil', '-convert', 'xml1', '-o', DEST_INFO_PLIST, | 300 proc = subprocess.Popen(['plutil', '-convert', 'xml1', '-o', DEST_INFO_PLIST, |
| 297 temp_info_plist.name]) | 301 temp_info_plist.name]) |
| 298 proc.wait() | 302 proc.wait() |
| 299 return proc.returncode | 303 return proc.returncode |
| 300 | 304 |
| 301 | 305 |
| 302 if __name__ == '__main__': | 306 if __name__ == '__main__': |
| 303 sys.exit(Main(sys.argv[1:])) | 307 sys.exit(Main(sys.argv[1:])) |
| OLD | NEW |