Index: tools/make_links.py |
diff --git a/tools/make_links.py b/tools/make_links.py |
deleted file mode 100755 |
index 294c9c94ae5e74642663b31176c8833da817f3d8..0000000000000000000000000000000000000000 |
--- a/tools/make_links.py |
+++ /dev/null |
@@ -1,161 +0,0 @@ |
-#!/usr/bin/env python |
-# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
-# for details. All rights reserved. Use of this source code is governed by a |
-# BSD-style license that can be found in the LICENSE file. |
- |
- |
-"""Tool for creating symlinks from SOURCES to TARGET. |
- |
-For each SOURCE in SOURCES create a link from SOURCE to TARGET. If a |
-SOURCE ends with .../lib, the lib suffix is ignored when determining |
-the name of the target link. |
- |
-If a SOURCE contains ":", the left side is the path and the right side is the |
-name of the package symlink. |
- |
-Before creating any links, the old entries of the TARGET directory will be |
-removed. |
- |
-Usage: |
- python tools/make_links.py OPTIONS TARGET SOURCES... |
- |
-""" |
- |
-import optparse |
-import os |
-import shutil |
-import subprocess |
-import sys |
-import urllib |
-import urlparse |
-import utils |
- |
-# Useful messages when we find orphaned checkouts. |
-old_directories = { |
- 'package_config': 'Please remove third_party/pkg/package_config.', |
- 'analyzer_cli': 'Please remove third_party/pkg/analyzer_cli.'} |
- |
-def get_options(): |
- result = optparse.OptionParser() |
- result.add_option("--timestamp_file", "", |
- help='Create a timestamp file when done creating the links.', |
- default='') |
- result.add_option("-q", "--quiet", |
- help="Don't print any messages", |
- action="store_true", |
- dest="quiet", |
- default=False) |
- result.add_option("--create-links", |
- help='Create links to the package lib directories in "packages/".', |
- action='store_false', |
- default=True) |
- result.add_option("--create-package-file", |
- help='Create a ".packages" file pointing to the packages.', |
- action='store_false', |
- default=True) |
- |
- return result.parse_args() |
- |
-def make_link(quiet, source, target, orig_source): |
- if os.path.islink(target): |
- if not quiet: |
- print 'Removing %s' % target |
- sys.stdout.flush() |
- os.unlink(target) |
- |
- if os.path.isdir(target): |
- if not quiet: |
- print 'Removing %s' % target |
- sys.stdout.flush() |
- os.rmdir(target) |
- |
- if os.path.isfile(orig_source): |
- if not quiet: |
- print 'Copying file from %s to %s' % (orig_source, target) |
- sys.stdout.flush() |
- shutil.copyfile(orig_source, target) |
- return 0 |
- else: |
- if not quiet: |
- print 'Creating link from %s to %s' % (source, target) |
- sys.stdout.flush() |
- |
- if utils.GuessOS() == 'win32': |
- return subprocess.call(['mklink', '/j', target, source], shell=True) |
- else: |
- return subprocess.call(['ln', '-s', source, target]) |
- |
-def create_timestamp_file(options): |
- if options.timestamp_file != '': |
- dir_name = os.path.dirname(options.timestamp_file) |
- if not os.path.exists(dir_name): |
- os.mkdir(dir_name) |
- open(options.timestamp_file, 'w').close() |
- |
-def main(argv): |
- (options, args) = get_options() |
- target_dir = os.path.relpath(args[0]) |
- target = os.path.join(target_dir, 'packages') |
- if os.path.exists(target): |
- # If the packages directory already exists, delete the current links in |
- # it. This is necessary, otherwise we can end up having links in there |
- # pointing to directories which no longer exist (on incremental builds). |
- for link in os.listdir(target): |
- full_link = os.path.join(target, link) |
- if os.path.isdir(full_link) and utils.IsWindows(): |
- # It seems like python on Windows is treating pseudo symlinks to |
- # directories as directories. |
- os.rmdir(full_link) |
- else: |
- os.remove(full_link) |
- else: |
- os.makedirs(target) |
- target = os.path.join(target_dir, '.packages') |
- if os.path.exists(target): |
- os.remove(target) |
- |
- linked_names = {}; |
- package_file_contents = '# .package file created by tools/make_links.py\n' |
- for source in args[1:]: |
- # Assume the source directory is named ".../NAME/lib". |
- split = source.split(':') |
- name = None |
- if len(split) == 2: (source, name) = split |
- |
- (path, lib) = os.path.split(source) |
- if lib != 'lib': |
- path = source |
- # Remove any additional path components preceding NAME, if one wasn't |
- # specified explicitly. |
- if not name: (_, name) = os.path.split(path) |
- # We have an issue with left-behind checkouts in third_party/pkg and |
- # third_party/pkg_tested when we move entries in DEPS. This reports them. |
- if name in linked_names: |
- print 'Duplicate directory %s is linked to both %s and %s.' % ( |
- name, linked_names[name], path) |
- if name in old_directories: |
- print old_directories[name] |
- return 1 |
- linked_names[name] = path |
- orig_source = source |
- if options.create_links: |
- if utils.GuessOS() == 'win32': |
- source = os.path.relpath(source) |
- else: |
- source = os.path.relpath(source, start=target) |
- exit_code = make_link(options.quiet, |
- source, os.path.join(target, name), orig_source) |
- if exit_code != 0: |
- return exit_code |
- abs_source = os.path.abspath(orig_source) |
- source_url = urlparse.urljoin('file:', urllib.pathname2url(abs_source)) |
- package_file_contents += '%s:%s\n' % (name, source_url) |
- if options.create_package_file: |
- with open(os.path.join(target_dir, '.packages'), 'w') as package_file: |
- package_file.write(package_file_contents) |
- create_timestamp_file(options) |
- return 0 |
- |
- |
-if __name__ == '__main__': |
- sys.exit(main(sys.argv)) |