OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 """Tool for creating symlinks from SOURCES to TARGET. | 7 """Tool for creating symlinks from SOURCES to TARGET. |
8 | 8 |
9 For each SOURCE in SOURCES create a link from SOURCE to TARGET. If a | 9 For each SOURCE in SOURCES create a link from SOURCE to TARGET. If a |
10 SOURCE ends with .../lib, the lib suffix is ignored when determining | 10 SOURCE ends with .../lib, the lib suffix is ignored when determining |
11 the name of the target link. | 11 the name of the target link. |
12 | 12 |
| 13 If a SOURCE contains ":", the left side is the path and the right side is the |
| 14 name of the package symlink. |
| 15 |
13 Before creating any links, the old entries of the TARGET directory will be | 16 Before creating any links, the old entries of the TARGET directory will be |
14 removed. | 17 removed. |
15 | 18 |
16 Usage: | 19 Usage: |
17 python tools/make_links.py OPTIONS TARGET SOURCES... | 20 python tools/make_links.py OPTIONS TARGET SOURCES... |
| 21 |
18 """ | 22 """ |
19 | 23 |
20 import optparse | 24 import optparse |
21 import os | 25 import os |
22 import shutil | 26 import shutil |
23 import subprocess | 27 import subprocess |
24 import sys | 28 import sys |
25 import utils | 29 import utils |
26 | 30 |
27 | 31 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if os.path.isdir(full_link) and utils.IsWindows(): | 81 if os.path.isdir(full_link) and utils.IsWindows(): |
78 # It seems like python on Windows is treating pseudo symlinks to | 82 # It seems like python on Windows is treating pseudo symlinks to |
79 # directories as directories. | 83 # directories as directories. |
80 os.rmdir(full_link) | 84 os.rmdir(full_link) |
81 else: | 85 else: |
82 os.remove(full_link) | 86 os.remove(full_link) |
83 else: | 87 else: |
84 os.makedirs(target) | 88 os.makedirs(target) |
85 for source in args[1:]: | 89 for source in args[1:]: |
86 # Assume the source directory is named ".../NAME/lib". | 90 # Assume the source directory is named ".../NAME/lib". |
87 (name, lib) = os.path.split(source) | 91 split = source.split(':') |
| 92 name = None |
| 93 if len(split) == 2: (source, name) = split |
| 94 |
| 95 (path, lib) = os.path.split(source) |
88 if lib != 'lib': | 96 if lib != 'lib': |
89 name = source | 97 path = source |
90 # Remove any addtional path components preceding NAME. | 98 # Remove any additional path components preceding NAME, if one wasn't |
91 (path, name) = os.path.split(name) | 99 # specified explicitly. |
| 100 if not name: (_, name) = os.path.split(path) |
92 orig_source = source | 101 orig_source = source |
93 if utils.GuessOS() == 'win32': | 102 if utils.GuessOS() == 'win32': |
94 source = os.path.relpath(source) | 103 source = os.path.relpath(source) |
95 else: | 104 else: |
96 source = os.path.relpath(source, start=target) | 105 source = os.path.relpath(source, start=target) |
97 exit_code = make_link(source, os.path.join(target, name), orig_source) | 106 exit_code = make_link(source, os.path.join(target, name), orig_source) |
98 if exit_code != 0: | 107 if exit_code != 0: |
99 return exit_code | 108 return exit_code |
100 create_timestamp_file(options) | 109 create_timestamp_file(options) |
101 return 0 | 110 return 0 |
102 | 111 |
103 | 112 |
104 if __name__ == '__main__': | 113 if __name__ == '__main__': |
105 sys.exit(main(sys.argv)) | 114 sys.exit(main(sys.argv)) |
OLD | NEW |