Fix eglib targets and filters.
[mono.git] / packaging / MacSDKRelease / profile.py
1 import itertools
2 import os
3 import re
4 import shutil
5 import string
6 import sys
7 import tempfile
8 import traceback
9
10 from glob import glob
11
12 from MacSDK import profile
13 from bockbuild.util.util import *
14
15
16 class MonoXamarinPackageProfile(MonoReleaseProfile):
17     description = 'The Mono Framework for MacOS (official release)'
18
19     def setup (self):
20         MonoReleaseProfile.setup (self)
21         bockbuild.packages_to_build.extend(['mono-extensions'])
22         if bockbuild.cmd_options.release_build:
23             self.setup_codesign()
24         else:
25             info("'--release' option not set, will not attempt to sign package!")
26
27         self.cache_host = 'http://xamarin-storage/bockbuild_cache/'
28
29     def setup_codesign(self):
30         self.identity = "Developer ID Installer: Xamarin Inc"
31
32         output = backtick("security -v find-identity")
33         if self.identity not in " ".join(output):
34             error("Identity '%s' was not found. You can create an unsigned package by removing '--release' to your command line." % self.identity)
35
36         password = os.getenv("CODESIGN_KEYCHAIN_PASSWORD")
37         if password:
38             print "Unlocking the keychain"
39             run_shell("security unlock-keychain -p %s" % password)
40         else:
41             error("CODESIGN_KEYCHAIN_PASSWORD needs to be defined.")
42
43     def setup_release(self):
44         MonoReleaseProfile.setup_release(self)
45         self.release_packages['mono'].configure_flags.extend(
46             ['--enable-extension-module=xamarin --enable-native-types --enable-pecrypt'])
47         info('Xamarin extensions enabled')
48
49     def run_pkgbuild(self, working_dir, package_type):
50         output = MonoReleaseProfile.run_pkgbuild(
51             self, working_dir, package_type)
52
53         output_unsigned = os.path.join(os.path.dirname(
54             output), os.path.basename(output).replace('.pkg', '.UNSIGNED.pkg'))
55         shutil.move(output, output_unsigned)
56
57         if not bockbuild.cmd_options.release_build:
58             return output_unsigned
59
60         productsign = "/usr/bin/productsign"
61         productsign_cmd = ' '.join([productsign,
62                                     "-s '%s'" % self.identity,
63                                     "'%s'" % output_unsigned,
64                                     "'%s'" % output])
65         run_shell(productsign_cmd)
66         os.remove(output_unsigned)
67         self.verify_codesign(output)
68
69         return output
70
71     def verify_codesign(self, pkg):
72         oldcwd = os.getcwd()
73         try:
74             name = os.path.basename(pkg)
75             pkgdir = os.path.dirname(pkg)
76             os.chdir(pkgdir)
77             spctl = "/usr/sbin/spctl"
78             spctl_cmd = ' '.join(
79                 [spctl, "-vvv", "--assess", "--type install", name, "2>&1"])
80             output = backtick(spctl_cmd)
81
82             if "accepted" in " ".join(output):
83                 warn("%s IS SIGNED" % pkg)
84             else:
85                 error("%s IS NOT SIGNED:" % pkg)
86         finally:
87             os.chdir(oldcwd)
88
89 MonoXamarinPackageProfile()