| 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 # Useful messages when we find orphaned checkouts. |
| 32 old_directories = {'package_config': |
| 33 'Please remove third_party/pkg/package_config.'} |
| 31 | 34 |
| 32 def get_options(): | 35 def get_options(): |
| 33 result = optparse.OptionParser() | 36 result = optparse.OptionParser() |
| 34 result.add_option("--timestamp_file", "", | 37 result.add_option("--timestamp_file", "", |
| 35 help='Create a timestamp file when done creating the links.', | 38 help='Create a timestamp file when done creating the links.', |
| 36 default='') | 39 default='') |
| 37 return result.parse_args() | 40 return result.parse_args() |
| 38 | 41 |
| 39 def make_link(source, target, orig_source): | 42 def make_link(source, target, orig_source): |
| 40 if os.path.islink(target): | 43 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): | 82 for link in os.listdir(target): |
| 80 full_link = os.path.join(target, link) | 83 full_link = os.path.join(target, link) |
| 81 if os.path.isdir(full_link) and utils.IsWindows(): | 84 if os.path.isdir(full_link) and utils.IsWindows(): |
| 82 # It seems like python on Windows is treating pseudo symlinks to | 85 # It seems like python on Windows is treating pseudo symlinks to |
| 83 # directories as directories. | 86 # directories as directories. |
| 84 os.rmdir(full_link) | 87 os.rmdir(full_link) |
| 85 else: | 88 else: |
| 86 os.remove(full_link) | 89 os.remove(full_link) |
| 87 else: | 90 else: |
| 88 os.makedirs(target) | 91 os.makedirs(target) |
| 92 linked_names = {}; |
| 89 for source in args[1:]: | 93 for source in args[1:]: |
| 90 # Assume the source directory is named ".../NAME/lib". | 94 # Assume the source directory is named ".../NAME/lib". |
| 91 split = source.split(':') | 95 split = source.split(':') |
| 92 name = None | 96 name = None |
| 93 if len(split) == 2: (source, name) = split | 97 if len(split) == 2: (source, name) = split |
| 94 | 98 |
| 95 (path, lib) = os.path.split(source) | 99 (path, lib) = os.path.split(source) |
| 96 if lib != 'lib': | 100 if lib != 'lib': |
| 97 path = source | 101 path = source |
| 98 # Remove any additional path components preceding NAME, if one wasn't | 102 # Remove any additional path components preceding NAME, if one wasn't |
| 99 # specified explicitly. | 103 # specified explicitly. |
| 100 if not name: (_, name) = os.path.split(path) | 104 if not name: (_, name) = os.path.split(path) |
| 105 # We have an issue with left-behind checkouts in third_party/pkg and |
| 106 # third_party/pkg_tested when we move entries in DEPS. This reports them. |
| 107 if name in linked_names: |
| 108 print 'Duplicate directory %s is linked to both %s and %s.' % ( |
| 109 name, linked_names[name], path) |
| 110 if name in old_directories: |
| 111 print old_directories[name] |
| 112 return 1 |
| 113 linked_names[name] = path |
| 101 orig_source = source | 114 orig_source = source |
| 102 if utils.GuessOS() == 'win32': | 115 if utils.GuessOS() == 'win32': |
| 103 source = os.path.relpath(source) | 116 source = os.path.relpath(source) |
| 104 else: | 117 else: |
| 105 source = os.path.relpath(source, start=target) | 118 source = os.path.relpath(source, start=target) |
| 106 exit_code = make_link(source, os.path.join(target, name), orig_source) | 119 exit_code = make_link(source, os.path.join(target, name), orig_source) |
| 107 if exit_code != 0: | 120 if exit_code != 0: |
| 108 return exit_code | 121 return exit_code |
| 109 create_timestamp_file(options) | 122 create_timestamp_file(options) |
| 110 return 0 | 123 return 0 |
| 111 | 124 |
| 112 | 125 |
| 113 if __name__ == '__main__': | 126 if __name__ == '__main__': |
| 114 sys.exit(main(sys.argv)) | 127 sys.exit(main(sys.argv)) |
| OLD | NEW |