Factor out get_source_files in the tools.
Before this patch, lint.py would scan all C++ files present in HEAD
(but with any modifications from the working directory), whilst
clang_format.py would look at all C++ files without consulting Git.
This patch introduces a `get_source_files` utility, now used by both
scripts, which looks only at the file system.
This means that lint.py will now scan untracked files, but since
clang_format.py already did that (and would cause test.py to fail if
they weren't properly formatted), this seems to be reasonable behaviour.
The alternative -- looking at files known to Git -- is attractive, but
it could be misleading because we scan the state of those files in the
working directory, not in Git's HEAD.
Change-Id: I88ab245c6452b5bdf3e8ffa3eabb223cc9339f3e
diff --git a/tools/lint.py b/tools/lint.py
index f23fa05..3ceb94f 100755
--- a/tools/lint.py
+++ b/tools/lint.py
@@ -52,8 +52,8 @@
parser = argparse.ArgumentParser(
description =
'''This tool lints C++ files and produces a summary of the errors found.
- If no files are provided on the command-line, all C++ source files in the
- repository are processed.
+ If no files are provided on the command-line, all C++ source files are
+ processed, except for the test traces.
Results are cached to speed up the process.
''',
# Print default values.
@@ -195,19 +195,6 @@
return CPP_EXT_REGEXP.search(filename) != None
-def GetDefaultFilesToLint():
- if git.is_git_repository_root(config.dir_root):
- files = git.get_tracked_files().split()
- files = filter(IsLinterInput, files)
- files = FilterOutTestTraceHeaders(files)
- return 0, files
- else:
- printer.Print(printer.COLOUR_ORANGE + 'WARNING: This script is not run ' \
- 'from its Git repository. The linter will not run.' + \
- printer.NO_COLOUR)
- return 1, []
-
-
cached_results_pkl_filename = \
os.path.join(config.dir_tools, '.cached_lint_results.pkl')
@@ -251,11 +238,7 @@
# Parse the arguments.
args = BuildOptions()
- files = args.files
- if not files:
- retcode, files = GetDefaultFilesToLint()
- if retcode:
- sys.exit(retcode)
+ files = args.files or util.get_source_files()
cached = not args.no_cache
retcode = RunLinter(files, jobs=args.jobs, cached=cached)