OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
6 | 6 |
7 import collections | 7 import collections |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import posixpath | 10 import posixpath |
11 import re | 11 import re |
12 import shutil | |
12 import sys | 13 import sys |
14 import tarfile | |
13 import tempfile | 15 import tempfile |
14 import threading | 16 import threading |
15 import time | 17 import time |
18 import urlparse | |
16 | 19 |
20 import download_from_google_storage | |
17 import gclient_utils | 21 import gclient_utils |
18 import scm | 22 import scm |
19 import subprocess2 | 23 import subprocess2 |
20 | 24 |
21 | 25 |
22 THIS_FILE_PATH = os.path.abspath(__file__) | 26 THIS_FILE_PATH = os.path.abspath(__file__) |
23 | 27 |
28 GSUTIL_DEFAULT_PATH = os.path.join( | |
29 os.path.dirname(os.path.abspath(__file__)), | |
30 'third_party', 'gsutil', 'gsutil') | |
31 | |
24 | 32 |
25 class DiffFiltererWrapper(object): | 33 class DiffFiltererWrapper(object): |
26 """Simple base class which tracks which file is being diffed and | 34 """Simple base class which tracks which file is being diffed and |
27 replaces instances of its file name in the original and | 35 replaces instances of its file name in the original and |
28 working copy lines of the svn/git diff output.""" | 36 working copy lines of the svn/git diff output.""" |
29 index_string = None | 37 index_string = None |
30 original_prefix = "--- " | 38 original_prefix = "--- " |
31 working_prefix = "+++ " | 39 working_prefix = "+++ " |
32 | 40 |
33 def __init__(self, relpath): | 41 def __init__(self, relpath): |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1163 except (gclient_utils.Error, subprocess2.CalledProcessError): | 1171 except (gclient_utils.Error, subprocess2.CalledProcessError): |
1164 if options.reset and options.delete_unversioned_trees: | 1172 if options.reset and options.delete_unversioned_trees: |
1165 print 'Removing troublesome path %s' % self.checkout_path | 1173 print 'Removing troublesome path %s' % self.checkout_path |
1166 gclient_utils.rmtree(self.checkout_path) | 1174 gclient_utils.rmtree(self.checkout_path) |
1167 exists = False | 1175 exists = False |
1168 else: | 1176 else: |
1169 msg = ('Can\'t update/checkout %s if an unversioned directory is ' | 1177 msg = ('Can\'t update/checkout %s if an unversioned directory is ' |
1170 'present. Delete the directory and try again.') | 1178 'present. Delete the directory and try again.') |
1171 raise gclient_utils.Error(msg % self.checkout_path) | 1179 raise gclient_utils.Error(msg % self.checkout_path) |
1172 | 1180 |
1181 BASE_URLS = { | |
1182 '/chrome/trunk/src': { | |
1183 'gs_path': '/chromium-svn-checkout/chrome/' | |
cmp
2013/12/26 19:25:45
Prepend gs:/ to this and on line 1186.
hinoka
2014/01/07 00:57:25
Done.
| |
1184 }, | |
1185 '/blink/trunk' : { | |
1186 'gs_path': '/chromium-svn-checkout/blink/' | |
1187 } | |
1188 } | |
1173 if not exists: | 1189 if not exists: |
1190 try: | |
1191 # Split out the revision number, its not useful for us. | |
cmp
2013/12/26 19:25:45
number, its -> number since it's
hinoka
2014/01/07 00:57:25
Done.
| |
1192 base_path = urlparse.urlparse(url).path.split('@')[0] | |
1193 if ('CHROME_HEADLESS' in os.environ | |
1194 and sys.platform == 'linux2' # TODO(hinoka): Enable for win/mac. | |
1195 and base_path in BASE_URLS): | |
1196 # Use a tarball for initial sync if we are on a bot. | |
1197 # Get an unauthenticated gsutil instance. | |
1198 gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH, | |
1199 boto_path=os.devnull) | |
cmp
2013/12/26 19:25:45
Indent needs to be fixed. It would be better as:
hinoka
2014/01/07 00:57:25
Done.
| |
1200 | |
1201 entry = BASE_URLS[base_path] | |
1202 gs_path = entry['gs_path'] | |
1203 _, out, _ = gsutil.check_call('ls', 'gs:/%s' % gs_path) | |
cmp
2013/12/26 19:25:45
Just use gs_path here (no string shenanigans req'd
hinoka
2014/01/07 00:57:25
Done.
| |
1204 # So that we can get the most recent revision. | |
1205 sorted_items = sorted(out.splitlines()) | |
1206 latest_checkout = sorted_items[-1] | |
1207 | |
1208 tempdir = tempfile.mkdtemp() | |
1209 print 'Downloading %s...' % latest_checkout | |
1210 code, out, err = gsutil.check_call('cp', latest_checkout, tempdir) | |
1211 if code: | |
1212 print '%s\n%s' % (out, err) | |
1213 raise Exception() | |
1214 filename = latest_checkout.split('/')[-1] | |
1215 tarball = os.path.join(tempdir, filename) | |
1216 print 'Unpacking into %s...' % self.checkout_path | |
1217 with tarfile.open(tarball, 'r:gz') as f: | |
1218 f.extractall(self.checkout_path) | |
cmp
2013/12/26 19:25:45
Use a local executable to unpack rather than Pytho
hinoka
2014/01/07 00:57:25
This would make gclient_scm pretty unportable :(
T
cmp
2014/01/07 01:09:52
You're assuming too much about how well an in-proc
hinoka
2014/01/07 02:03:32
How big of a tarball and what sort of problems are
| |
1219 print 'Deleting temp file' | |
1220 shutil.rmtree(tempdir) | |
cmp
2014/01/07 01:09:52
We found rmtree() to cause problems on Windows. W
hinoka
2014/01/07 02:03:32
Just realized gclient_utils.rmtree does exactly wh
| |
1221 | |
1222 # Rewrite the repository root to match. | |
1223 tarball_url = scm.SVN.CaptureLocalInfo( | |
1224 ['.'], self.checkout_path)['Repository Root'] | |
1225 tarball_parsed = urlparse.urlparse(tarball_url) | |
1226 tarball_root = '%s://%s' % (tarball_parsed.scheme, | |
1227 tarball_parsed.netloc) | |
1228 local_parsed = urlparse.urlparse(url) | |
1229 local_root = '%s://%s' % (local_parsed.scheme, local_parsed.netloc) | |
1230 | |
1231 if tarball_root != local_root: | |
1232 print 'Switching repository root to %s' % local_root | |
1233 self._Run(['switch', '--relocate', tarball_root, | |
1234 local_root, self.checkout_path], | |
cmp
2013/12/26 19:25:45
Indent needs to be less one character on line 1234
hinoka
2014/01/07 00:57:25
Done.
| |
1235 options) | |
1236 except Exception as e: | |
1237 print 'We tried to get a source tarball but failed.' | |
1238 print 'Resuming normal operations.' | |
1239 print str(e) | |
1240 | |
1174 gclient_utils.safe_makedirs(os.path.dirname(self.checkout_path)) | 1241 gclient_utils.safe_makedirs(os.path.dirname(self.checkout_path)) |
1175 # We need to checkout. | 1242 # We need to checkout. |
1176 command = ['checkout', url, self.checkout_path] | 1243 command = ['checkout', url, self.checkout_path] |
1177 command = self._AddAdditionalUpdateFlags(command, options, revision) | 1244 command = self._AddAdditionalUpdateFlags(command, options, revision) |
1178 self._RunAndGetFileList(command, options, file_list, self._root_dir) | 1245 self._RunAndGetFileList(command, options, file_list, self._root_dir) |
1179 return self.Svnversion() | 1246 return self.Svnversion() |
1180 | 1247 |
1181 if not managed: | 1248 if not managed: |
1182 print ('________ unmanaged solution; skipping %s' % self.relpath) | 1249 print ('________ unmanaged solution; skipping %s' % self.relpath) |
1183 return self.Svnversion() | 1250 return self.Svnversion() |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1452 new_command.append('--force') | 1519 new_command.append('--force') |
1453 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1520 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1454 new_command.extend(('--accept', 'theirs-conflict')) | 1521 new_command.extend(('--accept', 'theirs-conflict')) |
1455 elif options.manually_grab_svn_rev: | 1522 elif options.manually_grab_svn_rev: |
1456 new_command.append('--force') | 1523 new_command.append('--force') |
1457 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1524 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1458 new_command.extend(('--accept', 'postpone')) | 1525 new_command.extend(('--accept', 'postpone')) |
1459 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1526 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1460 new_command.extend(('--accept', 'postpone')) | 1527 new_command.extend(('--accept', 'postpone')) |
1461 return new_command | 1528 return new_command |
OLD | NEW |