Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: tools/make_links.py

Issue 2259613002: [fuchsia] Fix build. Build packages/ output. Add Directory::Exists(). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/list_pkg_directories.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 20 matching lines...) Expand all
31 # Useful messages when we find orphaned checkouts. 31 # Useful messages when we find orphaned checkouts.
32 old_directories = { 32 old_directories = {
33 'package_config': 'Please remove third_party/pkg/package_config.', 33 'package_config': 'Please remove third_party/pkg/package_config.',
34 'analyzer_cli': 'Please remove third_party/pkg/analyzer_cli.'} 34 'analyzer_cli': 'Please remove third_party/pkg/analyzer_cli.'}
35 35
36 def get_options(): 36 def get_options():
37 result = optparse.OptionParser() 37 result = optparse.OptionParser()
38 result.add_option("--timestamp_file", "", 38 result.add_option("--timestamp_file", "",
39 help='Create a timestamp file when done creating the links.', 39 help='Create a timestamp file when done creating the links.',
40 default='') 40 default='')
41 result.add_option("-q", "--quiet",
42 help="Don't print any messages",
43 action="store_true",
44 dest="quiet",
45 default=False)
41 return result.parse_args() 46 return result.parse_args()
42 47
43 def make_link(source, target, orig_source): 48 def make_link(quiet, source, target, orig_source):
44 if os.path.islink(target): 49 if os.path.islink(target):
45 print 'Removing %s' % target 50 if not quiet:
51 print 'Removing %s' % target
46 sys.stdout.flush() 52 sys.stdout.flush()
47 os.unlink(target) 53 os.unlink(target)
48 54
49 if os.path.isdir(target): 55 if os.path.isdir(target):
50 print 'Removing %s' % target 56 if not quiet:
57 print 'Removing %s' % target
51 sys.stdout.flush() 58 sys.stdout.flush()
52 os.rmdir(target) 59 os.rmdir(target)
53 60
54 if os.path.isfile(orig_source): 61 if os.path.isfile(orig_source):
55 print 'Copying file from %s to %s' % (orig_source, target) 62 if not quiet:
63 print 'Copying file from %s to %s' % (orig_source, target)
56 sys.stdout.flush() 64 sys.stdout.flush()
57 shutil.copyfile(orig_source, target) 65 shutil.copyfile(orig_source, target)
58 return 0 66 return 0
59 else: 67 else:
60 print 'Creating link from %s to %s' % (source, target) 68 if not quiet:
69 print 'Creating link from %s to %s' % (source, target)
61 sys.stdout.flush() 70 sys.stdout.flush()
62 71
63 if utils.GuessOS() == 'win32': 72 if utils.GuessOS() == 'win32':
64 return subprocess.call(['mklink', '/j', target, source], shell=True) 73 return subprocess.call(['mklink', '/j', target, source], shell=True)
65 else: 74 else:
66 return subprocess.call(['ln', '-s', source, target]) 75 return subprocess.call(['ln', '-s', source, target])
67 76
68 def create_timestamp_file(options): 77 def create_timestamp_file(options):
69 if options.timestamp_file != '': 78 if options.timestamp_file != '':
70 dir_name = os.path.dirname(options.timestamp_file) 79 dir_name = os.path.dirname(options.timestamp_file)
(...skipping 12 matching lines...) Expand all
83 for link in os.listdir(target): 92 for link in os.listdir(target):
84 full_link = os.path.join(target, link) 93 full_link = os.path.join(target, link)
85 if os.path.isdir(full_link) and utils.IsWindows(): 94 if os.path.isdir(full_link) and utils.IsWindows():
86 # It seems like python on Windows is treating pseudo symlinks to 95 # It seems like python on Windows is treating pseudo symlinks to
87 # directories as directories. 96 # directories as directories.
88 os.rmdir(full_link) 97 os.rmdir(full_link)
89 else: 98 else:
90 os.remove(full_link) 99 os.remove(full_link)
91 else: 100 else:
92 os.makedirs(target) 101 os.makedirs(target)
93 linked_names = {}; 102 linked_names = {};
94 for source in args[1:]: 103 for source in args[1:]:
95 # Assume the source directory is named ".../NAME/lib". 104 # Assume the source directory is named ".../NAME/lib".
96 split = source.split(':') 105 split = source.split(':')
97 name = None 106 name = None
98 if len(split) == 2: (source, name) = split 107 if len(split) == 2: (source, name) = split
99 108
100 (path, lib) = os.path.split(source) 109 (path, lib) = os.path.split(source)
101 if lib != 'lib': 110 if lib != 'lib':
102 path = source 111 path = source
103 # Remove any additional path components preceding NAME, if one wasn't 112 # Remove any additional path components preceding NAME, if one wasn't
104 # specified explicitly. 113 # specified explicitly.
105 if not name: (_, name) = os.path.split(path) 114 if not name: (_, name) = os.path.split(path)
106 # We have an issue with left-behind checkouts in third_party/pkg and 115 # We have an issue with left-behind checkouts in third_party/pkg and
107 # third_party/pkg_tested when we move entries in DEPS. This reports them. 116 # third_party/pkg_tested when we move entries in DEPS. This reports them.
108 if name in linked_names: 117 if name in linked_names:
109 print 'Duplicate directory %s is linked to both %s and %s.' % ( 118 print 'Duplicate directory %s is linked to both %s and %s.' % (
110 name, linked_names[name], path) 119 name, linked_names[name], path)
111 if name in old_directories: 120 if name in old_directories:
112 print old_directories[name] 121 print old_directories[name]
113 return 1 122 return 1
114 linked_names[name] = path 123 linked_names[name] = path
115 orig_source = source 124 orig_source = source
116 if utils.GuessOS() == 'win32': 125 if utils.GuessOS() == 'win32':
117 source = os.path.relpath(source) 126 source = os.path.relpath(source)
118 else: 127 else:
119 source = os.path.relpath(source, start=target) 128 source = os.path.relpath(source, start=target)
120 exit_code = make_link(source, os.path.join(target, name), orig_source) 129 exit_code = make_link(
130 options.quiet, source, os.path.join(target, name), orig_source)
121 if exit_code != 0: 131 if exit_code != 0:
122 return exit_code 132 return exit_code
123 create_timestamp_file(options) 133 create_timestamp_file(options)
124 return 0 134 return 0
125 135
126 136
127 if __name__ == '__main__': 137 if __name__ == '__main__':
128 sys.exit(main(sys.argv)) 138 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « tools/list_pkg_directories.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698