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

Side by Side Diff: gclient_utils.py

Issue 1156743008: Add experimental support for python in 'git cl format' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 6 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 | « .style.yapf ('k') | git_cache.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """Generic utils.""" 5 """Generic utils."""
6 6
7 import codecs 7 import codecs
8 import cStringIO 8 import cStringIO
9 import datetime 9 import datetime
10 import logging 10 import logging
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 """Returns the full path to the buildtools directory. 691 """Returns the full path to the buildtools directory.
692 This is based on the root of the checkout containing the current directory.""" 692 This is based on the root of the checkout containing the current directory."""
693 693
694 # Overriding the build tools path by environment is highly unsupported and may 694 # Overriding the build tools path by environment is highly unsupported and may
695 # break without warning. Do not rely on this for anything important. 695 # break without warning. Do not rely on this for anything important.
696 override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH') 696 override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')
697 if override is not None: 697 if override is not None:
698 return override 698 return override
699 699
700 primary_solution = GetPrimarySolutionPath() 700 primary_solution = GetPrimarySolutionPath()
701 if not primary_solution:
702 return None
701 buildtools_path = os.path.join(primary_solution, 'buildtools') 703 buildtools_path = os.path.join(primary_solution, 'buildtools')
702 if not os.path.exists(buildtools_path): 704 if not os.path.exists(buildtools_path):
703 # Buildtools may be in the gclient root. 705 # Buildtools may be in the gclient root.
704 gclient_root = FindGclientRoot(os.getcwd()) 706 gclient_root = FindGclientRoot(os.getcwd())
705 buildtools_path = os.path.join(gclient_root, 'buildtools') 707 buildtools_path = os.path.join(gclient_root, 'buildtools')
706 return buildtools_path 708 return buildtools_path
707 709
708 710
709 def GetBuildtoolsPlatformBinaryPath(): 711 def GetBuildtoolsPlatformBinaryPath():
710 """Returns the full path to the binary directory for the current platform.""" 712 """Returns the full path to the binary directory for the current platform."""
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 1166
1165 # (Windows) Query 'NUMBER_OF_PROCESSORS' environment variable. 1167 # (Windows) Query 'NUMBER_OF_PROCESSORS' environment variable.
1166 if 'NUMBER_OF_PROCESSORS' in os.environ: 1168 if 'NUMBER_OF_PROCESSORS' in os.environ:
1167 return int(os.environ['NUMBER_OF_PROCESSORS']) 1169 return int(os.environ['NUMBER_OF_PROCESSORS'])
1168 except Exception as e: 1170 except Exception as e:
1169 logging.exception("Exception raised while probing CPU count: %s", e) 1171 logging.exception("Exception raised while probing CPU count: %s", e)
1170 1172
1171 logging.debug('Failed to get CPU count. Defaulting to 1.') 1173 logging.debug('Failed to get CPU count. Defaulting to 1.')
1172 return 1 1174 return 1
1173 1175
1176
1174 def DefaultDeltaBaseCacheLimit(): 1177 def DefaultDeltaBaseCacheLimit():
1175 """Return a reasonable default for the git config core.deltaBaseCacheLimit. 1178 """Return a reasonable default for the git config core.deltaBaseCacheLimit.
1176 1179
1177 The primary constraint is the address space of virtual memory. The cache 1180 The primary constraint is the address space of virtual memory. The cache
1178 size limit is per-thread, and 32-bit systems can hit OOM errors if this 1181 size limit is per-thread, and 32-bit systems can hit OOM errors if this
1179 parameter is set too high. 1182 parameter is set too high.
1180 """ 1183 """
1181 if platform.architecture()[0].startswith('64'): 1184 if platform.architecture()[0].startswith('64'):
1182 return '2g' 1185 return '2g'
1183 else: 1186 else:
1184 return '512m' 1187 return '512m'
1185 1188
1189
1186 def DefaultIndexPackConfig(url=''): 1190 def DefaultIndexPackConfig(url=''):
1187 """Return reasonable default values for configuring git-index-pack. 1191 """Return reasonable default values for configuring git-index-pack.
1188 1192
1189 Experiments suggest that higher values for pack.threads don't improve 1193 Experiments suggest that higher values for pack.threads don't improve
1190 performance.""" 1194 performance."""
1191 cache_limit = DefaultDeltaBaseCacheLimit() 1195 cache_limit = DefaultDeltaBaseCacheLimit()
1192 result = ['-c', 'core.deltaBaseCacheLimit=%s' % cache_limit] 1196 result = ['-c', 'core.deltaBaseCacheLimit=%s' % cache_limit]
1193 if url in THREADED_INDEX_PACK_BLACKLIST: 1197 if url in THREADED_INDEX_PACK_BLACKLIST:
1194 result.extend(['-c', 'pack.threads=1']) 1198 result.extend(['-c', 'pack.threads=1'])
1195 return result 1199 return result
1200
1201
1202 def FindExecutable(executable):
1203 """This mimics the "which" utility."""
1204 path_folders = os.environ.get('PATH').split(os.pathsep)
1205
1206 for path_folder in path_folders:
1207 target = os.path.join(path_folder, executable)
1208 # Just incase we have some ~/blah paths.
1209 target = os.path.abspath(os.path.expanduser(target))
1210 if os.path.isfile(target) and os.access(target, os.X_OK):
1211 return target
1212 if sys.platform.startswith('win'):
1213 for suffix in ('.bat', '.cmd', '.exe'):
1214 alt_target = target + suffix
1215 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK):
1216 return alt_target
1217 return None
OLDNEW
« no previous file with comments | « .style.yapf ('k') | git_cache.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698