| 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 Before creating any links, the old entries of the TARGET directory will be |
| 14 removed. |
| 15 |
| 13 Usage: | 16 Usage: |
| 14 python tools/make_links.py OPTIONS TARGET SOURCES... | 17 python tools/make_links.py OPTIONS TARGET SOURCES... |
| 15 ''' | 18 ''' |
| 16 | 19 |
| 17 import optparse | 20 import optparse |
| 18 import os | 21 import os |
| 22 import shutil |
| 19 import subprocess | 23 import subprocess |
| 20 import sys | 24 import sys |
| 21 import utils | 25 import utils |
| 22 | 26 |
| 23 | 27 |
| 24 def get_options(): | 28 def get_options(): |
| 25 result = optparse.OptionParser() | 29 result = optparse.OptionParser() |
| 26 result.add_option("--timestamp_file", "", | 30 result.add_option("--timestamp_file", "", |
| 27 help='Create a timestamp file when done creating the links.', | 31 help='Create a timestamp file when done creating the links.', |
| 28 default='') | 32 default='') |
| (...skipping 17 matching lines...) Expand all Loading... |
| 46 return subprocess.call(['mklink', '/j', target, source], shell=True) | 50 return subprocess.call(['mklink', '/j', target, source], shell=True) |
| 47 else: | 51 else: |
| 48 return subprocess.call(['ln', '-s', source, target]) | 52 return subprocess.call(['ln', '-s', source, target]) |
| 49 | 53 |
| 50 def create_timestamp_file(options): | 54 def create_timestamp_file(options): |
| 51 if options.timestamp_file != '': | 55 if options.timestamp_file != '': |
| 52 dir_name = os.path.dirname(options.timestamp_file) | 56 dir_name = os.path.dirname(options.timestamp_file) |
| 53 if not os.path.exists(dir_name): | 57 if not os.path.exists(dir_name): |
| 54 os.mkdir(dir_name) | 58 os.mkdir(dir_name) |
| 55 open(options.timestamp_file, 'w').close() | 59 open(options.timestamp_file, 'w').close() |
| 56 | 60 |
| 57 | 61 |
| 58 def main(argv): | 62 def main(argv): |
| 59 (options, args) = get_options() | 63 (options, args) = get_options() |
| 60 target = os.path.relpath(args[0]) | 64 target = os.path.relpath(args[0]) |
| 61 if not os.path.exists(target): | 65 if os.path.exists(target): |
| 62 os.makedirs(target) | 66 # Remove the packages directory if it already exists. |
| 67 # This is necessary, otherwise we can end up having links in there |
| 68 # pointing to directories which no longer exist (on incremental builds). |
| 69 print 'Removing %s' % target |
| 70 shutil.rmtree(target) |
| 71 os.makedirs(target) |
| 63 for source in args[1:]: | 72 for source in args[1:]: |
| 64 # Assume the source directory is named ".../NAME/lib". | 73 # Assume the source directory is named ".../NAME/lib". |
| 65 (name, lib) = os.path.split(source) | 74 (name, lib) = os.path.split(source) |
| 66 if lib != 'lib': | 75 if lib != 'lib': |
| 67 name = source | 76 name = source |
| 68 # Remove any addtional path components preceding NAME. | 77 # Remove any addtional path components preceding NAME. |
| 69 (path, name) = os.path.split(name) | 78 (path, name) = os.path.split(name) |
| 70 if utils.GuessOS() == 'win32': | 79 if utils.GuessOS() == 'win32': |
| 71 source = os.path.relpath(source) | 80 source = os.path.relpath(source) |
| 72 else: | 81 else: |
| 73 source = os.path.relpath(source, start=target) | 82 source = os.path.relpath(source, start=target) |
| 74 exit_code = make_link(source, os.path.join(target, name)) | 83 exit_code = make_link(source, os.path.join(target, name)) |
| 75 if exit_code != 0: | 84 if exit_code != 0: |
| 76 return exit_code | 85 return exit_code |
| 77 create_timestamp_file(options) | 86 create_timestamp_file(options) |
| 78 return 0 | 87 return 0 |
| 79 | 88 |
| 80 | 89 |
| 81 if __name__ == '__main__': | 90 if __name__ == '__main__': |
| 82 sys.exit(main(sys.argv)) | 91 sys.exit(main(sys.argv)) |
| OLD | NEW |