| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse |
| 6 import errno |
| 5 import os | 7 import os |
| 8 import shutil |
| 6 import sys | 9 import sys |
| 7 | 10 |
| 8 # Packages a framework bundle by setting up symlinks for the "Current" version. | 11 def Main(): |
| 9 # Usage: python /path/to/Foo.framework current_version | 12 parser = argparse.ArgumentParser(description='Create Mac Framework symlinks') |
| 13 parser.add_argument('--framework', action='store', type=str, required=True) |
| 14 parser.add_argument('--version', action='store', type=str) |
| 15 parser.add_argument('--contents', action='store', type=str, nargs='+') |
| 16 parser.add_argument('--stamp', action='store', type=str, required=True) |
| 17 args = parser.parse_args() |
| 10 | 18 |
| 11 def Main(args): | 19 VERSIONS = 'Versions' |
| 12 if len(args) != 3: | 20 CURRENT = 'Current' |
| 13 print >> sys.stderr, "Usage: %s /path/to/Something.framework A", (args[0],) | |
| 14 return 1 | |
| 15 | 21 |
| 16 (framework, version) = args[1:] | 22 # Ensure the Foo.framework/Versions/A/ directory exists and create the |
| 23 # Foo.framework/Versions/Current symlink to it. |
| 24 if args.version: |
| 25 try: |
| 26 os.makedirs(os.path.join(args.framework, VERSIONS, args.version), 0744) |
| 27 except OSError as e: |
| 28 if e.errno != errno.EEXIST: |
| 29 raise e |
| 30 _Relink(os.path.join(args.version), |
| 31 os.path.join(args.framework, VERSIONS, CURRENT)) |
| 17 | 32 |
| 18 # Find the name of the binary based on the part before the ".framework". | 33 # Establish the top-level symlinks in the framework bundle. The dest of |
| 19 binary = os.path.splitext(os.path.basename(framework))[0] | 34 # the symlinks may not exist yet. |
| 35 if args.contents: |
| 36 for item in args.contents: |
| 37 _Relink(os.path.join(VERSIONS, CURRENT, item), |
| 38 os.path.join(args.framework, item)) |
| 20 | 39 |
| 21 CURRENT = 'Current' | 40 # Write out a stamp file. |
| 22 RESOURCES = 'Resources' | 41 if args.stamp: |
| 23 VERSIONS = 'Versions' | 42 with open(args.stamp, 'w') as f: |
| 24 | 43 f.write(str(args)) |
| 25 if not os.path.exists(os.path.join(framework, VERSIONS, version, binary)): | |
| 26 # Binary-less frameworks don't seem to contain symlinks (see e.g. | |
| 27 # chromium's out/Debug/org.chromium.Chromium.manifest/ bundle). | |
| 28 return 0 | |
| 29 | |
| 30 # Move into the framework directory to set the symlinks correctly. | |
| 31 os.chdir(framework) | |
| 32 | |
| 33 # Set up the Current version. | |
| 34 _Relink(version, os.path.join(VERSIONS, CURRENT)) | |
| 35 | |
| 36 # Set up the root symlinks. | |
| 37 _Relink(os.path.join(VERSIONS, CURRENT, binary), binary) | |
| 38 _Relink(os.path.join(VERSIONS, CURRENT, RESOURCES), RESOURCES) | |
| 39 | |
| 40 # The following directories are optional but should also be symlinked | |
| 41 # in the root. | |
| 42 EXTRA_DIRS = [ | |
| 43 'Helpers', | |
| 44 'Internet Plug-Ins', | |
| 45 'Libraries', | |
| 46 'XPCServices', | |
| 47 ] | |
| 48 for extra_dir in EXTRA_DIRS: | |
| 49 extra_dir_target = os.path.join(VERSIONS, version, extra_dir) | |
| 50 if os.path.exists(extra_dir_target): | |
| 51 _Relink(extra_dir_target, extra_dir) | |
| 52 | 44 |
| 53 return 0 | 45 return 0 |
| 54 | 46 |
| 55 | 47 |
| 56 def _Relink(dest, link): | 48 def _Relink(dest, link): |
| 57 """Creates a symlink to |dest| named |link|. If |link| already exists, | 49 """Creates a symlink to |dest| named |link|. If |link| already exists, |
| 58 it is overwritten.""" | 50 it is overwritten.""" |
| 59 if os.path.lexists(link): | 51 try: |
| 60 os.remove(link) | 52 os.remove(link) |
| 53 except OSError as e: |
| 54 if e.errno != errno.ENOENT: |
| 55 shutil.rmtree(link) |
| 61 os.symlink(dest, link) | 56 os.symlink(dest, link) |
| 62 | 57 |
| 63 | 58 |
| 64 if __name__ == '__main__': | 59 if __name__ == '__main__': |
| 65 sys.exit(Main(sys.argv)) | 60 sys.exit(Main()) |
| OLD | NEW |