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 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 """ | 22 """ |
23 | 23 |
24 import optparse | 24 import optparse |
25 import os | 25 import os |
26 import shutil | 26 import shutil |
27 import subprocess | 27 import subprocess |
28 import sys | 28 import sys |
29 import utils | 29 import utils |
30 | 30 |
31 old_directories = {'package_config': | |
ricow1
2015/08/10 10:19:30
add a note on what this is
Bill Hesse
2015/08/10 12:36:18
Done.
| |
32 'Please remove third_party/pkg/package_config.'} | |
31 | 33 |
32 def get_options(): | 34 def get_options(): |
33 result = optparse.OptionParser() | 35 result = optparse.OptionParser() |
34 result.add_option("--timestamp_file", "", | 36 result.add_option("--timestamp_file", "", |
35 help='Create a timestamp file when done creating the links.', | 37 help='Create a timestamp file when done creating the links.', |
36 default='') | 38 default='') |
37 return result.parse_args() | 39 return result.parse_args() |
38 | 40 |
39 def make_link(source, target, orig_source): | 41 def make_link(source, target, orig_source): |
40 if os.path.islink(target): | 42 if os.path.islink(target): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 for link in os.listdir(target): | 81 for link in os.listdir(target): |
80 full_link = os.path.join(target, link) | 82 full_link = os.path.join(target, link) |
81 if os.path.isdir(full_link) and utils.IsWindows(): | 83 if os.path.isdir(full_link) and utils.IsWindows(): |
82 # It seems like python on Windows is treating pseudo symlinks to | 84 # It seems like python on Windows is treating pseudo symlinks to |
83 # directories as directories. | 85 # directories as directories. |
84 os.rmdir(full_link) | 86 os.rmdir(full_link) |
85 else: | 87 else: |
86 os.remove(full_link) | 88 os.remove(full_link) |
87 else: | 89 else: |
88 os.makedirs(target) | 90 os.makedirs(target) |
91 linked_names = {}; | |
89 for source in args[1:]: | 92 for source in args[1:]: |
90 # Assume the source directory is named ".../NAME/lib". | 93 # Assume the source directory is named ".../NAME/lib". |
91 split = source.split(':') | 94 split = source.split(':') |
92 name = None | 95 name = None |
93 if len(split) == 2: (source, name) = split | 96 if len(split) == 2: (source, name) = split |
94 | 97 |
95 (path, lib) = os.path.split(source) | 98 (path, lib) = os.path.split(source) |
96 if lib != 'lib': | 99 if lib != 'lib': |
97 path = source | 100 path = source |
98 # Remove any additional path components preceding NAME, if one wasn't | 101 # Remove any additional path components preceding NAME, if one wasn't |
99 # specified explicitly. | 102 # specified explicitly. |
100 if not name: (_, name) = os.path.split(path) | 103 if not name: (_, name) = os.path.split(path) |
104 if name in linked_names: | |
ricow1
2015/08/10 10:19:30
Add a comment stating what the issues is, somethin
Bill Hesse
2015/08/10 12:36:18
Done.
| |
105 print 'Duplicate directory %s is linked to both %s and %s.' % ( | |
106 name, linked_names[name], path) | |
107 if name in old_directories: | |
108 print old_directories[name] | |
109 return 1 | |
110 linked_names[name] = path | |
101 orig_source = source | 111 orig_source = source |
102 if utils.GuessOS() == 'win32': | 112 if utils.GuessOS() == 'win32': |
103 source = os.path.relpath(source) | 113 source = os.path.relpath(source) |
104 else: | 114 else: |
105 source = os.path.relpath(source, start=target) | 115 source = os.path.relpath(source, start=target) |
106 exit_code = make_link(source, os.path.join(target, name), orig_source) | 116 exit_code = make_link(source, os.path.join(target, name), orig_source) |
107 if exit_code != 0: | 117 if exit_code != 0: |
108 return exit_code | 118 return exit_code |
109 create_timestamp_file(options) | 119 create_timestamp_file(options) |
110 return 0 | 120 return 0 |
111 | 121 |
112 | 122 |
113 if __name__ == '__main__': | 123 if __name__ == '__main__': |
114 sys.exit(main(sys.argv)) | 124 sys.exit(main(sys.argv)) |
OLD | NEW |