Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import os | |
| 6 import sys | |
| 7 | |
| 8 # Packages a framework bundle by setting up symlinks for the "Current" version. | |
| 9 # Usage: python /path/to/Foo.framework current_version | |
| 10 | |
| 11 def Main(args): | |
| 12 if len(args) != 3: | |
| 13 print >> sys.stderr, "Usage: %s /path/to/Something.framework A", (args[0],) | |
| 14 return 1 | |
| 15 | |
| 16 (framework, version) = args[1:] | |
| 17 | |
| 18 # Find the name of the binary based on the part before the ".framework". | |
| 19 binary = os.path.basename(framework).split('.')[0] | |
|
sdefresne
2016/06/09 07:16:18
nit: os.path.splitext(os.path.basename(framework))
Robert Sesek
2016/06/09 14:25:18
Done.
| |
| 20 | |
| 21 CURRENT = 'Current' | |
| 22 RESOURCES = 'Resources' | |
| 23 VERSIONS = 'Versions' | |
| 24 | |
| 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 pwd = os.getcwd() | |
|
sdefresne
2016/06/09 07:16:18
If you want to be sure to restore the current work
Robert Sesek
2016/06/09 14:25:18
I just dropped the cwd reset because, as you say,
| |
| 32 os.chdir(framework) | |
| 33 | |
| 34 # Set up the Current version. | |
| 35 _Relink(version, os.path.join(VERSIONS, CURRENT)) | |
| 36 | |
| 37 # Set up the root symlinks. | |
| 38 _Relink(os.path.join(VERSIONS, CURRENT, binary), binary) | |
| 39 _Relink(os.path.join(VERSIONS, CURRENT, RESOURCES), RESOURCES) | |
| 40 | |
| 41 # The following directories are optional but should also be symlinked | |
| 42 # in the root. | |
| 43 EXTRA_DIRS = [ | |
| 44 'Helpers', | |
| 45 'Internet Plug-Ins', | |
| 46 'Libraries', | |
| 47 'XPCServices', | |
| 48 ] | |
| 49 for extra_dir in EXTRA_DIRS: | |
| 50 extra_dir_target = os.path.join(VERSIONS, version, extra_dir) | |
| 51 if os.path.exists(extra_dir_target): | |
| 52 _Relink(extra_dir_target, extra_dir) | |
| 53 | |
| 54 # Back to where we were before! | |
| 55 os.chdir(pwd) | |
| 56 return 0 | |
| 57 | |
| 58 | |
| 59 def _Relink(dest, link): | |
| 60 """Creates a symlink to |dest| named |link|. If |link| already exists, | |
| 61 it is overwritten.""" | |
| 62 if os.path.lexists(link): | |
| 63 os.remove(link) | |
| 64 os.symlink(dest, link) | |
| 65 | |
| 66 | |
| 67 if __name__ == '__main__': | |
| 68 sys.exit(Main(sys.argv)) | |
| OLD | NEW |