blob: 841daa53675d143b58149a66755263a182f982d7 [file] [log] [blame]
#!/usr/bin/env python2.7
# Copyright 2017 Google Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import glob
import os
import os.path
import re
import shutil
import subprocess
import sys
import tempfile
# Arguments to the script:
# pkg path to application directory, e.g. out/Debug/
# executable and plist should already be in this directory
# identstr search string (regex fragment) for code signing identity
# profile path or name of provisioning profile
pkg,identstr,profile = sys.argv[1:]
# Find the Google signing identity.
identity = None
for line in subprocess.check_output(['security', 'find-identity']).split('\n'):
m = re.match(r'''.*\) (.*) "''' + identstr + '"', line)
if m:
identity =
assert identity
# Find the Google mobile provisioning profile.
mobileprovision = None
if os.path.isfile(profile):
mobileprovision = profile
for p in glob.glob(os.path.join(os.environ['HOME'], 'Library', 'MobileDevice',
'Provisioning Profiles',
\t<string>''' + profile + r'''</string>''', open(p).read(), re.MULTILINE):
mobileprovision = p
assert mobileprovision
# The .mobileprovision just gets copied into the package.
os.path.join(pkg, 'embedded.mobileprovision'))
# Extract the appliciation identitifer prefix from the .mobileprovision.
m ='''<key>ApplicationIdentifierPrefix</key>
\t<string>(.*)</string>''', open(mobileprovision).read(), re.MULTILINE)
prefix =
app, _ = os.path.splitext(os.path.basename(pkg))
# Write a minimal entitlements file, then codesign.
with tempfile.NamedTemporaryFile() as f:
<plist version="1.0">
<key>application-identifier</key> <string>{prefix}{app}</string>
<key>get-task-allow</key> <true/>
'''.format(prefix=prefix, app=app))
'--sign', identity,