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

Side by Side Diff: depot_tools/win_toolchain/toolchain2013.py

Issue 136793018: Fix presubmit errors in toolchain2013, so that cq works for depot_tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extracts a Windows VS2013 toolchain from various downloadable pieces.""" 6 """Extracts a Windows VS2013 toolchain from various downloadable pieces."""
7 7
8 8
9 import ctypes 9 import ctypes
10 import optparse 10 import optparse
(...skipping 19 matching lines...) Expand all
30 30
31 31
32 def RunOrDie(command): 32 def RunOrDie(command):
33 subprocess.check_call(command, shell=True) 33 subprocess.check_call(command, shell=True)
34 34
35 35
36 def TempDir(): 36 def TempDir():
37 """Generates a temporary directory (for downloading or extracting to) and keep 37 """Generates a temporary directory (for downloading or extracting to) and keep
38 track of the directory that's created for cleaning up later. 38 track of the directory that's created for cleaning up later.
39 """ 39 """
40 global g_temp_dirs
41 temp = tempfile.mkdtemp() 40 temp = tempfile.mkdtemp()
42 g_temp_dirs.append(temp) 41 g_temp_dirs.append(temp)
43 return temp 42 return temp
44 43
45 44
46 def DeleteAllTempDirs(): 45 def DeleteAllTempDirs():
47 """Removes all temporary directories created by |TempDir()|.""" 46 """Removes all temporary directories created by |TempDir()|."""
48 global g_temp_dirs 47 global g_temp_dirs
49 if g_temp_dirs: 48 if g_temp_dirs:
50 sys.stdout.write('Cleaning up temporaries...\n') 49 sys.stdout.write('Cleaning up temporaries...\n')
(...skipping 19 matching lines...) Expand all
70 69
71 def Download(url, local_path): 70 def Download(url, local_path):
72 """Downloads a large-ish binary file and print some status information while 71 """Downloads a large-ish binary file and print some status information while
73 doing so. 72 doing so.
74 """ 73 """
75 sys.stdout.write('Downloading %s...\n' % url) 74 sys.stdout.write('Downloading %s...\n' % url)
76 req = urllib2.urlopen(url) 75 req = urllib2.urlopen(url)
77 content_length = int(req.headers.get('Content-Length', 0)) 76 content_length = int(req.headers.get('Content-Length', 0))
78 bytes_read = 0L 77 bytes_read = 0L
79 terminator = '\r' if sys.stdout.isatty() else '\n' 78 terminator = '\r' if sys.stdout.isatty() else '\n'
80 with open(local_path, 'wb') as file: 79 with open(local_path, 'wb') as file_handle:
81 while True: 80 while True:
82 chunk = req.read(1024 * 1024) 81 chunk = req.read(1024 * 1024)
83 if not chunk: 82 if not chunk:
84 break 83 break
85 bytes_read += len(chunk) 84 bytes_read += len(chunk)
86 file.write(chunk) 85 file_handle.write(chunk)
87 sys.stdout.write('... %d/%d%s' % (bytes_read, content_length, terminator)) 86 sys.stdout.write('... %d/%d%s' % (bytes_read, content_length, terminator))
88 sys.stdout.flush() 87 sys.stdout.flush()
89 sys.stdout.write('\n') 88 sys.stdout.write('\n')
90 if content_length and content_length != bytes_read: 89 if content_length and content_length != bytes_read:
91 raise SystemExit('Got incorrect number of bytes downloading %s' % url) 90 raise SystemExit('Got incorrect number of bytes downloading %s' % url)
92 91
93 92
94 def ExtractIso(iso_path): 93 def ExtractIso(iso_path):
95 """Uses 7zip to extract the contents of the given .iso (or self-extracting 94 """Uses 7zip to extract the contents of the given .iso (or self-extracting
96 .exe). 95 .exe).
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 def CopyToFinalLocation(extracted_dirs, target_dir): 173 def CopyToFinalLocation(extracted_dirs, target_dir):
175 sys.stdout.write('Copying to final location...\n') 174 sys.stdout.write('Copying to final location...\n')
176 mappings = { 175 mappings = {
177 'Program Files\\Microsoft Visual Studio 12.0\\': '.\\', 176 'Program Files\\Microsoft Visual Studio 12.0\\': '.\\',
178 'System64\\': 'sys64\\', 177 'System64\\': 'sys64\\',
179 'System\\': 'sys32\\', 178 'System\\': 'sys32\\',
180 'Windows Kits\\8.0\\': 'win8sdk\\', 179 'Windows Kits\\8.0\\': 'win8sdk\\',
181 } 180 }
182 matches = [] 181 matches = []
183 for extracted_dir in extracted_dirs: 182 for extracted_dir in extracted_dirs:
184 for root, dirnames, filenames in os.walk(extracted_dir): 183 for root, _, filenames in os.walk(extracted_dir):
185 for filename in filenames: 184 for filename in filenames:
186 matches.append((extracted_dir, os.path.join(root, filename))) 185 matches.append((extracted_dir, os.path.join(root, filename)))
187 186
188 copies = [] 187 copies = []
189 for prefix, full_path in matches: 188 for prefix, full_path in matches:
190 # +1 for trailing \. 189 # +1 for trailing \.
191 partial_path = full_path[len(prefix) + 1:] 190 partial_path = full_path[len(prefix) + 1:]
192 for map_from, map_to in mappings.iteritems(): 191 for map_from, map_to in mappings.iteritems():
193 if partial_path.startswith(map_from): 192 if partial_path.startswith(map_from):
194 target_path = os.path.join(map_to, partial_path[len(map_from):]) 193 target_path = os.path.join(map_to, partial_path[len(map_from):])
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 parser.add_option('--targetdir', metavar='DIR', 257 parser.add_option('--targetdir', metavar='DIR',
259 help='put toolchain into DIR', 258 help='put toolchain into DIR',
260 default=os.path.join(BASEDIR, 'win_toolchain_2013')) 259 default=os.path.join(BASEDIR, 'win_toolchain_2013'))
261 parser.add_option('--noclean', action='store_false', dest='clean', 260 parser.add_option('--noclean', action='store_false', dest='clean',
262 help='do not remove temp files', 261 help='do not remove temp files',
263 default=True) 262 default=True)
264 parser.add_option('--local', metavar='DIR', 263 parser.add_option('--local', metavar='DIR',
265 help='use downloaded files from DIR') 264 help='use downloaded files from DIR')
266 parser.add_option('--express', 265 parser.add_option('--express',
267 help='use VS Express instead of Pro', action='store_true') 266 help='use VS Express instead of Pro', action='store_true')
268 options, args = parser.parse_args() 267 options, _ = parser.parse_args()
269 try: 268 try:
270 target_dir = os.path.abspath(options.targetdir) 269 target_dir = os.path.abspath(options.targetdir)
271 if os.path.exists(target_dir): 270 if os.path.exists(target_dir):
272 parser.error('%s already exists. Please [re]move it or use ' 271 parser.error('%s already exists. Please [re]move it or use '
273 '--targetdir to select a different target.\n' % 272 '--targetdir to select a different target.\n' %
274 target_dir) 273 target_dir)
275 # Set the working directory to 7z subdirectory. 7-zip doesn't find its 274 # Set the working directory to 7z subdirectory. 7-zip doesn't find its
276 # codec dll very well, so this is the simplest way to make sure it runs 275 # codec dll very well, so this is the simplest way to make sure it runs
277 # correctly, as we don't otherwise care about working directory. 276 # correctly, as we don't otherwise care about working directory.
278 os.chdir(os.path.join(BASEDIR, '7z')) 277 os.chdir(os.path.join(BASEDIR, '7z'))
279 image = GetSourceImage(options.local, not options.express) 278 image = GetSourceImage(options.local, not options.express)
280 extracted = ExtractComponents(image) 279 extracted = ExtractComponents(image)
281 CopyToFinalLocation(extracted, target_dir) 280 CopyToFinalLocation(extracted, target_dir)
282 281
283 GenerateSetEnvCmd(target_dir, not options.express) 282 GenerateSetEnvCmd(target_dir, not options.express)
284 finally: 283 finally:
285 if options.clean: 284 if options.clean:
286 DeleteAllTempDirs() 285 DeleteAllTempDirs()
287 286
288 287
289 if __name__ == '__main__': 288 if __name__ == '__main__':
290 sys.exit(main()) 289 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698