Chromium Code Reviews| 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 |
| 19 import subprocess | 22 import subprocess |
| 20 import sys | 23 import sys |
| 21 import utils | 24 import utils |
| 22 | 25 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 51 if options.timestamp_file != '': | 54 if options.timestamp_file != '': |
| 52 dir_name = os.path.dirname(options.timestamp_file) | 55 dir_name = os.path.dirname(options.timestamp_file) |
| 53 if not os.path.exists(dir_name): | 56 if not os.path.exists(dir_name): |
| 54 os.mkdir(dir_name) | 57 os.mkdir(dir_name) |
| 55 open(options.timestamp_file, 'w').close() | 58 open(options.timestamp_file, 'w').close() |
| 56 | 59 |
| 57 | 60 |
| 58 def main(argv): | 61 def main(argv): |
| 59 (options, args) = get_options() | 62 (options, args) = get_options() |
| 60 target = os.path.relpath(args[0]) | 63 target = os.path.relpath(args[0]) |
| 61 if not os.path.exists(target): | 64 if os.path.exists(target): |
|
ricow1
2013/10/23 07:45:44
why not just simplify to:
if os.path.exists(target
kustermann
2013/10/23 07:57:40
I thought about it as well -- I was just worried t
| |
| 65 # If the packages directory already exists, delete the current links inside | |
| 66 # it. This is necessary, otherwise we can end up having links in there | |
| 67 # pointing to directories which no longer exist (on incremental builds). | |
| 68 for link in os.listdir(target): | |
| 69 os.remove(os.path.join(target, link)) | |
| 70 else: | |
| 62 os.makedirs(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 |