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

Side by Side Diff: tools/make_links.py

Issue 1746743002: Use checked-in .package file for building and testing (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Stop creating [build_dir]/packages Created 4 years, 3 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
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
11 the name of the target link. 11 the name of the target link.
12 12
13 If a SOURCE contains ":", the left side is the path and the right side is the 13 If a SOURCE contains ":", the left side is the path and the right side is the
14 name of the package symlink. 14 name of the package symlink.
15 15
16 Before creating any links, the old entries of the TARGET directory will be 16 Before creating any links, the old entries of the TARGET directory will be
17 removed. 17 removed.
18 18
19 Usage: 19 Usage:
20 python tools/make_links.py OPTIONS TARGET SOURCES... 20 python tools/make_links.py OPTIONS TARGET SOURCES...
21 21
22 """ 22 """
23 23
24 import optparse 24 import optparse
25 import os 25 import os
26 import shutil 26 import shutil
27 import subprocess 27 import subprocess
28 import sys 28 import sys
29 import urllib
30 import urlparse
29 import utils 31 import utils
30 32
31 # Useful messages when we find orphaned checkouts. 33 # Useful messages when we find orphaned checkouts.
32 old_directories = { 34 old_directories = {
33 'package_config': 'Please remove third_party/pkg/package_config.', 35 'package_config': 'Please remove third_party/pkg/package_config.',
34 'analyzer_cli': 'Please remove third_party/pkg/analyzer_cli.'} 36 'analyzer_cli': 'Please remove third_party/pkg/analyzer_cli.'}
35 37
36 def get_options(): 38 def get_options():
37 result = optparse.OptionParser() 39 result = optparse.OptionParser()
38 result.add_option("--timestamp_file", "", 40 result.add_option("--timestamp_file", "",
39 help='Create a timestamp file when done creating the links.', 41 help='Create a timestamp file when done creating the links.',
40 default='') 42 default='')
41 result.add_option("-q", "--quiet", 43 result.add_option("-q", "--quiet",
42 help="Don't print any messages", 44 help="Don't print any messages",
43 action="store_true", 45 action="store_true",
44 dest="quiet", 46 dest="quiet",
45 default=False) 47 default=False)
48 result.add_option("--create-links",
49 help='Create links to the package lib directories in "packages/".',
50 action='store_false',
51 default=True)
52 result.add_option("--create-package-file",
53 help='Create a ".packages" file pointing to the packages.',
54 action='store_false',
55 default=True)
56
46 return result.parse_args() 57 return result.parse_args()
47 58
48 def make_link(quiet, source, target, orig_source): 59 def make_link(quiet, source, target, orig_source):
49 if os.path.islink(target): 60 if os.path.islink(target):
50 if not quiet: 61 if not quiet:
51 print 'Removing %s' % target 62 print 'Removing %s' % target
52 sys.stdout.flush() 63 sys.stdout.flush()
53 os.unlink(target) 64 os.unlink(target)
54 65
55 if os.path.isdir(target): 66 if os.path.isdir(target):
(...skipping 18 matching lines...) Expand all
74 else: 85 else:
75 return subprocess.call(['ln', '-s', source, target]) 86 return subprocess.call(['ln', '-s', source, target])
76 87
77 def create_timestamp_file(options): 88 def create_timestamp_file(options):
78 if options.timestamp_file != '': 89 if options.timestamp_file != '':
79 dir_name = os.path.dirname(options.timestamp_file) 90 dir_name = os.path.dirname(options.timestamp_file)
80 if not os.path.exists(dir_name): 91 if not os.path.exists(dir_name):
81 os.mkdir(dir_name) 92 os.mkdir(dir_name)
82 open(options.timestamp_file, 'w').close() 93 open(options.timestamp_file, 'w').close()
83 94
84
85 def main(argv): 95 def main(argv):
86 (options, args) = get_options() 96 (options, args) = get_options()
87 target = os.path.relpath(args[0]) 97 target_dir = os.path.relpath(args[0])
88 if os.path.exists(target): 98 if options.create_links:
89 # If the packages directory already exists, delete the current links inside 99 target = os.path.join(target_dir, 'packages')
90 # it. This is necessary, otherwise we can end up having links in there 100 if os.path.exists(target):
91 # pointing to directories which no longer exist (on incremental builds). 101 # If the packages directory already exists, delete the current links in
92 for link in os.listdir(target): 102 # it. This is necessary, otherwise we can end up having links in there
93 full_link = os.path.join(target, link) 103 # pointing to directories which no longer exist (on incremental builds).
94 if os.path.isdir(full_link) and utils.IsWindows(): 104 for link in os.listdir(target):
95 # It seems like python on Windows is treating pseudo symlinks to 105 full_link = os.path.join(target, link)
96 # directories as directories. 106 if os.path.isdir(full_link) and utils.IsWindows():
97 os.rmdir(full_link) 107 # It seems like python on Windows is treating pseudo symlinks to
98 else: 108 # directories as directories.
99 os.remove(full_link) 109 os.rmdir(full_link)
100 else: 110 else:
101 os.makedirs(target) 111 os.remove(full_link)
112 else:
113 os.makedirs(target)
114
102 linked_names = {}; 115 linked_names = {};
116 package_file_contents = '# .package file created by tools/make_links.py\n'
103 for source in args[1:]: 117 for source in args[1:]:
104 # Assume the source directory is named ".../NAME/lib". 118 # Assume the source directory is named ".../NAME/lib".
105 split = source.split(':') 119 split = source.split(':')
106 name = None 120 name = None
107 if len(split) == 2: (source, name) = split 121 if len(split) == 2: (source, name) = split
108 122
109 (path, lib) = os.path.split(source) 123 (path, lib) = os.path.split(source)
110 if lib != 'lib': 124 if lib != 'lib':
111 path = source 125 path = source
112 # Remove any additional path components preceding NAME, if one wasn't 126 # Remove any additional path components preceding NAME, if one wasn't
113 # specified explicitly. 127 # specified explicitly.
114 if not name: (_, name) = os.path.split(path) 128 if not name: (_, name) = os.path.split(path)
115 # We have an issue with left-behind checkouts in third_party/pkg and 129 # We have an issue with left-behind checkouts in third_party/pkg and
116 # third_party/pkg_tested when we move entries in DEPS. This reports them. 130 # third_party/pkg_tested when we move entries in DEPS. This reports them.
117 if name in linked_names: 131 if name in linked_names:
118 print 'Duplicate directory %s is linked to both %s and %s.' % ( 132 print 'Duplicate directory %s is linked to both %s and %s.' % (
119 name, linked_names[name], path) 133 name, linked_names[name], path)
120 if name in old_directories: 134 if name in old_directories:
121 print old_directories[name] 135 print old_directories[name]
122 return 1 136 return 1
123 linked_names[name] = path 137 linked_names[name] = path
124 orig_source = source 138 orig_source = source
125 if utils.GuessOS() == 'win32': 139 if options.create_links:
126 source = os.path.relpath(source) 140 if utils.GuessOS() == 'win32':
127 else: 141 source = os.path.relpath(source)
128 source = os.path.relpath(source, start=target) 142 else:
129 exit_code = make_link( 143 source = os.path.relpath(source, start=target)
130 options.quiet, source, os.path.join(target, name), orig_source) 144 exit_code = make_link(options.quiet,
131 if exit_code != 0: 145 source, os.path.join(target, name), orig_source)
132 return exit_code 146 if exit_code != 0:
147 return exit_code
148 abs_source = os.path.abspath(orig_source)
149 source_url = urlparse.urljoin('file:', urllib.pathname2url(abs_source))
150 package_file_contents += '%s:%s\n' % (name, source_url)
151 if options.create_package_file:
152 with open(os.path.join(target_dir, '.packages'), 'w') as package_file:
153 package_file.write(package_file_contents)
133 create_timestamp_file(options) 154 create_timestamp_file(options)
134 return 0 155 return 0
135 156
136 157
137 if __name__ == '__main__': 158 if __name__ == '__main__':
138 sys.exit(main(sys.argv)) 159 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698