Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: build/mac/tweak_info_plist.py

Issue 1881053002: Rework build/mac/tweak_info_plist.py to not rely on environment variables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/app_shim/app_shim.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #
11 # 1. Xcode wants to do the Info.plist work before it runs any build phases, 11 # 1. Xcode wants to do the Info.plist work before it runs any build phases,
12 # this means if we were to generate a .h file for INFOPLIST_PREFIX_HEADER 12 # this means if we were to generate a .h file for INFOPLIST_PREFIX_HEADER
13 # we'd have to put it in another target so it runs in time. 13 # we'd have to put it in another target so it runs in time.
14 # 2. Xcode also doesn't check to see if the header being used as a prefix for 14 # 2. Xcode also doesn't check to see if the header being used as a prefix for
15 # the Info.plist has changed. So even if we updated it, it's only looking 15 # the Info.plist has changed. So even if we updated it, it's only looking
16 # at the modtime of the info.plist to see if that's changed. 16 # at the modtime of the info.plist to see if that's changed.
17 # 17 #
18 # So, we work around all of this by making a script build phase that will run 18 # So, we work around all of this by making a script build phase that will run
19 # during the app build, and simply update the info.plist in place. This way 19 # during the app build, and simply update the info.plist in place. This way
20 # by the time the app target is done, the info.plist is correct. 20 # by the time the app target is done, the info.plist is correct.
21 # 21 #
22 22
23 import optparse 23 import optparse
24 import os 24 import os
25 from os import environ as env
26 import plistlib 25 import plistlib
27 import re 26 import re
28 import subprocess 27 import subprocess
29 import sys 28 import sys
30 import tempfile 29 import tempfile
31 30
32 TOP = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) 31 TOP = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
33 32
34 33
35 def _GetOutput(args): 34 def _GetOutput(args):
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 'KSUpdateURL') 194 'KSUpdateURL')
196 195
197 tag_keys = [] 196 tag_keys = []
198 for tag_suffix in _TagSuffixes(): 197 for tag_suffix in _TagSuffixes():
199 tag_keys.append('KSChannelID' + tag_suffix) 198 tag_keys.append('KSChannelID' + tag_suffix)
200 _RemoveKeys(plist, *tag_keys) 199 _RemoveKeys(plist, *tag_keys)
201 200
202 201
203 def Main(argv): 202 def Main(argv):
204 parser = optparse.OptionParser('%prog [options]') 203 parser = optparse.OptionParser('%prog [options]')
204 parser.add_option('--plist', dest='plist_path', action='store',
205 type='string', default=None, help='The path of the plist to tweak.')
205 parser.add_option('--breakpad', dest='use_breakpad', action='store', 206 parser.add_option('--breakpad', dest='use_breakpad', action='store',
206 type='int', default=False, help='Enable Breakpad [1 or 0]') 207 type='int', default=False, help='Enable Breakpad [1 or 0]')
207 parser.add_option('--breakpad_uploads', dest='breakpad_uploads', 208 parser.add_option('--breakpad_uploads', dest='breakpad_uploads',
208 action='store', type='int', default=False, 209 action='store', type='int', default=False,
209 help='Enable Breakpad\'s uploading of crash dumps [1 or 0]') 210 help='Enable Breakpad\'s uploading of crash dumps [1 or 0]')
210 parser.add_option('--keystone', dest='use_keystone', action='store', 211 parser.add_option('--keystone', dest='use_keystone', action='store',
211 type='int', default=False, help='Enable Keystone [1 or 0]') 212 type='int', default=False, help='Enable Keystone [1 or 0]')
212 parser.add_option('--scm', dest='add_scm_info', action='store', type='int', 213 parser.add_option('--scm', dest='add_scm_info', action='store', type='int',
213 default=True, help='Add SCM metadata [1 or 0]') 214 default=True, help='Add SCM metadata [1 or 0]')
214 parser.add_option('--branding', dest='branding', action='store', 215 parser.add_option('--branding', dest='branding', action='store',
215 type='string', default=None, help='The branding of the binary') 216 type='string', default=None, help='The branding of the binary')
216 parser.add_option('--bundle_id', dest='bundle_identifier', 217 parser.add_option('--bundle_id', dest='bundle_identifier',
217 action='store', type='string', default=None, 218 action='store', type='string', default=None,
218 help='The bundle id of the binary') 219 help='The bundle id of the binary')
219 parser.add_option('--version', dest='version', action='store', type='string', 220 parser.add_option('--version', dest='version', action='store', type='string',
220 default=None, help='The version string [major.minor.build.patch]') 221 default=None, help='The version string [major.minor.build.patch]')
221 (options, args) = parser.parse_args(argv) 222 (options, args) = parser.parse_args(argv)
222 223
223 if len(args) > 0: 224 if len(args) > 0:
224 print >>sys.stderr, parser.get_usage() 225 print >>sys.stderr, parser.get_usage()
225 return 1 226 return 1
226 227
228 if not options.plist_path:
229 print >>sys.stderr, 'No --plist specified.'
230 return 1
231
227 # Read the plist into its parsed format. 232 # Read the plist into its parsed format.
228 DEST_INFO_PLIST = os.path.join(env['TARGET_BUILD_DIR'], env['INFOPLIST_PATH']) 233 plist = plistlib.readPlist(options.plist_path)
229 plist = plistlib.readPlist(DEST_INFO_PLIST)
230 234
231 # Insert the product version. 235 # Insert the product version.
232 if not _AddVersionKeys(plist, version=options.version): 236 if not _AddVersionKeys(plist, version=options.version):
233 return 2 237 return 2
234 238
235 # Add Breakpad if configured to do so. 239 # Add Breakpad if configured to do so.
236 if options.use_breakpad: 240 if options.use_breakpad:
237 if options.branding is None: 241 if options.branding is None:
238 print >>sys.stderr, 'Use of Breakpad requires branding.' 242 print >>sys.stderr, 'Use of Breakpad requires branding.'
239 return 1 243 return 1
240 _AddBreakpadKeys(plist, options.branding) 244 _AddBreakpadKeys(plist, options.branding)
241 if options.breakpad_uploads: 245 if options.breakpad_uploads:
242 plist['BreakpadURL'] = 'https://clients2.google.com/cr/report' 246 plist['BreakpadURL'] = 'https://clients2.google.com/cr/report'
243 else: 247 else:
244 # This allows crash dumping to a file without uploading the 248 # This allows crash dumping to a file without uploading the
245 # dump, for testing purposes. Breakpad does not recognise 249 # dump, for testing purposes. Breakpad does not recognise
246 # "none" as a special value, but this does stop crash dump 250 # "none" as a special value, but this does stop crash dump
247 # uploading from happening. We need to specify something 251 # uploading from happening. We need to specify something
248 # because if "BreakpadURL" is not present, Breakpad will not 252 # because if "BreakpadURL" is not present, Breakpad will not
249 # register its crash handler and no crash dumping will occur. 253 # register its crash handler and no crash dumping will occur.
250 plist['BreakpadURL'] = 'none' 254 plist['BreakpadURL'] = 'none'
251 else: 255 else:
252 _RemoveBreakpadKeys(plist) 256 _RemoveBreakpadKeys(plist)
253 257
254 # Only add Keystone in Release builds. 258 # Add Keystone if configured to do so.
255 if options.use_keystone and env['CONFIGURATION'] == 'Release': 259 if options.use_keystone:
256 if options.bundle_identifier is None: 260 if options.bundle_identifier is None:
257 print >>sys.stderr, 'Use of Keystone requires the bundle id.' 261 print >>sys.stderr, 'Use of Keystone requires the bundle id.'
258 return 1 262 return 1
259 _AddKeystoneKeys(plist, options.bundle_identifier) 263 _AddKeystoneKeys(plist, options.bundle_identifier)
260 else: 264 else:
261 _RemoveKeystoneKeys(plist) 265 _RemoveKeystoneKeys(plist)
262 266
263 # Adds or removes any SCM keys. 267 # Adds or removes any SCM keys.
264 if not _DoSCMKeys(plist, options.add_scm_info): 268 if not _DoSCMKeys(plist, options.add_scm_info):
265 return 3 269 return 3
266 270
267 # Now that all keys have been mutated, rewrite the file. 271 # Now that all keys have been mutated, rewrite the file.
268 temp_info_plist = tempfile.NamedTemporaryFile() 272 temp_info_plist = tempfile.NamedTemporaryFile()
269 plistlib.writePlist(plist, temp_info_plist.name) 273 plistlib.writePlist(plist, temp_info_plist.name)
270 274
271 # Info.plist will work perfectly well in any plist format, but traditionally 275 # Info.plist will work perfectly well in any plist format, but traditionally
272 # applications use xml1 for this, so convert it to ensure that it's valid. 276 # applications use xml1 for this, so convert it to ensure that it's valid.
273 proc = subprocess.Popen(['plutil', '-convert', 'xml1', '-o', DEST_INFO_PLIST, 277 proc = subprocess.Popen(['plutil', '-convert', 'xml1',
278 '-o', options.plist_path,
274 temp_info_plist.name]) 279 temp_info_plist.name])
275 proc.wait() 280 proc.wait()
276 return proc.returncode 281 return proc.returncode
277 282
278 283
279 if __name__ == '__main__': 284 if __name__ == '__main__':
280 sys.exit(Main(sys.argv[1:])) 285 sys.exit(Main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | chrome/app_shim/app_shim.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698