blob: ee8ab46b887089fecd090e5595b9279ca0ec0368 [file] [log] [blame]
Mike Klein6d3b7aa2017-01-30 14:00:54 -05001#!/usr/bin/env python2.7
2#
3# Copyright 2017 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8import os
9import re
10import shutil
11import subprocess
12import sys
13import tempfile
14
15# Arguments to the script:
16# app path to binary to package, e.g. out/Debug/dm
17# identity code signing identity, a long hex string
18# (run security find-identity -v -p codesigning | grep Google)
19# mobileprovision path to Google_Development.mobileprovision
20app, identity, mobileprovision = sys.argv[1:]
21
22out, app = os.path.split(app)
23
24pkg = os.path.join(out, app + '.app')
25if not os.path.exists(pkg):
26 os.mkdir(pkg)
27
28# The binary and .mobileprovision just get copied into the package.
29shutil.copy(os.path.join(out, app), pkg)
30shutil.copy(mobileprovision,
31 os.path.join(pkg, 'embedded.mobileprovision'))
32
33# Write a minimal Info.plist to name the package and point at the binary.
34with open(os.path.join(pkg, 'Info.plist'), 'w') as f:
35 f.write('''
36<plist version="1.0">
37 <dict>
38 <key>CFBundleExecutable</key> <string>{app}</string>
39 <key>CFBundleIdentifier</key> <string>com.google.{app}</string>
40 </dict>
41</plist>
42'''.format(app=app))
43
44# Extract the appliciation identitifer prefix from the .mobileprovision.
45m = re.search(r'''<key>ApplicationIdentifierPrefix</key>
46\t<array>
47\t<string>(.*)</string>''', open(mobileprovision).read(), re.MULTILINE)
48prefix = m.group(1)
49
50# Write a minimal entitlements file, then codesign.
51with tempfile.NamedTemporaryFile() as f:
52 f.write('''
53<plist version="1.0">
54 <dict>
55 <key>application-identifier</key> <string>{prefix}.com.google.{app}</string>
56 <key>get-task-allow</key> <true/>
57 </dict>
58</plist>
59'''.format(prefix=prefix, app=app))
60 f.flush()
61
62 subprocess.check_call(['codesign',
63 '--force',
64 '--sign', identity,
65 '--entitlements', f.name,
66 '--timestamp=none',
67 pkg])