pw_presubmit: Support paths with spaces; run Bazel
- Split Git output by line instead of whitespace to support spaces in
filenames.
- Run Bazel tests in the fast presubmit program.
- Use pw_cli.log for pigweed_presubmit.py.
Change-Id: I14ffdf8f41ba953fe39efa4b45e5639695964acc
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index d204427..7febdb1 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -508,6 +508,7 @@
*CC,
gn_clang_build,
gn_arm_build,
+ *BAZEL,
*python_checks.ALL,
)
@@ -635,6 +636,13 @@
if __name__ == '__main__':
- # By default, display log messages like a simple print statement.
- logging.basicConfig(format='%(message)s', level=logging.INFO)
+ try:
+ # If pw_cli is available, use it to initialize logs.
+ from pw_cli import log
+
+ log.install(logging.INFO)
+ except ImportError:
+ # If pw_cli isn't available, display log messages like a simple print.
+ logging.basicConfig(format='%(message)s', level=logging.INFO)
+
sys.exit(main(**vars(argument_parser().parse_args())))
diff --git a/pw_presubmit/py/pw_presubmit/tools.py b/pw_presubmit/py/pw_presubmit/tools.py
index 3d05bf0..9517565 100644
--- a/pw_presubmit/py/pw_presubmit/tools.py
+++ b/pw_presubmit/py/pw_presubmit/tools.py
@@ -88,8 +88,8 @@
def _git_ls_files(*args: PathOrStr, repo: PathOrStr = '.') -> List[str]:
return [
- os.path.abspath(os.path.join(repo, path))
- for path in git_stdout('ls-files', '--', *args, repo=repo).split()
+ os.path.abspath(os.path.join(repo, path)) for path in git_stdout(
+ 'ls-files', '--', *args, repo=repo).splitlines()
]
@@ -106,7 +106,7 @@
commit,
'--',
*paths,
- repo=repo).split()
+ repo=repo).splitlines()
]