Index: presubmit_canned_checks.py |
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py |
index bd3c361f2742f1145df08607e22f754f7b61b705..646491e188666e6d5cf089a436308340097c5c59 100644 |
--- a/presubmit_canned_checks.py |
+++ b/presubmit_canned_checks.py |
@@ -562,6 +562,49 @@ def GetUnitTests(input_api, output_api, unit_tests, env=None): |
return results |
+def GetGitUnitTestsRecursively(input_api, output_api, directory, |
+ whitelist, blacklist): |
+ """Gets all files in the directory tree (git repo) that match the whitelist. |
+ |
+ Restricts itself to only find files within the Change's source repo, not |
+ dependencies. |
+ """ |
+ def curry_check(whitelist, blacklist): |
M-A Ruel
2014/05/14 00:20:57
This is not necessary, the values are bound anyhow
agable
2014/05/14 22:43:20
But but but I have to pay honor to Haskell Curry!
|
+ def check(filename): |
+ return (any(input_api.re.match(f, filename) for f in whitelist) and |
+ not any(input_api.re.match(f, filename) for f in blacklist)) |
+ return check |
+ check = curry_check(whitelist, blacklist) |
+ |
+ tests = [] |
+ |
+ repo_root = input_api.change.RepositoryRoot() |
+ toplevel = input_api.os_path.abspath( |
+ input_api.os_path.join(input_api.PresubmitLocalPath(), directory)) |
+ to_run = found = 0 |
+ for root, dirs, files in input_api.os_walk(toplevel): |
+ git_toplevel = input_api.subprocess.check_output( |
+ ['git', 'rev-parse', '--show-toplevel'], cwd=root).strip() |
M-A Ruel
2014/05/14 00:20:57
That's not how I thought about doing it, my take w
agable
2014/05/14 22:43:20
PTAL. I added one for SVN too.
|
+ if git_toplevel != repo_root: |
+ del dirs[:] |
+ continue |
+ for name in files: |
+ found += 1 |
+ fullname = input_api.os_path.join(root, name) |
+ if check(fullname): |
+ to_run += 1 |
+ tests.append(fullname) |
+ input_api.logging.debug('Found %d files, running %d' % (found, to_run)) |
+ if not to_run: |
+ return [ |
+ output_api.PresubmitPromptWarning( |
+ 'Out of %d files, found none that matched w=%r, b=%r in directory %s' |
+ % (found, whitelist, blacklist, directory)) |
+ ] |
+ |
+ return GetUnitTests(input_api, output_api, tests) |
+ |
+ |
def GetPythonUnitTests(input_api, output_api, unit_tests): |
"""Run the unit tests out of process, capture the output and use the result |
code to determine success. |
@@ -744,7 +787,7 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None, |
if True: |
return [GetPylintCmd(files)] |
else: |
- return map(GetPylintCmd, files) |
+ return map(lambda x: GetPylintCmd([x]), files) |
def RunPylint(input_api, *args, **kwargs): |