Commit 4ff922af authored by maruel@chromium.org's avatar maruel@chromium.org

Remove gcl.ChangeInfo dependency in presubmit_support.py.

TEST=none
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18309 0039d316-1c4b-4281-b951-d872f2087c98
parent 07f0186d
...@@ -173,7 +173,7 @@ class InputApi(object): ...@@ -173,7 +173,7 @@ class InputApi(object):
"""Builds an InputApi object. """Builds an InputApi object.
Args: Args:
change: A presubmit.GclChange object. change: A presubmit.Change object.
presubmit_path: The path to the presubmit script being processed. presubmit_path: The path to the presubmit script being processed.
is_committing: True if the change is about to be committed. is_committing: True if the change is about to be committed.
""" """
...@@ -360,7 +360,7 @@ class AffectedFile(object): ...@@ -360,7 +360,7 @@ class AffectedFile(object):
def __init__(self, path, action, repository_root=''): def __init__(self, path, action, repository_root=''):
self._path = path self._path = path
self._action = action self._action = action
self._repository_root = repository_root self._local_root = repository_root
self._is_directory = None self._is_directory = None
self._properties = {} self._properties = {}
self.scm = '' self.scm = ''
...@@ -380,7 +380,7 @@ class AffectedFile(object): ...@@ -380,7 +380,7 @@ class AffectedFile(object):
def AbsoluteLocalPath(self): def AbsoluteLocalPath(self):
"""Returns the absolute path of this file on the local disk. """Returns the absolute path of this file on the local disk.
""" """
return normpath(os.path.join(self._repository_root, self.LocalPath())) return normpath(os.path.join(self._local_root, self.LocalPath()))
def IsDirectory(self): def IsDirectory(self):
"""Returns true if this object is a directory.""" """Returns true if this object is a directory."""
...@@ -489,7 +489,7 @@ class SvnAffectedFile(AffectedFile): ...@@ -489,7 +489,7 @@ class SvnAffectedFile(AffectedFile):
return self._is_text_file return self._is_text_file
class GclChange(object): class Change(object):
"""Describe a change. """Describe a change.
Used directly by the presubmit scripts to query the current change being Used directly by the presubmit scripts to query the current change being
...@@ -500,24 +500,27 @@ class GclChange(object): ...@@ -500,24 +500,27 @@ class GclChange(object):
self.KEY: equivalent to tags['KEY'] self.KEY: equivalent to tags['KEY']
""" """
_AFFECTED_FILES = AffectedFile
# Matches key/value (or "tag") lines in changelist descriptions. # Matches key/value (or "tag") lines in changelist descriptions.
_tag_line_re = re.compile( _TAG_LINE_RE = re.compile(
'^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$') '^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$')
def __init__(self, change_info): def __init__(self, name, description, local_root, files, issue, patchset):
# Do not keep a reference to the original change_info. if files is None:
self._name = change_info.name files = []
self._full_description = change_info.description self._name = name
self._repository_root = change_info.GetLocalRoot() self._full_description = description
self.issue = change_info.issue self._local_root = local_root
self.patchset = change_info.patchset self.issue = issue
self.patchset = patchset
# From the description text, build up a dictionary of key/value pairs # From the description text, build up a dictionary of key/value pairs
# plus the description minus all key/value or "tag" lines. # plus the description minus all key/value or "tag" lines.
self._description_without_tags = [] self._description_without_tags = []
self.tags = {} self.tags = {}
for line in self._full_description.splitlines(): for line in self._full_description.splitlines():
m = self._tag_line_re.match(line) m = self._TAG_LINE_RE.match(line)
if m: if m:
self.tags[m.group('key')] = m.group('value') self.tags[m.group('key')] = m.group('value')
else: else:
...@@ -528,8 +531,8 @@ class GclChange(object): ...@@ -528,8 +531,8 @@ class GclChange(object):
self._description_without_tags = self._description_without_tags.rstrip() self._description_without_tags = self._description_without_tags.rstrip()
self._affected_files = [ self._affected_files = [
SvnAffectedFile(info[1], info[0].strip(), self._repository_root) self._AFFECTED_FILES(info[1], info[0].strip(), self._local_root)
for info in change_info.GetFiles() for info in files
] ]
def Name(self): def Name(self):
...@@ -553,7 +556,7 @@ class GclChange(object): ...@@ -553,7 +556,7 @@ class GclChange(object):
"""Returns the repository (checkout) root directory for this change, """Returns the repository (checkout) root directory for this change,
as an absolute path. as an absolute path.
""" """
return self._repository_root return self._local_root
def __getattr__(self, attr): def __getattr__(self, attr):
"""Return tags directly as attributes on the object.""" """Return tags directly as attributes on the object."""
...@@ -622,6 +625,10 @@ class GclChange(object): ...@@ -622,6 +625,10 @@ class GclChange(object):
self.AffectedFiles(include_deletes=False))) self.AffectedFiles(include_deletes=False)))
class SvnChange(Change):
_AFFECTED_FILES = SvnAffectedFile
def ListRelevantPresubmitFiles(files, root): def ListRelevantPresubmitFiles(files, root):
"""Finds all presubmit files that apply to a given set of source files. """Finds all presubmit files that apply to a given set of source files.
...@@ -648,14 +655,13 @@ def ListRelevantPresubmitFiles(files, root): ...@@ -648,14 +655,13 @@ def ListRelevantPresubmitFiles(files, root):
class PresubmitExecuter(object): class PresubmitExecuter(object):
def __init__(self, change_info, committing): def __init__(self, change, committing):
""" """
Args: Args:
change_info: The gcl.ChangeInfo object for the change. change: The Change object.
committing: True if 'gcl commit' is running, False if 'gcl upload' is. committing: True if 'gcl commit' is running, False if 'gcl upload' is.
""" """
# TODO(maruel): Determine the SCM. self.change = change
self.change = GclChange(change_info)
self.committing = committing self.committing = committing
def ExecPresubmitScript(self, script_text, presubmit_path): def ExecPresubmitScript(self, script_text, presubmit_path):
...@@ -697,7 +703,7 @@ class PresubmitExecuter(object): ...@@ -697,7 +703,7 @@ class PresubmitExecuter(object):
return result return result
def DoPresubmitChecks(change_info, def DoPresubmitChecks(change,
committing, committing,
verbose, verbose,
output_stream, output_stream,
...@@ -714,7 +720,7 @@ def DoPresubmitChecks(change_info, ...@@ -714,7 +720,7 @@ def DoPresubmitChecks(change_info,
when needed. when needed.
Args: Args:
change_info: The gcl.ChangeInfo object for the change. change: The Change object.
committing: True if 'gcl commit' is running, False if 'gcl upload' is. committing: True if 'gcl commit' is running, False if 'gcl upload' is.
verbose: Prints debug info. verbose: Prints debug info.
output_stream: A stream to write output from presubmit tests to. output_stream: A stream to write output from presubmit tests to.
...@@ -725,16 +731,16 @@ def DoPresubmitChecks(change_info, ...@@ -725,16 +731,16 @@ def DoPresubmitChecks(change_info,
Return: Return:
True if execution can continue, False if not. True if execution can continue, False if not.
""" """
presubmit_files = ListRelevantPresubmitFiles(change_info.GetFileNames(), presubmit_files = ListRelevantPresubmitFiles(change.AbsoluteLocalPaths(True),
change_info.GetLocalRoot()) change.RepositoryRoot())
if not presubmit_files and verbose: if not presubmit_files and verbose:
output_stream.write("Warning, no presubmit.py found.\n") output_stream.write("Warning, no presubmit.py found.\n")
results = [] results = []
executer = PresubmitExecuter(change_info, committing) executer = PresubmitExecuter(change, committing)
if default_presubmit: if default_presubmit:
if verbose: if verbose:
output_stream.write("Running default presubmit script.\n") output_stream.write("Running default presubmit script.\n")
fake_path = os.path.join(change_info.GetLocalRoot(), 'PRESUBMIT.py') fake_path = os.path.join(change.RepositoryRoot(), 'PRESUBMIT.py')
results += executer.ExecPresubmitScript(default_presubmit, fake_path) results += executer.ExecPresubmitScript(default_presubmit, fake_path)
for filename in presubmit_files: for filename in presubmit_files:
filename = os.path.abspath(filename) filename = os.path.abspath(filename)
...@@ -805,18 +811,33 @@ def Main(argv): ...@@ -805,18 +811,33 @@ def Main(argv):
help="Act recursively") help="Act recursively")
parser.add_option("-v", "--verbose", action="store_true", parser.add_option("-v", "--verbose", action="store_true",
help="Verbose output") help="Verbose output")
parser.add_option("--files", default='')
parser.add_option("--name", default='no name')
parser.add_option("--description", default='')
parser.add_option("--issue", type='int', default=0)
parser.add_option("--patchset", type='int', default=0)
parser.add_options("--root", default='')
parser.add_options("--default_presubmit", default='')
parser.add_options("--may_prompt", action='store_true')
options, args = parser.parse_args(argv[1:]) options, args = parser.parse_args(argv[1:])
files = ParseFiles(args, options.recursive) if not options.files:
options.files = ParseFiles(args, options.recursive)
if not options.root:
options.root = gcl.GetRepositoryRoot()
if options.verbose: if options.verbose:
print "Found %d files." % len(files) print "Found %d files." % len(files)
return not DoPresubmitChecks(gcl.ChangeInfo('No name', 0, 0, '', files, return not DoPresubmitChecks(SvnChange(options.name,
gcl.GetRepositoryRoot()), options.description,
options.root,
options.files,
options.issue,
options.patchset),
options.commit, options.commit,
options.verbose, options.verbose,
sys.stdout, sys.stdout,
sys.stdin, sys.stdin,
None, options.default_presubmit,
False) options.may_prompt)
if __name__ == '__main__': if __name__ == '__main__':
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment