OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import fnmatch | 6 import fnmatch |
7 import glob | 7 import glob |
8 import os | 8 import os |
9 import plistlib | 9 import plistlib |
10 import shutil | 10 import shutil |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 else: | 225 else: |
226 app_identifier_prefix = '*.' | 226 app_identifier_prefix = '*.' |
227 entitlements.ExpandVariables({ | 227 entitlements.ExpandVariables({ |
228 'CFBundleIdentifier': bundle_identifier, | 228 'CFBundleIdentifier': bundle_identifier, |
229 'AppIdentifierPrefix': app_identifier_prefix, | 229 'AppIdentifierPrefix': app_identifier_prefix, |
230 }) | 230 }) |
231 return entitlements | 231 return entitlements |
232 | 232 |
233 | 233 |
234 class Action(object): | 234 class Action(object): |
235 | |
236 """Class implementing one action supported by the script.""" | 235 """Class implementing one action supported by the script.""" |
237 | 236 |
238 @classmethod | 237 @classmethod |
239 def Register(cls, subparsers): | 238 def Register(cls, subparsers): |
240 parser = subparsers.add_parser(cls.name, help=cls.help) | 239 parser = subparsers.add_parser(cls.name, help=cls.help) |
241 parser.set_defaults(func=cls._Execute) | 240 parser.set_defaults(func=cls._Execute) |
242 cls._Register(parser) | 241 cls._Register(parser) |
243 | 242 |
244 | 243 |
245 class CodeSignBundleAction(Action): | 244 class CodeSignBundleAction(Action): |
246 | |
247 """Class implementing the code-sign-bundle action.""" | 245 """Class implementing the code-sign-bundle action.""" |
248 | 246 |
249 name = 'code-sign-bundle' | 247 name = 'code-sign-bundle' |
250 help = 'perform code signature for a bundle' | 248 help = 'perform code signature for a bundle' |
251 | 249 |
252 @staticmethod | 250 @staticmethod |
253 def _Register(parser): | 251 def _Register(parser): |
254 parser.add_argument( | 252 parser.add_argument( |
255 '--entitlements', '-e', dest='entitlements_path', | 253 '--entitlements', '-e', dest='entitlements_path', |
256 help='path to the entitlements file to use') | 254 help='path to the entitlements file to use') |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 codesign_extra_args.extend( | 312 codesign_extra_args.extend( |
315 ['--entitlements', temporary_entitlements_file.name]) | 313 ['--entitlements', temporary_entitlements_file.name]) |
316 | 314 |
317 entitlements = GenerateEntitlements( | 315 entitlements = GenerateEntitlements( |
318 args.entitlements_path, provisioning_profile, bundle.identifier) | 316 args.entitlements_path, provisioning_profile, bundle.identifier) |
319 entitlements.WriteTo(temporary_entitlements_file.name) | 317 entitlements.WriteTo(temporary_entitlements_file.name) |
320 | 318 |
321 CodeSignBundle(bundle.path, args.identity, codesign_extra_args) | 319 CodeSignBundle(bundle.path, args.identity, codesign_extra_args) |
322 | 320 |
323 | 321 |
| 322 class CodeSignFileAction(Action): |
| 323 """Class implementing code signature for a single file.""" |
| 324 |
| 325 name = 'code-sign-file' |
| 326 help = 'code-sign a single file' |
| 327 |
| 328 @staticmethod |
| 329 def _Register(parser): |
| 330 parser.add_argument( |
| 331 'path', help='path to the file to codesign') |
| 332 parser.add_argument( |
| 333 '--identity', '-i', required=True, |
| 334 help='identity to use to codesign') |
| 335 parser.add_argument( |
| 336 '--output', '-o', |
| 337 help='if specified copy the file to that location before signing it') |
| 338 parser.set_defaults(sign=True) |
| 339 |
| 340 @staticmethod |
| 341 def _Execute(args): |
| 342 if not args.identity: |
| 343 args.identity = '-' |
| 344 |
| 345 install_path = args.path |
| 346 if args.output: |
| 347 |
| 348 if os.path.isfile(args.output): |
| 349 os.unlink(args.output) |
| 350 elif os.path.isdir(args.output): |
| 351 shutil.rmtree(args.output) |
| 352 |
| 353 if os.path.isfile(args.path): |
| 354 shutil.copy(args.path, args.output) |
| 355 elif os.path.isdir(args.path): |
| 356 shutil.copytree(args.path, args.output) |
| 357 |
| 358 install_path = args.output |
| 359 |
| 360 CodeSignBundle(install_path, args.identity, |
| 361 ['--deep', '--preserve-metadata=identifier,entitlements']) |
| 362 |
| 363 |
324 class GenerateEntitlementsAction(Action): | 364 class GenerateEntitlementsAction(Action): |
325 | |
326 """Class implementing the generate-entitlements action.""" | 365 """Class implementing the generate-entitlements action.""" |
327 | 366 |
328 name = 'generate-entitlements' | 367 name = 'generate-entitlements' |
329 help = 'generate entitlements file' | 368 help = 'generate entitlements file' |
330 | 369 |
331 @staticmethod | 370 @staticmethod |
332 def _Register(parser): | 371 def _Register(parser): |
333 parser.add_argument( | 372 parser.add_argument( |
334 '--entitlements', '-e', dest='entitlements_path', | 373 '--entitlements', '-e', dest='entitlements_path', |
335 help='path to the entitlements file to use') | 374 help='path to the entitlements file to use') |
(...skipping 10 matching lines...) Expand all Loading... |
346 provisioning_profile = FindProvisioningProfile(bundle_identifier, False) | 385 provisioning_profile = FindProvisioningProfile(bundle_identifier, False) |
347 entitlements = GenerateEntitlements( | 386 entitlements = GenerateEntitlements( |
348 args.entitlements_path, provisioning_profile, bundle_identifier) | 387 args.entitlements_path, provisioning_profile, bundle_identifier) |
349 entitlements.WriteTo(args.path) | 388 entitlements.WriteTo(args.path) |
350 | 389 |
351 | 390 |
352 def Main(): | 391 def Main(): |
353 parser = argparse.ArgumentParser('codesign iOS bundles') | 392 parser = argparse.ArgumentParser('codesign iOS bundles') |
354 subparsers = parser.add_subparsers() | 393 subparsers = parser.add_subparsers() |
355 | 394 |
356 for action in [ CodeSignBundleAction, GenerateEntitlementsAction ]: | 395 actions = [ |
| 396 CodeSignBundleAction, |
| 397 CodeSignFileAction, |
| 398 GenerateEntitlementsAction, |
| 399 ] |
| 400 |
| 401 for action in actions: |
357 action.Register(subparsers) | 402 action.Register(subparsers) |
358 | 403 |
359 args = parser.parse_args() | 404 args = parser.parse_args() |
360 args.func(args) | 405 args.func(args) |
361 | 406 |
362 | 407 |
363 if __name__ == '__main__': | 408 if __name__ == '__main__': |
364 sys.exit(Main()) | 409 sys.exit(Main()) |
OLD | NEW |