OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 Google Inc. All rights reserved. | 2 # Copyright (c) 2012 Google Inc. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Utility functions to perform Xcode-style build steps. | 6 """Utility functions to perform Xcode-style build steps. |
7 | 7 |
8 These functions are executed via gyp-mac-tool when using the Makefile generator. | 8 These functions are executed via gyp-mac-tool when using the Makefile generator. |
9 """ | 9 """ |
10 | 10 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 subprocess.check_call(command_line) | 343 subprocess.check_call(command_line) |
344 | 344 |
345 def ExecMergeInfoPlist(self, output, *inputs): | 345 def ExecMergeInfoPlist(self, output, *inputs): |
346 """Merge multiple .plist files into a single .plist file.""" | 346 """Merge multiple .plist files into a single .plist file.""" |
347 merged_plist = {} | 347 merged_plist = {} |
348 for path in inputs: | 348 for path in inputs: |
349 plist = self._LoadPlistMaybeBinary(path) | 349 plist = self._LoadPlistMaybeBinary(path) |
350 self._MergePlist(merged_plist, plist) | 350 self._MergePlist(merged_plist, plist) |
351 plistlib.writePlist(merged_plist, output) | 351 plistlib.writePlist(merged_plist, output) |
352 | 352 |
353 def ExecCodeSignBundle(self, key, resource_rules, entitlements, provisioning): | 353 def ExecCodeSignBundle(self, key, entitlements, provisioning): |
354 """Code sign a bundle. | 354 """Code sign a bundle. |
355 | 355 |
356 This function tries to code sign an iOS bundle, following the same | 356 This function tries to code sign an iOS bundle, following the same |
357 algorithm as Xcode: | 357 algorithm as Xcode: |
358 1. copy ResourceRules.plist from the user or the SDK into the bundle, | 358 1. pick the provisioning profile that best match the bundle identifier, |
359 2. pick the provisioning profile that best match the bundle identifier, | |
360 and copy it into the bundle as embedded.mobileprovision, | 359 and copy it into the bundle as embedded.mobileprovision, |
361 3. copy Entitlements.plist from user or SDK next to the bundle, | 360 2. copy Entitlements.plist from user or SDK next to the bundle, |
362 4. code sign the bundle. | 361 3. code sign the bundle. |
363 """ | 362 """ |
364 resource_rules_path = self._InstallResourceRules(resource_rules) | |
365 substitutions, overrides = self._InstallProvisioningProfile( | 363 substitutions, overrides = self._InstallProvisioningProfile( |
366 provisioning, self._GetCFBundleIdentifier()) | 364 provisioning, self._GetCFBundleIdentifier()) |
367 entitlements_path = self._InstallEntitlements( | 365 entitlements_path = self._InstallEntitlements( |
368 entitlements, substitutions, overrides) | 366 entitlements, substitutions, overrides) |
369 subprocess.check_call([ | 367 subprocess.check_call([ |
370 'codesign', '--force', '--sign', key, '--resource-rules', | 368 'codesign', '--force', '--sign', key, '--entitlements', |
371 resource_rules_path, '--entitlements', entitlements_path, | 369 entitlements_path, os.path.join( |
372 os.path.join( | |
373 os.environ['TARGET_BUILD_DIR'], | 370 os.environ['TARGET_BUILD_DIR'], |
374 os.environ['FULL_PRODUCT_NAME'])]) | 371 os.environ['FULL_PRODUCT_NAME'])]) |
375 | 372 |
376 def _InstallResourceRules(self, resource_rules): | |
377 """Installs ResourceRules.plist from user or SDK into the bundle. | |
378 | |
379 Args: | |
380 resource_rules: string, optional, path to the ResourceRules.plist file | |
381 to use, default to "${SDKROOT}/ResourceRules.plist" | |
382 | |
383 Returns: | |
384 Path to the copy of ResourceRules.plist into the bundle. | |
385 """ | |
386 source_path = resource_rules | |
387 target_path = os.path.join( | |
388 os.environ['BUILT_PRODUCTS_DIR'], | |
389 os.environ['CONTENTS_FOLDER_PATH'], | |
390 'ResourceRules.plist') | |
391 if not source_path: | |
392 source_path = os.path.join( | |
393 os.environ['SDKROOT'], 'ResourceRules.plist') | |
394 shutil.copy2(source_path, target_path) | |
395 return target_path | |
396 | |
397 def _InstallProvisioningProfile(self, profile, bundle_identifier): | 373 def _InstallProvisioningProfile(self, profile, bundle_identifier): |
398 """Installs embedded.mobileprovision into the bundle. | 374 """Installs embedded.mobileprovision into the bundle. |
399 | 375 |
400 Args: | 376 Args: |
401 profile: string, optional, short name of the .mobileprovision file | 377 profile: string, optional, short name of the .mobileprovision file |
402 to use, if empty or the file is missing, the best file installed | 378 to use, if empty or the file is missing, the best file installed |
403 will be used | 379 will be used |
404 bundle_identifier: string, value of CFBundleIdentifier from Info.plist | 380 bundle_identifier: string, value of CFBundleIdentifier from Info.plist |
405 | 381 |
406 Returns: | 382 Returns: |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 data = data.replace('$(%s)' % key, value) | 578 data = data.replace('$(%s)' % key, value) |
603 return data | 579 return data |
604 if isinstance(data, list): | 580 if isinstance(data, list): |
605 return [self._ExpandVariables(v, substitutions) for v in data] | 581 return [self._ExpandVariables(v, substitutions) for v in data] |
606 if isinstance(data, dict): | 582 if isinstance(data, dict): |
607 return {k: self._ExpandVariables(data[k], substitutions) for k in data} | 583 return {k: self._ExpandVariables(data[k], substitutions) for k in data} |
608 return data | 584 return data |
609 | 585 |
610 if __name__ == '__main__': | 586 if __name__ == '__main__': |
611 sys.exit(main(sys.argv[1:])) | 587 sys.exit(main(sys.argv[1:])) |
OLD | NEW |