Flutter Engine
The Flutter Engine
dart_codesign.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
4# for details. All rights reserved. Use of this source code is governed by a
5# BSD-style license that can be found in the LICENSE file.
6#
7# Sign given binaries with using the specified signing identity and
8# using entitlements from runtime/tools/entitlement/${binary_name}.plist
9# if any.
10#
11
12import optparse
13import os
14import subprocess
15
16SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
17
18
19def SignBinary(identity, binary):
20 codesign_args = [
21 "--deep", "--force", "--verify", "--verbose", "--timestamp",
22 "--options", "runtime", "--sign", identity
23 ]
24
25 name = os.path.basename(binary)
26
27 # Check if we have a matching entitlements file and apply it.
28 # It would be simpler if we could specify it from outside but
29 # GN does not give us tools for doing that: executable target can't
30 # push arbitrary configuration down to the link tool where
31 # we would like to perform code signing.
32 entitlements_file = os.path.join(SCRIPT_DIR, "entitlements",
33 name + ".plist")
34 if os.path.exists(entitlements_file):
35 codesign_args += ["--entitlements", entitlements_file]
36 cmd = ["codesign"] + codesign_args + [binary]
37 result = subprocess.run(cmd, capture_output=True, encoding="utf8")
38 if result.returncode != 0:
39 print("failed to run: " + " ".join(cmd))
40 print(f"exit code: {result.returncode}")
41 print("stdout:")
42 print(result.stdout)
43 print("stdout:")
44 print(result.stderr)
45 raise Exception("failed to codesign")
46
47
48parser = optparse.OptionParser()
49parser.add_option("--identity", type="string", help="Code signing identity")
50parser.add_option("--binary",
51 type="string",
52 action="append",
53 help="Binary to sign")
54options = parser.parse_args()[0]
55
56if not options.identity:
57 raise Exception("Missing code signing identity (--identity)")
58
59if not options.binary:
60 raise Exception("Missing binaries to sign (--binary)")
61
62for binary in options.binary:
63 SignBinary(options.identity, binary)
def SignBinary(identity, binary)
def print(*args, **kwargs)
Definition: run_tests.py:49
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741