Make breakpad, gcl and presubmit_support dependencies optional

TEST=unit tests

Review URL: http://codereview.chromium.org/503068

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35072 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent 1811135923
commit ea8c1a9bc9

@ -881,6 +881,18 @@ def TryChange(change_info, args, swallow_exception):
return path return path
trychange_args = [] trychange_args = []
settings = {
'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'),
'host': GetCodeReviewSetting('TRYSERVER_HTTP_HOST'),
'svn_repo': GetCodeReviewSetting('TRYSERVER_SVN_URL'),
'project': GetCodeReviewSetting('TRYSERVER_PROJECT'),
'root': GetCodeReviewSetting('TRYSERVER_ROOT'),
'patchlevel': GetCodeReviewSetting('TRYSERVER_PATCHLEVEL'),
}
for (k, v) in settings.iteritems():
if v:
trychange_args.extend(['--' + k, v])
gclient_root = FindGclientRootDir(GetRepositoryRoot()) gclient_root = FindGclientRootDir(GetRepositoryRoot())
if gclient_root: if gclient_root:
trychange_args.extend(['--root', PathDifference(gclient_root, trychange_args.extend(['--root', PathDifference(gclient_root,

@ -35,15 +35,19 @@ class CheckCallError(OSError):
self.stdout = stdout self.stdout = stdout
def CheckCall(command, cwd=None): def CheckCall(command, cwd=None, print_error=True):
"""Like subprocess.check_call() but returns stdout. """Like subprocess.check_call() but returns stdout.
Works on python 2.4 Works on python 2.4
""" """
try: try:
stderr = None
if not print_error:
stderr = subprocess.PIPE
process = subprocess.Popen(command, cwd=cwd, process = subprocess.Popen(command, cwd=cwd,
shell=sys.platform.startswith('win'), shell=sys.platform.startswith('win'),
stdout=subprocess.PIPE) stdout=subprocess.PIPE,
stderr=stderr)
output = process.communicate()[0] output = process.communicate()[0]
except OSError, e: except OSError, e:
raise CheckCallError(command, cwd, errno, None) raise CheckCallError(command, cwd, errno, None)

@ -35,11 +35,11 @@ class TryChangeUnittest(TryChangeTestsBase):
"""General trychange.py tests.""" """General trychange.py tests."""
def testMembersChanged(self): def testMembersChanged(self):
members = [ members = [
'EscapeDot', 'GIT', 'GetTryServerSettings', 'GuessVCS', 'EscapeDot', 'GIT', 'GuessVCS',
'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess',
'SCM', 'SVN', 'TryChange', 'USAGE', 'breakpad', 'SCM', 'SVN', 'TryChange', 'USAGE',
'datetime', 'gcl', 'gclient_utils', 'getpass', 'logging', 'breakpad', 'datetime', 'gclient_utils', 'getpass', 'logging',
'optparse', 'os', 'presubmit_support', 'scm', 'shutil', 'socket', 'optparse', 'os', 'scm', 'shutil', 'socket',
'subprocess', 'sys', 'tempfile', 'urllib', 'subprocess', 'sys', 'tempfile', 'urllib',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
@ -50,7 +50,7 @@ class SVNUnittest(TryChangeTestsBase):
"""trychange.SVN tests.""" """trychange.SVN tests."""
def testMembersChanged(self): def testMembersChanged(self):
members = [ members = [
'GetFileNames', 'GetLocalRoot', 'GetBots', 'GetFileNames', 'GetLocalRoot',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(trychange.SVN, members) self.compareMembers(trychange.SVN, members)
@ -74,7 +74,7 @@ class GITUnittest(TryChangeTestsBase):
"""trychange.GIT tests.""" """trychange.GIT tests."""
def testMembersChanged(self): def testMembersChanged(self):
members = [ members = [
'GetFileNames', 'GetLocalRoot', 'GetBots', 'GetFileNames', 'GetLocalRoot',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(trychange.GIT, members) self.compareMembers(trychange.GIT, members)

@ -19,12 +19,13 @@ import sys
import tempfile import tempfile
import urllib import urllib
import breakpad try:
import breakpad
except ImportError:
pass
import gcl
import gclient_utils import gclient_utils
import scm import scm
import presubmit_support
__version__ = '1.2' __version__ = '1.2'
@ -65,38 +66,6 @@ class NoTryServerAccess(Exception):
return self.args[0] + '\n' + HELP_STRING return self.args[0] + '\n' + HELP_STRING
def GetTryServerSettings():
"""Grab try server settings local to the repository."""
def _SafeResolve(host):
try:
return socket.getaddrinfo(host, None)
except socket.gaierror:
return None
settings = {}
settings['http_port'] = gcl.GetCodeReviewSetting('TRYSERVER_HTTP_PORT')
settings['http_host'] = gcl.GetCodeReviewSetting('TRYSERVER_HTTP_HOST')
settings['svn_repo'] = gcl.GetCodeReviewSetting('TRYSERVER_SVN_URL')
settings['default_project'] = gcl.GetCodeReviewSetting('TRYSERVER_PROJECT')
settings['default_root'] = gcl.GetCodeReviewSetting('TRYSERVER_ROOT')
# Pick a patchlevel, default to 0.
default_patchlevel = gcl.GetCodeReviewSetting('TRYSERVER_PATCHLEVEL')
if default_patchlevel:
default_patchlevel = int(default_patchlevel)
else:
default_patchlevel = 0
settings['default_patchlevel'] = default_patchlevel
# Use http is the http_host name resolve, fallback to svn otherwise.
if (settings['http_port'] and settings['http_host'] and
_SafeResolve(settings['http_host'])):
settings['default_transport'] = 'http'
elif settings.get('svn_repo'):
settings['default_transport'] = 'svn'
return settings
def EscapeDot(name): def EscapeDot(name):
return name.replace('.', '-') return name.replace('.', '-')
@ -143,6 +112,17 @@ class SVN(SCM):
"""Return the path of the repository root.""" """Return the path of the repository root."""
return self.checkout_root return self.checkout_root
def GetBots(self):
try:
import gcl
return gcl.GetCachedFile('PRESUBMIT.py', use_root=True)
except ImportError:
try:
return gclient_utils.FileRead(os.path.join(self.checkout_root,
'PRESUBMIT.py'))
except OSError:
return None
class GIT(SCM): class GIT(SCM):
"""Gathers the options and diff for a git checkout.""" """Gathers the options and diff for a git checkout."""
@ -184,6 +164,13 @@ class GIT(SCM):
"""Return the path of the repository root.""" """Return the path of the repository root."""
return self.checkout_root return self.checkout_root
def GetBots(self):
try:
return gclient_utils.FileRead(os.path.join(self.checkout_root,
'PRESUBMIT.py'))
except OSError:
return None
def _ParseSendChangeOptions(options): def _ParseSendChangeOptions(options):
"""Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" """Parse common options passed to _SendChangeHTTP and _SendChangeSVN."""
@ -270,7 +257,7 @@ def _SendChangeSVN(options):
command = ['svn', 'checkout', '--depth', 'empty', '-q', command = ['svn', 'checkout', '--depth', 'empty', '-q',
options.svn_repo, temp_dir] options.svn_repo, temp_dir]
if options.email: if options.email:
command += ['--username', options.email] command.extend(['--username', options.email])
gclient_utils.CheckCall(command) gclient_utils.CheckCall(command)
# TODO(maruel): Use a subdirectory per user? # TODO(maruel): Use a subdirectory per user?
@ -281,7 +268,7 @@ def _SendChangeSVN(options):
full_url = options.svn_repo + '/' + file_name full_url = options.svn_repo + '/' + file_name
file_found = False file_found = False
try: try:
gclient_utils.CheckCall(['svn', 'ls', full_url]) gclient_utils.CheckCall(['svn', 'ls', full_url], print_error=False)
file_found = True file_found = True
except gclient_utils.CheckCallError: except gclient_utils.CheckCallError:
pass pass
@ -289,20 +276,17 @@ def _SendChangeSVN(options):
# The file already exists in the repo. Note that commiting a file is a # The file already exists in the repo. Note that commiting a file is a
# no-op if the file's content (the diff) is not modified. This is why # no-op if the file's content (the diff) is not modified. This is why
# the file name contains the date and time. # the file name contains the date and time.
gclient_utils.CheckCall(['svn', 'update', full_path]) gclient_utils.CheckCall(['svn', 'update', full_path],
f = open(full_path, 'wb') print_error=False)
f.write(options.diff) gclient_utils.FileWrite(full_path, options.diff, 'wb')
f.close()
else: else:
# Add the file to the repo # Add the file to the repo.
f = open(full_path, 'wb') gclient_utils.FileWrite(full_path, options.diff, 'wb')
f.write(options.diff) gclient_utils.CheckCall(["svn", "add", full_path], print_error=False)
f.close()
gclient_utils.CheckCall(["svn", "add", full_path])
temp_file.write(description) temp_file.write(description)
temp_file.flush() temp_file.flush()
gclient_utils.CheckCall(["svn", "commit", full_path, '--file', gclient_utils.CheckCall(["svn", "commit", full_path, '--file',
temp_file.name]) temp_file.name], print_error=False)
except gclient_utils.CheckCallError, e: except gclient_utils.CheckCallError, e:
raise NoTryServerAccess(' '.join(e.command) + '\nOuput:\n' + raise NoTryServerAccess(' '.join(e.command) + '\nOuput:\n' +
e.stdout) e.stdout)
@ -353,11 +337,6 @@ def TryChange(argv,
file_list: Default value to pass to --file. file_list: Default value to pass to --file.
swallow_exception: Whether we raise or swallow exceptions. swallow_exception: Whether we raise or swallow exceptions.
""" """
default_settings = GetTryServerSettings()
transport_functions = { 'http': _SendChangeHTTP, 'svn': _SendChangeSVN }
default_transport = transport_functions.get(
default_settings.get('default_transport'))
# Parse argv # Parse argv
parser = optparse.OptionParser(usage=USAGE, parser = optparse.OptionParser(usage=USAGE,
version=__version__, version=__version__,
@ -397,9 +376,8 @@ def TryChange(argv,
# "'release'" # "'release'"
group.add_option("--target", help=optparse.SUPPRESS_HELP) group.add_option("--target", help=optparse.SUPPRESS_HELP)
# TODO(bradnelson): help="Override which project to use" group.add_option("--project",
group.add_option("--project", help=optparse.SUPPRESS_HELP, help="Override which project to use")
default=default_settings['default_project'])
# Override the list of tests to run, use multiple times to list many tests # Override the list of tests to run, use multiple times to list many tests
# (or comma separated) # (or comma separated)
@ -418,11 +396,9 @@ def TryChange(argv,
help="Url where to grab a patch") help="Url where to grab a patch")
group.add_option("--root", group.add_option("--root",
help="Root to use for the patch; base subdirectory for " help="Root to use for the patch; base subdirectory for "
"patch created in a subdirectory", "patch created in a subdirectory")
default=default_settings["default_root"])
group.add_option("--patchlevel", type='int', metavar="LEVEL", group.add_option("--patchlevel", type='int', metavar="LEVEL",
help="Used as -pN parameter to patch", help="Used as -pN parameter to patch")
default=default_settings["default_patchlevel"])
parser.add_option_group(group) parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Access the try server by HTTP") group = optparse.OptionGroup(parser, "Access the try server by HTTP")
@ -430,13 +406,10 @@ def TryChange(argv,
action="store_const", action="store_const",
const=_SendChangeHTTP, const=_SendChangeHTTP,
dest="send_patch", dest="send_patch",
default=default_transport,
help="Use HTTP to talk to the try server [default]") help="Use HTTP to talk to the try server [default]")
group.add_option("--host", group.add_option("--host",
default=default_settings['http_host'],
help="Host address") help="Host address")
group.add_option("--port", group.add_option("--port",
default=default_settings['http_port'],
help="HTTP port") help="HTTP port")
group.add_option("--proxy", group.add_option("--proxy",
help="HTTP proxy") help="HTTP proxy")
@ -450,7 +423,6 @@ def TryChange(argv,
help="Use SVN to talk to the try server") help="Use SVN to talk to the try server")
group.add_option("--svn_repo", group.add_option("--svn_repo",
metavar="SVN_URL", metavar="SVN_URL",
default=default_settings['svn_repo'],
help="SVN url to use to write the changes in; --use_svn is " help="SVN url to use to write the changes in; --use_svn is "
"implied when using --svn_repo") "implied when using --svn_repo")
parser.add_option_group(group) parser.add_option_group(group)
@ -491,14 +463,22 @@ def TryChange(argv,
# Get try slaves from PRESUBMIT.py files if not specified. # Get try slaves from PRESUBMIT.py files if not specified.
if not options.bot: if not options.bot:
if options.url: # Even if the diff comes from options.url, use the local checkout for bot
parser.error('You need to specify which bots to use.') # selection.
root_presubmit = gcl.GetCachedFile('PRESUBMIT.py', use_root=True) try:
options.bot = presubmit_support.DoGetTrySlaves(options.scm.GetFileNames(), # Get try slaves from PRESUBMIT.py files if not specified.
options.scm.GetLocalRoot(), import presubmit_support
root_presubmit, root_presubmit = options.scm.GetBots()
False, options.bot = presubmit_support.DoGetTrySlaves(
sys.stdout) options.scm.GetFileNames(),
options.scm.GetLocalRoot(),
root_presubmit,
False,
sys.stdout)
except ImportError:
pass
# If no bot is specified, either the default pool will be selected or the
# try server will refuse the job. Either case we don't need to interfere.
if options.name is None: if options.name is None:
if options.issue: if options.issue:

Loading…
Cancel
Save