blob: f89656e8838bf69ad0ae73456b0356d4209311de [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 re
import shutil
import subprocess
import sys
import tempfile
# Arguments to the script:
# app path to binary to package, e.g. out/Debug/dm
app, = 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'''.*\) (.*) ".*Google.*"''', line)
if m:
identity =
assert identity
# Find the Google mobile provisioning profile.
mobileprovision = None
for p in glob.glob(os.path.join(os.environ['HOME'], 'Library', 'MobileDevice',
'Provisioning Profiles', '*.mobileprovision')):
\t<string>Google Development</string>''', open(p).read(), re.MULTILINE):
mobileprovision = p
assert mobileprovision
out, app = os.path.split(app)
pkg = os.path.join(out, app + '.app')
if not os.path.exists(pkg):
# The binary and .mobileprovision just get copied into the package.
shutil.copy(os.path.join(out, app), pkg)
os.path.join(pkg, 'embedded.mobileprovision'))
# Write a minimal Info.plist to name the package and point at the binary.
with open(os.path.join(pkg, 'Info.plist'), 'w') as f:
<plist version="1.0">
<key>CFBundleExecutable</key> <string>{app}</string>
<key>CFBundleIdentifier</key> <string>{app}</string>
# Extract the appliciation identitifer prefix from the .mobileprovision.
m ='''<key>ApplicationIdentifierPrefix</key>
\t<string>(.*)</string>''', open(mobileprovision).read(), re.MULTILINE)
prefix =
# 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,