| 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 21 matching lines...) Expand all Loading... |
| 32 if os.path.islink(target): | 32 if os.path.islink(target): |
| 33 print 'Removing %s' % target | 33 print 'Removing %s' % target |
| 34 sys.stdout.flush() | 34 sys.stdout.flush() |
| 35 os.unlink(target) | 35 os.unlink(target) |
| 36 | 36 |
| 37 if os.path.isdir(target): | 37 if os.path.isdir(target): |
| 38 print 'Removing %s' % target | 38 print 'Removing %s' % target |
| 39 sys.stdout.flush() | 39 sys.stdout.flush() |
| 40 os.rmdir(target) | 40 os.rmdir(target) |
| 41 | 41 |
| 42 print 'Creating link from %s to %s' % (source, target) |
| 43 sys.stdout.flush() |
| 44 |
| 42 if utils.GuessOS() == 'win32': | 45 if utils.GuessOS() == 'win32': |
| 43 source = os.path.relpath(source) | |
| 44 return subprocess.call(['mklink', '/j', target, source], shell=True) | 46 return subprocess.call(['mklink', '/j', target, source], shell=True) |
| 45 else: | 47 else: |
| 46 source = os.path.relpath(source, start=target) | |
| 47 return subprocess.call(['ln', '-s', source, target]) | 48 return subprocess.call(['ln', '-s', source, target]) |
| 48 | 49 |
| 49 | 50 |
| 50 def main(argv): | 51 def main(argv): |
| 51 target = os.path.relpath(argv[1]) | 52 target = os.path.relpath(argv[1]) |
| 52 for source in argv[2:]: | 53 for source in argv[2:]: |
| 53 # Assume the source directory is named ".../TARGET_NAME/lib". | 54 # Assume the source directory is named ".../TARGET_NAME/lib". |
| 54 (name, lib) = os.path.split(source) | 55 (name, lib) = os.path.split(source) |
| 55 if lib != 'lib': | 56 if lib != 'lib': |
| 56 name = source | 57 name = source |
| 57 # Remove any addtional path components preceding TARGET_NAME. | 58 # Remove any addtional path components preceding TARGET_NAME. |
| 58 (path, name) = os.path.split(name) | 59 (path, name) = os.path.split(name) |
| 60 if utils.GuessOS() == 'win32': |
| 61 source = os.path.relpath(source) |
| 62 else: |
| 63 source = os.path.relpath(source, start=target) |
| 59 exit_code = make_link(source, os.path.join(target, name)) | 64 exit_code = make_link(source, os.path.join(target, name)) |
| 60 if exit_code != 0: | 65 if exit_code != 0: |
| 61 return exit_code | 66 return exit_code |
| 62 return 0 | 67 return 0 |
| 63 | 68 |
| 64 | 69 |
| 65 if __name__ == '__main__': | 70 if __name__ == '__main__': |
| 66 sys.exit(main(sys.argv)) | 71 sys.exit(main(sys.argv)) |
| OLD | NEW |