|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Copyright 2013 The Flutter Authors. All rights reserved. |
| 4 | +# Use of this source code is governed by a BSD-style license that can be |
| 5 | +# found in the LICENSE file. |
| 6 | + |
| 7 | +import argparse |
| 8 | +import subprocess |
| 9 | +import shutil |
| 10 | +import sys |
| 11 | +import os |
| 12 | + |
| 13 | +from create_xcframework import create_xcframework |
| 14 | + |
| 15 | +DSYMUTIL = os.path.join(os.path.dirname(__file__), '..', '..', '..', |
| 16 | + 'buildtools', 'mac-x64', 'clang', 'bin', 'dsymutil') |
| 17 | + |
| 18 | +def main(): |
| 19 | + parser = argparse.ArgumentParser(description='Creates FlutterMacOS.framework for macOS') |
| 20 | + |
| 21 | + parser.add_argument('--dst', type=str, required=True) |
| 22 | + parser.add_argument('--arm64-out-dir', type=str, required=True) |
| 23 | + parser.add_argument('--x64-out-dir', type=str, required=True) |
| 24 | + parser.add_argument('--strip', action="store_true", default=False) |
| 25 | + parser.add_argument('--dsym', action="store_true", default=False) |
| 26 | + |
| 27 | + args = parser.parse_args() |
| 28 | + |
| 29 | + fat_framework = os.path.join(args.dst, 'FlutterMacOS.framework') |
| 30 | + arm64_framework = os.path.join(args.arm64_out_dir, 'FlutterMacOS.framework') |
| 31 | + x64_framework = os.path.join(args.x64_out_dir, 'FlutterMacOS.framework') |
| 32 | + |
| 33 | + arm64_dylib = os.path.join(arm64_framework, 'FlutterMacOS') |
| 34 | + x64_dylib = os.path.join(x64_framework, 'FlutterMacOS') |
| 35 | + |
| 36 | + if not os.path.isdir(arm64_framework): |
| 37 | + print('Cannot find macOS arm64 Framework at %s' % arm64_framework) |
| 38 | + return 1 |
| 39 | + |
| 40 | + if not os.path.isdir(x64_framework): |
| 41 | + print('Cannot find macOS x64 Framework at %s' % x64_framework) |
| 42 | + return 1 |
| 43 | + |
| 44 | + if not os.path.isfile(arm64_dylib): |
| 45 | + print('Cannot find macOS arm64 dylib at %s' % arm64_dylib) |
| 46 | + return 1 |
| 47 | + |
| 48 | + if not os.path.isfile(x64_dylib): |
| 49 | + print('Cannot find macOS x64 dylib at %s' % x64_dylib) |
| 50 | + return 1 |
| 51 | + |
| 52 | + if not os.path.isfile(DSYMUTIL): |
| 53 | + print('Cannot find dsymutil at %s' % DSYMUTIL) |
| 54 | + return 1 |
| 55 | + |
| 56 | + shutil.rmtree(fat_framework, True) |
| 57 | + shutil.copytree(arm64_framework, fat_framework, symlinks=True) |
| 58 | + |
| 59 | + fat_framework_binary = os.path.join(fat_framework, 'Versions', 'A', 'FlutterMacOS') |
| 60 | + |
| 61 | + # Create the arm64/x64 fat framework. |
| 62 | + subprocess.check_call([ |
| 63 | + 'lipo', |
| 64 | + arm64_dylib, |
| 65 | + x64_dylib, |
| 66 | + '-create', |
| 67 | + '-output', |
| 68 | + fat_framework_binary |
| 69 | + ]) |
| 70 | + process_framework(args, fat_framework, fat_framework_binary) |
| 71 | + |
| 72 | + |
| 73 | +def process_framework(args, fat_framework, fat_framework_binary): |
| 74 | + if args.dsym: |
| 75 | + dsym_out = os.path.splitext(fat_framework)[0] + '.dSYM' |
| 76 | + subprocess.check_call([DSYMUTIL, '-o', dsym_out, fat_framework_binary]) |
| 77 | + |
| 78 | + if args.strip: |
| 79 | + # copy unstripped |
| 80 | + unstripped_out = os.path.join(args.dst, 'FlutterMacOS.unstripped') |
| 81 | + shutil.copyfile(fat_framework_binary, unstripped_out) |
| 82 | + |
| 83 | + subprocess.check_call(["strip", "-x", "-S", fat_framework_binary]) |
| 84 | + |
| 85 | + |
| 86 | +if __name__ == '__main__': |
| 87 | + sys.exit(main()) |
0 commit comments