| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 # See if the operation failed. | 125 # See if the operation failed. |
| 126 _RemoveKeys(plist, 'SCMRevision') | 126 _RemoveKeys(plist, 'SCMRevision') |
| 127 if scm_revision != None: | 127 if scm_revision != None: |
| 128 plist['SCMRevision'] = scm_revision | 128 plist['SCMRevision'] = scm_revision |
| 129 elif add_keys: | 129 elif add_keys: |
| 130 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.' |
| 131 | 131 |
| 132 return True | 132 return True |
| 133 | 133 |
| 134 | 134 |
| 135 def _DoPDFKeys(plist, add_keys): | |
| 136 """Adds PDF support to the document types list. If add_keys is True, it will | |
| 137 add the type information dictionary. If it is False, it will remove it if | |
| 138 present.""" | |
| 139 | |
| 140 PDF_FILE_EXTENSION = 'pdf' | |
| 141 | |
| 142 def __AddPDFKeys(sub_plist): | |
| 143 """Writes the keys into a sub-dictionary of the plist.""" | |
| 144 sub_plist['CFBundleTypeExtensions'] = [PDF_FILE_EXTENSION] | |
| 145 sub_plist['CFBundleTypeIconFile'] = 'document.icns' | |
| 146 sub_plist['CFBundleTypeMIMETypes'] = 'application/pdf' | |
| 147 sub_plist['CFBundleTypeName'] = 'PDF Document' | |
| 148 sub_plist['CFBundleTypeRole'] = 'Viewer' | |
| 149 | |
| 150 DOCUMENT_TYPES_KEY = 'CFBundleDocumentTypes' | |
| 151 | |
| 152 # First get the list of document types, creating it if necessary. | |
| 153 try: | |
| 154 extensions = plist[DOCUMENT_TYPES_KEY] | |
| 155 except KeyError: | |
| 156 # If this plist doesn't have a type dictionary, create one if set to add the | |
| 157 # keys. If not, bail. | |
| 158 if not add_keys: | |
| 159 return | |
| 160 extensions = plist[DOCUMENT_TYPES_KEY] = [] | |
| 161 | |
| 162 # Loop over each entry in the list, looking for one that handles PDF types. | |
| 163 for i, ext in enumerate(extensions): | |
| 164 # If an entry for .pdf files is found... | |
| 165 if 'CFBundleTypeExtensions' not in ext: | |
| 166 continue | |
| 167 if PDF_FILE_EXTENSION in ext['CFBundleTypeExtensions']: | |
| 168 if add_keys: | |
| 169 # Overwrite the existing keys with new ones. | |
| 170 __AddPDFKeys(ext) | |
| 171 else: | |
| 172 # Otherwise, delete the entry entirely. | |
| 173 del extensions[i] | |
| 174 return | |
| 175 | |
| 176 # No PDF entry exists. If one needs to be added, do so now. | |
| 177 if add_keys: | |
| 178 pdf_entry = {} | |
| 179 __AddPDFKeys(pdf_entry) | |
| 180 extensions.append(pdf_entry) | |
| 181 | |
| 182 | |
| 183 def _AddBreakpadKeys(plist, branding): | 135 def _AddBreakpadKeys(plist, branding): |
| 184 """Adds the Breakpad keys. This must be called AFTER _AddVersionKeys() and | 136 """Adds the Breakpad keys. This must be called AFTER _AddVersionKeys() and |
| 185 also requires the |branding| argument.""" | 137 also requires the |branding| argument.""" |
| 186 plist['BreakpadReportInterval'] = '3600' # Deliberately a string. | 138 plist['BreakpadReportInterval'] = '3600' # Deliberately a string. |
| 187 plist['BreakpadProduct'] = '%s_Mac' % branding | 139 plist['BreakpadProduct'] = '%s_Mac' % branding |
| 188 plist['BreakpadProductDisplay'] = branding | 140 plist['BreakpadProductDisplay'] = branding |
| 189 plist['BreakpadVersion'] = plist['CFBundleShortVersionString'] | 141 plist['BreakpadVersion'] = plist['CFBundleShortVersionString'] |
| 190 # These are both deliberately strings and not boolean. | 142 # These are both deliberately strings and not boolean. |
| 191 plist['BreakpadSendAndExit'] = 'YES' | 143 plist['BreakpadSendAndExit'] = 'YES' |
| 192 plist['BreakpadSkipConfirm'] = 'YES' | 144 plist['BreakpadSkipConfirm'] = 'YES' |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 parser = optparse.OptionParser('%prog [options]') | 204 parser = optparse.OptionParser('%prog [options]') |
| 253 parser.add_option('--breakpad', dest='use_breakpad', action='store', | 205 parser.add_option('--breakpad', dest='use_breakpad', action='store', |
| 254 type='int', default=False, help='Enable Breakpad [1 or 0]') | 206 type='int', default=False, help='Enable Breakpad [1 or 0]') |
| 255 parser.add_option('--breakpad_uploads', dest='breakpad_uploads', | 207 parser.add_option('--breakpad_uploads', dest='breakpad_uploads', |
| 256 action='store', type='int', default=False, | 208 action='store', type='int', default=False, |
| 257 help='Enable Breakpad\'s uploading of crash dumps [1 or 0]') | 209 help='Enable Breakpad\'s uploading of crash dumps [1 or 0]') |
| 258 parser.add_option('--keystone', dest='use_keystone', action='store', | 210 parser.add_option('--keystone', dest='use_keystone', action='store', |
| 259 type='int', default=False, help='Enable Keystone [1 or 0]') | 211 type='int', default=False, help='Enable Keystone [1 or 0]') |
| 260 parser.add_option('--scm', dest='add_scm_info', action='store', type='int', | 212 parser.add_option('--scm', dest='add_scm_info', action='store', type='int', |
| 261 default=True, help='Add SCM metadata [1 or 0]') | 213 default=True, help='Add SCM metadata [1 or 0]') |
| 262 parser.add_option('--pdf', dest='add_pdf_support', action='store', type='int', | |
| 263 default=False, help='Add PDF file handler support [1 or 0]') | |
| 264 parser.add_option('--branding', dest='branding', action='store', | 214 parser.add_option('--branding', dest='branding', action='store', |
| 265 type='string', default=None, help='The branding of the binary') | 215 type='string', default=None, help='The branding of the binary') |
| 266 parser.add_option('--bundle_id', dest='bundle_identifier', | 216 parser.add_option('--bundle_id', dest='bundle_identifier', |
| 267 action='store', type='string', default=None, | 217 action='store', type='string', default=None, |
| 268 help='The bundle id of the binary') | 218 help='The bundle id of the binary') |
| 269 parser.add_option('--version', dest='version', action='store', type='string', | 219 parser.add_option('--version', dest='version', action='store', type='string', |
| 270 default=None, help='The version string [major.minor.build.patch]') | 220 default=None, help='The version string [major.minor.build.patch]') |
| 271 (options, args) = parser.parse_args(argv) | 221 (options, args) = parser.parse_args(argv) |
| 272 | 222 |
| 273 if len(args) > 0: | 223 if len(args) > 0: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 print >>sys.stderr, 'Use of Keystone requires the bundle id.' | 257 print >>sys.stderr, 'Use of Keystone requires the bundle id.' |
| 308 return 1 | 258 return 1 |
| 309 _AddKeystoneKeys(plist, options.bundle_identifier) | 259 _AddKeystoneKeys(plist, options.bundle_identifier) |
| 310 else: | 260 else: |
| 311 _RemoveKeystoneKeys(plist) | 261 _RemoveKeystoneKeys(plist) |
| 312 | 262 |
| 313 # Adds or removes any SCM keys. | 263 # Adds or removes any SCM keys. |
| 314 if not _DoSCMKeys(plist, options.add_scm_info): | 264 if not _DoSCMKeys(plist, options.add_scm_info): |
| 315 return 3 | 265 return 3 |
| 316 | 266 |
| 317 # Adds or removes the PDF file handler entry. | |
| 318 _DoPDFKeys(plist, options.add_pdf_support) | |
| 319 | |
| 320 # Now that all keys have been mutated, rewrite the file. | 267 # Now that all keys have been mutated, rewrite the file. |
| 321 temp_info_plist = tempfile.NamedTemporaryFile() | 268 temp_info_plist = tempfile.NamedTemporaryFile() |
| 322 plistlib.writePlist(plist, temp_info_plist.name) | 269 plistlib.writePlist(plist, temp_info_plist.name) |
| 323 | 270 |
| 324 # Info.plist will work perfectly well in any plist format, but traditionally | 271 # Info.plist will work perfectly well in any plist format, but traditionally |
| 325 # applications use xml1 for this, so convert it to ensure that it's valid. | 272 # applications use xml1 for this, so convert it to ensure that it's valid. |
| 326 proc = subprocess.Popen(['plutil', '-convert', 'xml1', '-o', DEST_INFO_PLIST, | 273 proc = subprocess.Popen(['plutil', '-convert', 'xml1', '-o', DEST_INFO_PLIST, |
| 327 temp_info_plist.name]) | 274 temp_info_plist.name]) |
| 328 proc.wait() | 275 proc.wait() |
| 329 return proc.returncode | 276 return proc.returncode |
| 330 | 277 |
| 331 | 278 |
| 332 if __name__ == '__main__': | 279 if __name__ == '__main__': |
| 333 sys.exit(Main(sys.argv[1:])) | 280 sys.exit(Main(sys.argv[1:])) |
| OLD | NEW |