Transfer the Mac SDK bockbuild profiles & resources inside the Mono repository.
[mono.git] / bockbuild / mac-sdk-xamarin / profile.py
1 #!/usr/bin/python -u -OO
2
3 import itertools
4 import os
5 import re
6 import shutil
7 import string
8 import sys
9 import tempfile
10 import traceback
11
12 from glob import glob
13
14 if __name__ == "__main__":
15     sys.path.append(os.path.realpath('../..'))
16     sys.path.append(os.path.realpath('../../packages'))
17     sys.path.append(os.path.realpath('../mono-mac'))
18
19 from MonoReleaseProfile import MonoReleaseProfile
20 from bockbuild.util.util import *
21
22
23 class MonoXamarinPackageProfile(MonoReleaseProfile):
24
25     def __init__(self):
26         MonoReleaseProfile.__init__(self)
27
28         # add the private stuff
29         self.packages_to_build.extend(['mono-extensions'])
30
31         if self.cmd_options.release_build:
32             self.setup_codesign()
33         else:
34             info("'--release' option not set, will not attempt to sign package!")
35
36         self.cache_host = 'http://storage.bos.xamarin.com/bockbuild_cache/'
37
38     def setup_codesign(self):
39         self.identity = "Developer ID Installer: Xamarin Inc"
40
41         output = backtick("security -v find-identity")
42         if self.identity not in " ".join(output):
43             error("Identity '%s' was not found. You can create an unsigned package by removing '--release' to your command line." % self.identity)
44
45         password = os.getenv("CODESIGN_KEYCHAIN_PASSWORD")
46         if password:
47             print "Unlocking the keychain"
48             run_shell("security unlock-keychain -p %s" % password)
49         else:
50             error("CODESIGN_KEYCHAIN_PASSWORD needs to be defined.")
51
52     def setup_release(self):
53         MonoReleaseProfile.setup_release(self)
54         self.release_packages['mono'].configure_flags.extend(
55             ['--enable-extension-module=xamarin --enable-native-types --enable-pecrypt'])
56         info('Xamarin extensions enabled')
57
58     def run_pkgbuild(self, working_dir, package_type):
59         output = MonoReleaseProfile.run_pkgbuild(
60             self, working_dir, package_type)
61
62         output_unsigned = os.path.join(os.path.dirname(
63             output), os.path.basename(output).replace('.pkg', '.UNSIGNED.pkg'))
64         shutil.move(output, output_unsigned)
65
66         if not self.cmd_options.release_build:
67             return output_unsigned
68
69         productsign = "/usr/bin/productsign"
70         productsign_cmd = ' '.join([productsign,
71                                     "-s '%s'" % self.identity,
72                                     "'%s'" % output_unsigned,
73                                     "'%s'" % output])
74         run_shell(productsign_cmd)
75         os.remove(output_unsigned)
76         self.verify_codesign(output)
77
78         return output
79
80     def verify_codesign(self, pkg):
81         oldcwd = os.getcwd()
82         try:
83             name = os.path.basename(pkg)
84             pkgdir = os.path.dirname(pkg)
85             os.chdir(pkgdir)
86             spctl = "/usr/sbin/spctl"
87             spctl_cmd = ' '.join(
88                 [spctl, "-vvv", "--assess", "--type install", name, "2>&1"])
89             output = backtick(spctl_cmd)
90
91             if "accepted" in " ".join(output):
92                 warn("%s IS SIGNED" % pkg)
93             else:
94                 error("%s IS NOT SIGNED:" % pkg)
95         finally:
96             os.chdir(oldcwd)
97
98 if __name__ == "__main__":
99     try:
100         MonoXamarinPackageProfile().build()
101     except Exception as e:
102         exc_type, exc_value, exc_traceback = sys.exc_info()
103         error('%s (%s)' % (e, exc_type.__name__), more_output=True)
104         error(('%s:%s @%s\t\t"%s"' % p for p in traceback.extract_tb(
105             exc_traceback)[-3:]), more_output=True)
106     except KeyboardInterrupt:
107         error('Interrupted.')