|
| 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 | +buildroot_dir = os.path.abspath( |
| 14 | + os.path.join(os.path.realpath(__file__), '..', '..', '..', '..') |
| 15 | +) |
| 16 | + |
| 17 | +DSYMUTIL = os.path.join( |
| 18 | + os.path.dirname(__file__), '..', '..', '..', 'buildtools', 'mac-x64', |
| 19 | + 'clang', 'bin', 'dsymutil' |
| 20 | +) |
| 21 | + |
| 22 | +out_dir = os.path.join(buildroot_dir, 'out') |
| 23 | + |
| 24 | + |
| 25 | +def main(): |
| 26 | + parser = argparse.ArgumentParser( |
| 27 | + description='Creates FlutterEmbedder.framework for macOS' |
| 28 | + ) |
| 29 | + |
| 30 | + parser.add_argument('--dst', type=str, required=True) |
| 31 | + parser.add_argument('--arm64-out-dir', type=str, required=True) |
| 32 | + parser.add_argument('--x64-out-dir', type=str, required=True) |
| 33 | + parser.add_argument('--strip', action='store_true', default=False) |
| 34 | + parser.add_argument('--dsym', action='store_true', default=False) |
| 35 | + # TODO(godofredoc): Remove after recipes v2 have landed. |
| 36 | + parser.add_argument('--zip', action='store_true', default=False) |
| 37 | + |
| 38 | + args = parser.parse_args() |
| 39 | + |
| 40 | + dst = ( |
| 41 | + args.dst |
| 42 | + if os.path.isabs(args.dst) else os.path.join(buildroot_dir, args.dst) |
| 43 | + ) |
| 44 | + arm64_out_dir = ( |
| 45 | + args.arm64_out_dir if os.path.isabs(args.arm64_out_dir) else |
| 46 | + os.path.join(buildroot_dir, args.arm64_out_dir) |
| 47 | + ) |
| 48 | + x64_out_dir = ( |
| 49 | + args.x64_out_dir if os.path.isabs(args.x64_out_dir) else |
| 50 | + os.path.join(buildroot_dir, args.x64_out_dir) |
| 51 | + ) |
| 52 | + |
| 53 | + fat_framework = os.path.join(dst, 'FlutterEmbedder.framework') |
| 54 | + arm64_framework = os.path.join(arm64_out_dir, 'FlutterEmbedder.framework') |
| 55 | + x64_framework = os.path.join(x64_out_dir, 'FlutterEmbedder.framework') |
| 56 | + |
| 57 | + arm64_dylib = os.path.join(arm64_framework, 'FlutterEmbedder') |
| 58 | + x64_dylib = os.path.join(x64_framework, 'FlutterEmbedder') |
| 59 | + |
| 60 | + if not os.path.isdir(arm64_framework): |
| 61 | + print('Cannot find macOS arm64 Framework at %s' % arm64_framework) |
| 62 | + return 1 |
| 63 | + |
| 64 | + if not os.path.isdir(x64_framework): |
| 65 | + print('Cannot find macOS x64 Framework at %s' % x64_framework) |
| 66 | + return 1 |
| 67 | + |
| 68 | + if not os.path.isfile(arm64_dylib): |
| 69 | + print('Cannot find macOS arm64 dylib at %s' % arm64_dylib) |
| 70 | + return 1 |
| 71 | + |
| 72 | + if not os.path.isfile(x64_dylib): |
| 73 | + print('Cannot find macOS x64 dylib at %s' % x64_dylib) |
| 74 | + return 1 |
| 75 | + |
| 76 | + if not os.path.isfile(DSYMUTIL): |
| 77 | + print('Cannot find dsymutil at %s' % DSYMUTIL) |
| 78 | + return 1 |
| 79 | + |
| 80 | + shutil.rmtree(fat_framework, True) |
| 81 | + shutil.copytree(arm64_framework, fat_framework, symlinks=True) |
| 82 | + regenerate_symlinks(fat_framework) |
| 83 | + |
| 84 | + fat_framework_binary = os.path.join( |
| 85 | + fat_framework, 'Versions', 'A', 'FlutterEmbedder' |
| 86 | + ) |
| 87 | + |
| 88 | + # Create the arm64/x64 fat framework. |
| 89 | + subprocess.check_call([ |
| 90 | + 'lipo', arm64_dylib, x64_dylib, '-create', '-output', fat_framework_binary |
| 91 | + ]) |
| 92 | + process_framework(dst, args, fat_framework, fat_framework_binary) |
| 93 | + |
| 94 | + return 0 |
| 95 | + |
| 96 | + |
| 97 | +def regenerate_symlinks(fat_framework): |
| 98 | + """Regenerates the symlinks structure. |
| 99 | +
|
| 100 | + Recipes V2 upload artifacts in CAS before integration and CAS follows symlinks. |
| 101 | + This logic regenerates the symlinks in the expected structure. |
| 102 | + """ |
| 103 | + if os.path.islink(os.path.join(fat_framework, 'FlutterEmbedder')): |
| 104 | + return |
| 105 | + os.remove(os.path.join(fat_framework, 'FlutterEmbedder')) |
| 106 | + shutil.rmtree(os.path.join(fat_framework, 'Headers'), True) |
| 107 | + shutil.rmtree(os.path.join(fat_framework, 'Modules'), True) |
| 108 | + shutil.rmtree(os.path.join(fat_framework, 'Resources'), True) |
| 109 | + current_version_path = os.path.join(fat_framework, 'Versions', 'Current') |
| 110 | + shutil.rmtree(current_version_path, True) |
| 111 | + os.symlink('A', current_version_path) |
| 112 | + os.symlink( |
| 113 | + os.path.join('Versions', 'Current', 'FlutterEmbedder'), |
| 114 | + os.path.join(fat_framework, 'FlutterEmbedder') |
| 115 | + ) |
| 116 | + os.symlink( |
| 117 | + os.path.join('Versions', 'Current', 'Headers'), |
| 118 | + os.path.join(fat_framework, 'Headers') |
| 119 | + ) |
| 120 | + os.symlink( |
| 121 | + os.path.join('Versions', 'Current', 'Modules'), |
| 122 | + os.path.join(fat_framework, 'Modules') |
| 123 | + ) |
| 124 | + os.symlink( |
| 125 | + os.path.join('Versions', 'Current', 'Resources'), |
| 126 | + os.path.join(fat_framework, 'Resources') |
| 127 | + ) |
| 128 | + |
| 129 | + |
| 130 | +def process_framework(dst, args, fat_framework, fat_framework_binary): |
| 131 | + if args.dsym: |
| 132 | + dsym_out = os.path.splitext(fat_framework)[0] + '.dSYM' |
| 133 | + subprocess.check_call([DSYMUTIL, '-o', dsym_out, fat_framework_binary]) |
| 134 | + if args.zip: |
| 135 | + dsym_dst = os.path.join(dst, 'FlutterEmbedder.dSYM') |
| 136 | + subprocess.check_call([ |
| 137 | + 'zip', '-r', '-y', 'FlutterEmbedder.dSYM.zip', '.' |
| 138 | + ], |
| 139 | + cwd=dsym_dst) |
| 140 | + dsym_final_src_path = os.path.join(dsym_dst, 'FlutterEmbedder.dSYM.zip') |
| 141 | + dsym_final_dst_path = os.path.join(dst, 'FlutterEmbedder.dSYM.zip') |
| 142 | + shutil.move(dsym_final_src_path, dsym_final_dst_path) |
| 143 | + |
| 144 | + if args.strip: |
| 145 | + # copy unstripped |
| 146 | + unstripped_out = os.path.join(dst, 'FlutterEmbedder.unstripped') |
| 147 | + shutil.copyfile(fat_framework_binary, unstripped_out) |
| 148 | + subprocess.check_call(['strip', '-x', '-S', fat_framework_binary]) |
| 149 | + |
| 150 | + # Zip FlutterEmbedder.framework. |
| 151 | + if args.zip: |
| 152 | + framework_dst = os.path.join(dst, 'FlutterEmbedder.framework') |
| 153 | + subprocess.check_call([ |
| 154 | + 'zip', |
| 155 | + '-r', |
| 156 | + '-y', |
| 157 | + 'FlutterEmbedder.framework.zip', |
| 158 | + '.', |
| 159 | + ], |
| 160 | + cwd=framework_dst) |
| 161 | + final_src_path = os.path.join( |
| 162 | + framework_dst, 'FlutterEmbedder.framework.zip' |
| 163 | + ) |
| 164 | + final_dst_path = os.path.join(dst, 'FlutterEmbedder.framework.zip') |
| 165 | + shutil.move(final_src_path, final_dst_path) |
| 166 | + |
| 167 | + |
| 168 | +if __name__ == '__main__': |
| 169 | + sys.exit(main()) |
0 commit comments