├── LICENSE.txt ├── README.md ├── bump_buildnum.py └── copy_dylibs.py /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xcode Development Tools 2 | 3 | A small collection of scripts I have developed to make working with Xcode easier. 4 | 5 | ## copy_dylibs.py 6 | `copy_dylibs.py` is used to detect and copy local library dependencies into your app bundle. 7 | 8 | A local dependency is a dynamic library that you will have built yourself or installed using a package management tool like homebrew or MacPorts. They won't exist on the end-user system and therefore your app won't run on their system if you have used them (there is also a good chance they won't run on your system either until they are copied into the app bundle and code-signed). 9 | 10 | Any library dependency that resides outside of `/System` or `/usr/lib` is deemed a local library dependency. 11 | 12 | The script works by examining the main executable and looking for local library dependencies and then copying them into the app bundle `Frameworks` folder. Any local library dependencies copied are themselves examined to see if they use any other local library dependencies, ad infinitum. 13 | 14 | When a local library dependency is copied into the app bundle, its "install name" is adjusted in both the executable/dynamic library that references it and within the library dependency itself. The script changes the "install name" to use [`@rpath`](https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html) instead of an absolute path. 15 | 16 | Xcode will provide all the information the script needs, via environment variables, however additional local library dependencies can be specifed on the command line. This is useful for libraries that are loaded via `dlopen()` and therefore cannot be detected by the script. 17 | 18 | 19 | ### Notes on fat binary dependencies 20 | `copy_dylibs.py` will fail on fat binary dependencies that have not had their _install name_ fixed when they were created. 21 | 22 | Here's an example: 23 | 24 | An external build system was used to create two libraries for use with the iOS Simulator, one arm64 and the other x86_64. These were building into different output directories: 25 | 26 | ``` 27 | extlib/arm64/libfoo.dylib 28 | extlib/x86_64/libfoo.dylib 29 | ``` 30 | 31 | and `lipo` was used to create the fat binary: 32 | 33 | ``` 34 | $ lipo -create -output extlib/fat/libfoo.dylib extlib/arm64/libfoo.dylib extlib/x86_64/libfoo.dylib 35 | ``` 36 | 37 | When you examine this library you will see that the original install names are preserved in the fat binary: 38 | 39 | ``` 40 | $ otool -L extlib/fat/libfoo.dylib 41 | 42 | extlib/fat/libfoo.dylib (architecture x86_64): 43 | extlib/x64_64/libfoo.dylib (compatibility version 0.0.0, current version 0.0.0) 44 | ... 45 | system libraries 46 | ... 47 | extlib/fat/libfoo.dylib (architecture arm64): 48 | extlib/arm64/libfoo.dylib (compatibility version 0.0.0, current version 0.0.0) 49 | ... 50 | system libraries 51 | ... 52 | ``` 53 | 54 | This will confuse `copy_dylibs.py` and it will end-up copying in one of the thin libraries into the Xcode build directory, overwriting the fat binary because it has the same name. 55 | 56 | The way to fix this is to use `install_name_tool` after `lipo`: 57 | 58 | ``` 59 | install_name_tool -id extlib/fat/libfoo.dylib extlib/fat/libfoo.dylib 60 | ``` 61 | 62 | ### Configuring 63 | In order to configure `copy_dylibs.py` into your Xcode project: 64 | 65 | - Add this repo as a submodule in a directory of your choosing, for example `External`, using `git submodule add https://github.com/trojanfoe/xcodedevtools External/xcodedevtools`. 66 | - Select the project settings of the **App Target** and in the *Build Phases* tab press the `+` top-left above *Target Dependencies* and select *New Run Script Phase*. Rename the script to *Copy Dylibs*. 67 | - In the new *Run Script* section put `python $PROJECT_DIR/External/xcodedevtools/copy_dylibs.py` in the top textbox, depending on where you added the submodule. 68 | - You should move *Copy Dylibs* so it runs after *Link Binary With Libraries* and before *Copy Bundle Resources* to avoid warning messages like `changes being made to the file will invalidate the code signature in ...`. 69 | 70 | 71 | ### Code Signing 72 | The script will code sign all `.dylib` files that it copies into the app bundle. 73 | 74 | Previously I was relying on adding `--deep` to the *Other Code Signing Flags*, however I have noticed that has no effect when running an app on an iOS device and the embedded frameworks remain unsigned. The `--deep` flag does work when running on the iOS Simulator or running a native macOS app, however to cover all cases I have put code signing back into the script. 75 | 76 | ## bump_buildnum.py 77 | `bump_buildnum.py` is used to manage build number versioning of your app bundle. 78 | 79 | It works by maintaining a `.ver` file in the source tree that is incremented whenever a source file change is detected during a build. The updated build number is then written into the `Info.plist` file to allow for automatic versioning. Only the build version is incremented, and the main version needs to be incremented manually, based on feature updates that only you know about. 80 | 81 | It is configured in a similar way to `copy_dylibs.py`. 82 | 83 | I don't use it any longer so don't have much more to say about it, however if you find it useful let me know and I'll put more effort into documenting it. 84 | -------------------------------------------------------------------------------- /bump_buildnum.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | # 5 | # Bump build number in Info.plist files if a source file have changed. 6 | # 7 | # usage: bump_buildnum.py buildnum.ver Info.plist [ ... Info.plist ] 8 | # 9 | # Copyright (c)2019 Andy Duplain 10 | # 11 | 12 | import sys, os, subprocess, re 13 | 14 | 15 | def read_verfile(name): 16 | version = None 17 | build = None 18 | verfile = open(name, "r") 19 | for line in verfile: 20 | match = re.match(r"^version\s+(\S+)", line) 21 | if match: 22 | version = match.group(1).rstrip() 23 | match = re.match(r"^build\s+(\S+)", line) 24 | if match: 25 | build = int(match.group(1).rstrip()) 26 | verfile.close() 27 | return (version, build) 28 | 29 | 30 | def write_verfile(name, version, build): 31 | verfile = open(name, "w") 32 | verfile.write("version {0}\n".format(version)) 33 | verfile.write("build {0}\n".format(build)) 34 | verfile.close() 35 | return True 36 | 37 | 38 | def set_plist_version(plistname, version, build): 39 | if not os.path.exists(plistname): 40 | print("{0} does not exist".format(plistname)) 41 | return False 42 | 43 | plistbuddy = "/usr/libexec/Plistbuddy" 44 | if not os.path.exists(plistbuddy): 45 | print("{0} does not exist".format(plistbuddy)) 46 | return False 47 | 48 | cmdline = [ 49 | plistbuddy, 50 | "-c", 51 | "Set CFBundleShortVersionString {0}".format(version), 52 | "-c", 53 | "Set CFBundleVersion {0}".format(build), 54 | plistname, 55 | ] 56 | if subprocess.call(cmdline) != 0: 57 | print("Failed to update {0}".format(plistname)) 58 | return False 59 | 60 | print("Updated {0} with v{1} ({2})".format(plistname, version, build)) 61 | return True 62 | 63 | 64 | def should_bump(vername, dirname): 65 | verstat = os.stat(vername) 66 | allnames = [] 67 | for dirname, dirnames, filenames in os.walk(dirname): 68 | for filename in filenames: 69 | allnames.append(os.path.join(dirname, filename)) 70 | 71 | for filename in allnames: 72 | filestat = os.stat(filename) 73 | if filestat.st_mtime > verstat.st_mtime: 74 | print("{0} is newer than {1}".format(filename, vername)) 75 | return True 76 | 77 | return False 78 | 79 | 80 | def upver(vername): 81 | (version, build) = read_verfile(vername) 82 | if version == None or build == None: 83 | print("Failed to read version/build from {0}".format(vername)) 84 | return False 85 | 86 | # Bump the version number if any files in the same directory as the version file 87 | # have changed, including sub-directories. 88 | srcdir = os.path.dirname(vername) 89 | bump = should_bump(vername, srcdir) 90 | 91 | if bump: 92 | build += 1 93 | print("Incremented to build {0}".format(build)) 94 | write_verfile(vername, version, build) 95 | print("Written {0}".format(vername)) 96 | else: 97 | print("Staying at build {0}".format(build)) 98 | 99 | return (version, build) 100 | 101 | 102 | if __name__ == "__main__": 103 | if ("ACTION" in os.environ) and os.environ["ACTION"] == "clean": 104 | print("{0}: Not running while cleaning".format(sys.argv[0])) 105 | sys.exit(0) 106 | 107 | if len(sys.argv) < 3: 108 | print("Usage: {0} buildnum.ver Info.plist [... Info.plist]".format(sys.argv[0])) 109 | sys.exit(1) 110 | vername = sys.argv[1] 111 | 112 | (version, build) = upver(vername) 113 | if version == None or build == None: 114 | sys.exit(2) 115 | 116 | for i in range(2, len(sys.argv)): 117 | plistname = sys.argv[i] 118 | set_plist_version(plistname, version, build) 119 | 120 | sys.exit(0) 121 | -------------------------------------------------------------------------------- /copy_dylibs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from __future__ import print_function 3 | 4 | """Copy dylibs into the build folder. 5 | 6 | Usage: copy_dylibs.py [dylib ... dylib] 7 | 8 | If additional dylibs are specified on the command line, they will be copied into the app bundle. 9 | 10 | Copyright (c)2019,2021 Andy Duplain 11 | 12 | """ 13 | 14 | import sys, os, traceback, shutil, subprocess, re 15 | 16 | # Any dependencies outside of these directories need copying and fixing 17 | good_dirs = ["/System/", "/usr/lib/", "@rpath/"] 18 | 19 | # Turn on for more output 20 | debug = True 21 | 22 | frameworks_dir = None 23 | 24 | # Module and library install_name changes: 25 | # { 26 | # dylib_path : [ old_name, new_name ], ..., [old_name, new_name] 27 | # ... 28 | # } 29 | install_names = {} 30 | 31 | # List of dylibs copied 32 | copied_dylibs = set() 33 | 34 | 35 | def echo(message): 36 | print(message) 37 | sys.stdout.flush() 38 | 39 | 40 | def echon(message): 41 | sys.stdout.write(message) 42 | sys.stdout.flush() 43 | 44 | 45 | def is_file_good(file): 46 | for dir in good_dirs: 47 | if file.startswith(dir): 48 | return True 49 | return False 50 | 51 | 52 | def copy_dylib(src): 53 | global copied_dylibs 54 | 55 | if src.startswith("@"): 56 | return None 57 | 58 | (dylib_path, dylib_filename) = os.path.split(src) 59 | dest = os.path.join(frameworks_dir, dylib_filename) 60 | 61 | if not os.path.exists(dest): 62 | if debug: 63 | echo("Copying {0} into bundle".format(src)) 64 | shutil.copyfile(src, dest) 65 | os.chmod(dest, 0o644) 66 | copied_dylibs.add(dest) 67 | copy_dependencies(dest) 68 | return dest 69 | else: 70 | return None 71 | 72 | def copy_dependencies(file): 73 | global install_names 74 | 75 | if file.startswith("@"): 76 | return 77 | 78 | (file_path, file_filename) = os.path.split(file) 79 | echo("Examining {0}".format(file_filename)) 80 | found = 0 81 | pipe = subprocess.Popen(["otool", "-L", file], stdout=subprocess.PIPE) 82 | while True: 83 | line = pipe.stdout.readline().decode("utf-8") 84 | if line == "": 85 | break 86 | # /opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8) 87 | m = re.match(r"\s*(\S+)\s*\(compatibility version .+\)$", line) 88 | if m: 89 | dep = m.group(1) 90 | if not is_file_good(dep): 91 | (dep_path, dep_filename) = os.path.split(dep) 92 | if dep_filename != file_filename: 93 | echo(" ...found {0}".format(dep)) 94 | found += 1 95 | save_install_name(file, dep, "@rpath/" + dep_filename) 96 | dest = copy_dylib(dep) 97 | if dest is not None: 98 | save_install_name(dest, dep, "@rpath/" + dep_filename) 99 | 100 | 101 | def save_install_name(file, old_name, new_name): 102 | global install_names 103 | 104 | list = [] 105 | if file in install_names: 106 | list = install_names[file] 107 | list.append([old_name, new_name]) 108 | install_names[file] = list 109 | 110 | 111 | def change_install_names(): 112 | for dylib in install_names.keys(): 113 | (dylib_path, dylib_filename) = os.path.split(dylib) 114 | list = install_names[dylib] 115 | for install_name in list: 116 | old_name = install_name[0] 117 | new_name = install_name[1] 118 | # echo("{0}: old={1} new={2}".format(dylib, old_name, new_name)) 119 | (old_name_path, old_name_filename) = os.path.split(old_name) 120 | if dylib_filename == old_name_filename: 121 | cmdline = ["install_name_tool", "-id", new_name, dylib] 122 | else: 123 | cmdline = ["install_name_tool", "-change", old_name, new_name, dylib] 124 | if debug: 125 | echo("Running: " + " ".join(cmdline)) 126 | exitcode = subprocess.call(cmdline) 127 | if exitcode != 0: 128 | raise RuntimeError( 129 | "Failed to change '{0}' to '{1}' in '{2}".format( 130 | old_name, new_name, dylib 131 | ) 132 | ) 133 | 134 | 135 | def codesign(): 136 | if os.environ["CODE_SIGNING_ALLOWED"] == "YES": 137 | code_sign_identity = os.environ["EXPANDED_CODE_SIGN_IDENTITY"] 138 | for dylib in copied_dylibs: 139 | echo("Codesigning {0}".format(os.path.basename(dylib))) 140 | cmdline = [ 141 | "/usr/bin/codesign", 142 | "--force", 143 | "--sign", 144 | code_sign_identity, 145 | dylib, 146 | ] 147 | if debug: 148 | echo("Running: " + " ".join(cmdline)) 149 | exitcode = subprocess.call(cmdline) 150 | if exitcode != 0: 151 | raise RuntimeError("Failed to codesign '{0}'".format(dylib)) 152 | 153 | 154 | def main(args): 155 | global frameworks_dir 156 | 157 | if not "ACTION" in os.environ or not "TARGET_BUILD_DIR" in os.environ: 158 | print("This is an Xcode Build Phase script!") 159 | return 1 160 | 161 | # Only work during builds 162 | action = os.environ["ACTION"] 163 | if action != "build" and action != "install": 164 | return 0 165 | 166 | # Set-up output directories within app bundle 167 | build_dir = os.environ["TARGET_BUILD_DIR"] 168 | frameworks_path = os.environ["FRAMEWORKS_FOLDER_PATH"] 169 | frameworks_dir = os.path.join(build_dir, frameworks_path) 170 | 171 | executable_path = os.environ["EXECUTABLE_PATH"] 172 | executable_file = os.path.join(build_dir, executable_path) 173 | 174 | if os.path.exists(frameworks_dir): 175 | # Process existing .dylib files in Frameworks directory first as Xcode might have copied them and they might need attention 176 | for file in os.listdir(frameworks_dir): 177 | if file.endswith(".dylib"): 178 | copy_dependencies(os.path.join(frameworks_dir, file)) 179 | else: 180 | os.makedirs(frameworks_dir) 181 | 182 | # Copy additional dylibs 183 | if len(args) > 1: 184 | for arg in args[1:]: 185 | copy_dylib(arg) 186 | 187 | # Process main executable 188 | copy_dependencies(executable_file) 189 | 190 | change_install_names() 191 | 192 | codesign() 193 | 194 | if debug: 195 | echo("This is what your executable looks like now:") 196 | pipe = subprocess.Popen( 197 | ["otool", "-L", executable_file], stdout=subprocess.PIPE 198 | ) 199 | while True: 200 | line = pipe.stdout.readline().decode("utf-8") 201 | if line == "": 202 | break 203 | echon(line) 204 | 205 | 206 | if __name__ == "__main__": 207 | exitcode = 99 208 | try: 209 | exitcode = main(sys.argv) 210 | except Exception as e: 211 | echo(traceback.format_exc()) 212 | sys.exit(exitcode) 213 | --------------------------------------------------------------------------------