| 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 12 matching lines...) Expand all Loading... |
| 23 def make_link(source, target): | 23 def make_link(source, target): |
| 24 # TODO(ahe): Remove this code when the build bots are green again. | 24 # TODO(ahe): Remove this code when the build bots are green again. |
| 25 bug_cleanup = os.path.join(target, 'lib') | 25 bug_cleanup = os.path.join(target, 'lib') |
| 26 if os.path.islink(bug_cleanup): | 26 if os.path.islink(bug_cleanup): |
| 27 print 'Removing %s' % bug_cleanup | 27 print 'Removing %s' % bug_cleanup |
| 28 sys.stdout.flush() | 28 sys.stdout.flush() |
| 29 os.unlink(bug_cleanup) | 29 os.unlink(bug_cleanup) |
| 30 # End of temporary code. | 30 # End of temporary code. |
| 31 | 31 |
| 32 if os.path.islink(target): | 32 if os.path.islink(target): |
| 33 print 'Removing %s' % target |
| 34 sys.stdout.flush() |
| 33 os.unlink(target) | 35 os.unlink(target) |
| 34 | 36 |
| 37 if os.path.isdir(target): |
| 38 print 'Removing %s' % target |
| 39 sys.stdout.flush() |
| 40 os.rmdir(target) |
| 41 |
| 35 if utils.GuessOS() == 'win32': | 42 if utils.GuessOS() == 'win32': |
| 36 return subprocess.call(['mklink', '/j', target, source]) | 43 source = os.path.relpath(source) |
| 44 return subprocess.call(['mklink', '/j', target, source], shell=True) |
| 37 else: | 45 else: |
| 46 source = os.path.relpath(source, start=target) |
| 38 return subprocess.call(['ln', '-s', source, target]) | 47 return subprocess.call(['ln', '-s', source, target]) |
| 39 | 48 |
| 40 | 49 |
| 41 def main(argv): | 50 def main(argv): |
| 42 target = argv[1] | 51 target = os.path.relpath(argv[1]) |
| 43 for source in argv[2:]: | 52 for source in argv[2:]: |
| 44 # Assume the source directory is named ".../TARGET_NAME/lib". | 53 # Assume the source directory is named ".../TARGET_NAME/lib". |
| 45 (name, lib) = os.path.split(source) | 54 (name, lib) = os.path.split(source) |
| 46 if lib != 'lib': | 55 if lib != 'lib': |
| 47 name = source | 56 name = source |
| 48 # Remove any addtional path components preceding TARGET_NAME. | 57 # Remove any addtional path components preceding TARGET_NAME. |
| 49 (path, name) = os.path.split(name) | 58 (path, name) = os.path.split(name) |
| 50 exit_code = make_link(os.path.relpath(source, start=target), | 59 exit_code = make_link(source, os.path.join(target, name)) |
| 51 os.path.join(target, name)) | |
| 52 if exit_code != 0: | 60 if exit_code != 0: |
| 53 return exit_code | 61 return exit_code |
| 54 return 0 | 62 return 0 |
| 55 | 63 |
| 56 | 64 |
| 57 if __name__ == '__main__': | 65 if __name__ == '__main__': |
| 58 sys.exit(main(sys.argv)) | 66 sys.exit(main(sys.argv)) |
| OLD | NEW |