pw_presubmit: Check for different file types in each build
- Separate the file types checked in check_builds_for_files by build
system.
- Add .py to the list of checked extensions for GN in Pigweed's
source_is_in_build_files presubmit step.
Change-Id: Ibbcb847a6cd1026ce6ffe627ee3fd3c8edf0d458
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/22190
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
diff --git a/pw_presubmit/py/pw_presubmit/build.py b/pw_presubmit/py/pw_presubmit/build.py
index 618f3a2..c08ef3d 100644
--- a/pw_presubmit/py/pw_presubmit/build.py
+++ b/pw_presubmit/py/pw_presubmit/build.py
@@ -106,7 +106,8 @@
def check_builds_for_files(
- extensions_to_check: Container[str],
+ bazel_extensions_to_check: Container[str],
+ gn_extensions_to_check: Container[str],
files: Iterable[Path],
bazel_dirs: Iterable[Path] = (),
gn_dirs: Iterable[Tuple[Path, Path]] = (),
@@ -115,7 +116,8 @@
"""Checks that source files are in the GN and Bazel builds.
Args:
- extensions_to_check: which file suffixes to look for
+ bazel_extensions_to_check: which file suffixes to look for in Bazel
+ gn_extensions_to_check: which file suffixes to look for in GN
files: the files that should be checked
bazel_dirs: directories in which to run bazel query
gn_dirs: (source_dir, output_dir) tuples with which to run gn desc
@@ -144,13 +146,18 @@
missing: Dict[str, List[Path]] = collections.defaultdict(list)
- for path in (p for p in files if p.suffix in extensions_to_check):
- if bazel_dirs and path.suffix != '.rst' and path not in bazel_builds:
- # TODO(pwbug/176) Replace this workaround for fuzzers.
- if 'fuzz' not in str(path):
- missing['Bazel'].append(path)
- if (gn_dirs or gn_build_files) and path not in gn_builds:
- missing['GN'].append(path)
+ if bazel_dirs:
+ for path in (p for p in files
+ if p.suffix in bazel_extensions_to_check):
+ if path not in bazel_builds:
+ # TODO(pwbug/176) Replace this workaround for fuzzers.
+ if 'fuzz' not in str(path):
+ missing['Bazel'].append(path)
+
+ if gn_dirs or gn_build_files:
+ for path in (p for p in files if p.suffix in gn_extensions_to_check):
+ if path not in gn_builds:
+ missing['GN'].append(path)
for builder, paths in missing.items():
_LOG.warning('%s missing from the %s build:\n%s',
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index 15f7c39..c1228e2 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -329,14 +329,16 @@
raise PresubmitFailure
-_SOURCES_IN_BUILD = '.rst', *format_code.C_FORMAT.extensions
+_BAZEL_SOURCES_IN_BUILD = tuple(format_code.C_FORMAT.extensions)
+_GN_SOURCES_IN_BUILD = '.rst', '.py', *_BAZEL_SOURCES_IN_BUILD
-@filter_paths(endswith=(*_SOURCES_IN_BUILD, 'BUILD', '.bzl', '.gn', '.gni'))
+@filter_paths(endswith=(*_GN_SOURCES_IN_BUILD, 'BUILD', '.bzl', '.gn', '.gni'))
def source_is_in_build_files(ctx: PresubmitContext):
"""Checks that source files are in the GN and Bazel builds."""
missing = build.check_builds_for_files(
- _SOURCES_IN_BUILD,
+ _BAZEL_SOURCES_IN_BUILD,
+ _GN_SOURCES_IN_BUILD,
ctx.paths,
bazel_dirs=[ctx.root],
gn_build_files=git_repo.list_files(