Commit 8b40a9b8 authored by maruel@chromium.org's avatar maruel@chromium.org

Fix ListRelevantPresubmitFiles().

It was affected by the current directory!

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@17554 0039d316-1c4b-4281-b951-d872f2087c98
parent 143993e9
...@@ -230,8 +230,9 @@ class InputApi(object): ...@@ -230,8 +230,9 @@ class InputApi(object):
dir_with_slash = normpath("%s/" % self.PresubmitLocalPath()) dir_with_slash = normpath("%s/" % self.PresubmitLocalPath())
if len(dir_with_slash) == 1: if len(dir_with_slash) == 1:
dir_with_slash = '' dir_with_slash = ''
return filter(lambda x: normpath(x.LocalPath()).startswith(dir_with_slash), return filter(
self.change.AffectedFiles(include_dirs, include_deletes)) lambda x: normpath(x.AbsoluteLocalPath()).startswith(dir_with_slash),
self.change.AffectedFiles(include_dirs, include_deletes))
def LocalPaths(self, include_dirs=False): def LocalPaths(self, include_dirs=False):
"""Returns local paths of input_api.AffectedFiles().""" """Returns local paths of input_api.AffectedFiles()."""
...@@ -548,33 +549,29 @@ class GclChange(object): ...@@ -548,33 +549,29 @@ class GclChange(object):
self.AffectedFiles(include_deletes=False))) self.AffectedFiles(include_deletes=False)))
def ListRelevantPresubmitFiles(files): 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.
Args: Args:
files: An iterable container containing file paths. files: An iterable container containing file paths.
root: Path where to stop searching.
Return: Return:
['foo/blat/PRESUBMIT.py', 'mat/gat/PRESUBMIT.py'] List of absolute paths of the existing PRESUBMIT.py scripts.
""" """
checked_dirs = {} # Keys are directory paths, values are ignored. entries = []
source_dirs = [os.path.dirname(f) for f in files] for f in files:
presubmit_files = [] f = normpath(os.path.join(root, f))
for dir in source_dirs: while f:
while (True): f = os.path.dirname(f)
if dir in checked_dirs: if f in entries:
break # We've already walked up from this directory.
test_path = os.path.join(dir, 'PRESUBMIT.py')
if os.path.isfile(test_path):
presubmit_files.append(normpath(test_path))
checked_dirs[dir] = ''
if dir in ['', '.']:
break break
else: entries.append(f)
dir = os.path.dirname(dir) if f == root:
return presubmit_files break
entries.sort()
entries = map(lambda x: os.path.join(x, 'PRESUBMIT.py'), entries)
return filter(lambda x: os.path.isfile(x), entries)
class PresubmitExecuter(object): class PresubmitExecuter(object):
...@@ -653,7 +650,9 @@ def DoPresubmitChecks(change_info, ...@@ -653,7 +650,9 @@ 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.FileList()) checkout_root = gcl.GetRepositoryRoot()
presubmit_files = ListRelevantPresubmitFiles(change_info.FileList(),
checkout_root)
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 = []
...@@ -661,7 +660,8 @@ def DoPresubmitChecks(change_info, ...@@ -661,7 +660,8 @@ def DoPresubmitChecks(change_info,
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")
results += executer.ExecPresubmitScript(default_presubmit, 'PRESUBMIT.py') fake_path = os.path.join(checkout_root, 'PRESUBMIT.py')
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)
if verbose: if verbose:
......
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