From 49b663aa87da00c0277e3ba3be664d121b8803ba Mon Sep 17 00:00:00 2001 From: dehnert Date: Mon, 15 Aug 2016 22:03:29 +0200 Subject: [PATCH] started working on python script that automatically packages the binary for mac os Former-commit-id: 11a73f85e7493bc3ab940241599cdab6d505ab91 --- util/osx-package/packager.py | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 util/osx-package/packager.py diff --git a/util/osx-package/packager.py b/util/osx-package/packager.py new file mode 100644 index 000000000..39d06a667 --- /dev/null +++ b/util/osx-package/packager.py @@ -0,0 +1,47 @@ +import argparse +import subprocess +import os + +def get_dependencies(file): + # Call otool -L file to obtain the dependencies. + proc = subprocess.Popen(["otool", "-L", args.binary], stdout=subprocess.PIPE) + result = {} + for line_bytes in proc.stdout: + line = line_bytes.decode("utf-8").strip() + lib = line.split()[0] + if (lib.startswith("@")): + lib = lib.split("/", 1)[1] + (base, file) = os.path.split(lib) + print(base + " // " + file) + + return result + +def parse_arguments(): + parser = argparse.ArgumentParser(description='Package the storm binary on Mac OS.') + parser.add_argument('binary', help='the binary to package') + args = parser.parse_args() + return args + +dep_exeptions = set() +dep_exeptions.add("libSystem.B.dylib") +dep_exeptions.add("libc++.1.dylib") + +def rec_gather_all_dependencies(file, deps = set()): + current_deps = get_dependencies(file) + new_deps = current_deps.keys() - dep_exeptions - deps + deps = deps | current_deps.keys() + + for d in new_deps: + rec_gather_all_dependencies(file, deps) + + return deps + +def print_deps(deps): + print("Found the following dependencies:") + for d in deps: + print(d) + +if __name__ == "__main__": + args = parse_arguments() + deps = rec_gather_all_dependencies(args.binary) + print_deps(deps)