Skip to content

Commit

Permalink
pw_build: Require "tests" and "docs" targets in all modules
Browse files Browse the repository at this point in the history
- Allow empty pw_test_group targets.
- Create empty pw_test_group targets for modules that need them.
- Create stub docs pages for modules that are missing them.
- Require odules to provide "tests" and "docs" targets by assuming
  they're present in the module list generation code.
- Update the generated modules list.

Change-Id: I5a67741afa0a8a5d2e2ba508435027f750a471c4
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/103487
Commit-Queue: Auto-Submit <[email protected]>
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed Jul 26, 2022
1 parent 63271a2 commit 8f42549
Show file tree
Hide file tree
Showing 64 changed files with 355 additions and 23 deletions.
4 changes: 4 additions & 0 deletions docker/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import("//build_overrides/pigweed.gni")

import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
2 changes: 2 additions & 0 deletions docs/module_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ To create a new Pigweed module, follow the below steps.
- Declare tests in ``pw_test_group("tests")``
- Declare docs in ``pw_docs_group("docs")``

Both ``tests`` and ``docs`` are required, even if the module is empty!

6. Add Bazel build support in ``{pw_module_dir}/BUILD.bazel``

7. Add CMake build support in ``{pw_module_dir}/CMakeLists.txt``
Expand Down
4 changes: 4 additions & 0 deletions pw_android_toolchain/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build_overrides/pigweed.gni")

import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

config("static_libstdc") {
# Compile against the static libstdc++ and libc++, since we don't have an
Expand All @@ -25,3 +26,6 @@ config("static_libstdc") {
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_arduino_build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("$dir_pw_arduino_build/arduino.gni")
import("$dir_pw_build/facade.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

declare_args() {
# Backend for the pw_arduino_init module.
Expand Down Expand Up @@ -51,3 +52,6 @@ if (pw_arduino_build_CORE_PATH != "") {
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_assert_basic/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import("//build_overrides/pigweed.gni")
import("$dir_pw_build/facade.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")
import("backend.gni")

config("public_include_path") {
Expand Down Expand Up @@ -89,3 +90,6 @@ pw_source_set("basic_handler") {
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_assert_log/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("//build_overrides/pigweed.gni")

import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

config("public_include_path") {
include_dirs = [ "public" ]
Expand Down Expand Up @@ -90,3 +91,6 @@ group("pw_assert_log.impl") {
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_assert_tokenized/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("//build_overrides/pigweed.gni")

import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

declare_args() {
pw_assert_tokenized_HANDLER_BACKEND = "$dir_pw_assert_tokenized:log_handler"
Expand Down Expand Up @@ -111,3 +112,6 @@ pw_source_set("log_handler") {
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_assert_zephyr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import("//build_overrides/pigweed.gni")

import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_bloat/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("//build_overrides/pigweed.gni")

import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")
import("bloat.gni")

config("default_config") {
Expand Down Expand Up @@ -51,3 +52,6 @@ pw_doc_group("docs") {
"examples:simple_bloat_loop",
]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_boot/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("$dir_pw_boot/backend.gni")
import("$dir_pw_build/facade.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")
import("$dir_pw_unit_test/test.gni")

config("default_config") {
include_dirs = [ "public" ]
Expand All @@ -32,3 +33,6 @@ pw_facade("pw_boot") {
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_boot_cortex_m/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("$dir_pw_boot/backend.gni")
import("$dir_pw_build/linker_script.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

declare_args() {
# This list should contain the necessary defines for setting pw_boot linker
Expand Down Expand Up @@ -73,3 +74,6 @@ if (pw_boot_BACKEND != "$dir_pw_boot_cortex_m" &&
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
61 changes: 61 additions & 0 deletions pw_build/generated_pigweed_modules_lists.gni
Original file line number Diff line number Diff line change
Expand Up @@ -290,40 +290,75 @@ declare_args() {

# A list with all Pigweed module test groups. DO NOT SET THIS BUILD ARGUMENT!
pw_module_tests = [
"$dir_docker:tests",
"$dir_pw_allocator:tests",
"$dir_pw_analog:tests",
"$dir_pw_android_toolchain:tests",
"$dir_pw_arduino_build:tests",
"$dir_pw_assert:tests",
"$dir_pw_assert_basic:tests",
"$dir_pw_assert_log:tests",
"$dir_pw_assert_tokenized:tests",
"$dir_pw_assert_zephyr:tests",
"$dir_pw_base64:tests",
"$dir_pw_bloat:tests",
"$dir_pw_blob_store:tests",
"$dir_pw_bluetooth:tests",
"$dir_pw_bluetooth_hci:tests",
"$dir_pw_boot:tests",
"$dir_pw_boot_cortex_m:tests",
"$dir_pw_build:tests",
"$dir_pw_build_info:tests",
"$dir_pw_build_mcuxpresso:tests",
"$dir_pw_bytes:tests",
"$dir_pw_checksum:tests",
"$dir_pw_chrono:tests",
"$dir_pw_chrono_embos:tests",
"$dir_pw_chrono_freertos:tests",
"$dir_pw_chrono_stl:tests",
"$dir_pw_chrono_threadx:tests",
"$dir_pw_chrono_zephyr:tests",
"$dir_pw_cli:tests",
"$dir_pw_console:tests",
"$dir_pw_containers:tests",
"$dir_pw_cpu_exception:tests",
"$dir_pw_cpu_exception_cortex_m:tests",
"$dir_pw_crypto:tests",
"$dir_pw_digital_io:tests",
"$dir_pw_docgen:tests",
"$dir_pw_doctor:tests",
"$dir_pw_env_setup:tests",
"$dir_pw_file:tests",
"$dir_pw_function:tests",
"$dir_pw_fuzzer:tests",
"$dir_pw_hdlc:tests",
"$dir_pw_hex_dump:tests",
"$dir_pw_i2c:tests",
"$dir_pw_i2c_mcuxpresso:tests",
"$dir_pw_interrupt:tests",
"$dir_pw_interrupt_cortex_m:tests",
"$dir_pw_interrupt_zephyr:tests",
"$dir_pw_kvs:tests",
"$dir_pw_libc:tests",
"$dir_pw_log:tests",
"$dir_pw_log_android:tests",
"$dir_pw_log_basic:tests",
"$dir_pw_log_null:tests",
"$dir_pw_log_rpc:tests",
"$dir_pw_log_string:tests",
"$dir_pw_log_tokenized:tests",
"$dir_pw_log_zephyr:tests",
"$dir_pw_malloc:tests",
"$dir_pw_malloc_freelist:tests",
"$dir_pw_metric:tests",
"$dir_pw_minimal_cpp_stdlib:tests",
"$dir_pw_module:tests",
"$dir_pw_multisink:tests",
"$dir_pw_package:tests",
"$dir_pw_persistent_ram:tests",
"$dir_pw_polyfill:tests",
"$dir_pw_preprocessor:tests",
"$dir_pw_presubmit:tests",
"$dir_pw_protobuf:tests",
"$dir_pw_protobuf_compiler:tests",
"$dir_pw_random:tests",
Expand All @@ -336,10 +371,28 @@ declare_args() {
"$dir_pw_span:tests",
"$dir_pw_spi:tests",
"$dir_pw_status:tests",
"$dir_pw_stm32cube_build:tests",
"$dir_pw_stream:tests",
"$dir_pw_string:tests",
"$dir_pw_symbolizer:tests",
"$dir_pw_sync:tests",
"$dir_pw_sync_baremetal:tests",
"$dir_pw_sync_embos:tests",
"$dir_pw_sync_freertos:tests",
"$dir_pw_sync_stl:tests",
"$dir_pw_sync_threadx:tests",
"$dir_pw_sync_zephyr:tests",
"$dir_pw_sys_io:tests",
"$dir_pw_sys_io_arduino:tests",
"$dir_pw_sys_io_baremetal_lm3s6965evb:tests",
"$dir_pw_sys_io_baremetal_stm32f429:tests",
"$dir_pw_sys_io_emcraft_sf2:tests",
"$dir_pw_sys_io_mcuxpresso:tests",
"$dir_pw_sys_io_stdio:tests",
"$dir_pw_sys_io_stm32cube:tests",
"$dir_pw_sys_io_zephyr:tests",
"$dir_pw_system:tests",
"$dir_pw_target_runner:tests",
"$dir_pw_thread:tests",
"$dir_pw_thread_embos:tests",
"$dir_pw_thread_freertos:tests",
Expand All @@ -349,11 +402,15 @@ declare_args() {
"$dir_pw_tls_client_boringssl:tests",
"$dir_pw_tls_client_mbedtls:tests",
"$dir_pw_tokenizer:tests",
"$dir_pw_tool:tests",
"$dir_pw_toolchain:tests",
"$dir_pw_trace:tests",
"$dir_pw_trace_tokenized:tests",
"$dir_pw_transfer:tests",
"$dir_pw_unit_test:tests",
"$dir_pw_varint:tests",
"$dir_pw_watch:tests",
"$dir_pw_web_ui:tests",
"$dir_pw_work_queue:tests",
]

Expand Down Expand Up @@ -410,11 +467,13 @@ declare_args() {
"$dir_pw_kvs:docs",
"$dir_pw_libc:docs",
"$dir_pw_log:docs",
"$dir_pw_log_android:docs",
"$dir_pw_log_basic:docs",
"$dir_pw_log_null:docs",
"$dir_pw_log_rpc:docs",
"$dir_pw_log_string:docs",
"$dir_pw_log_tokenized:docs",
"$dir_pw_log_zephyr:docs",
"$dir_pw_malloc:docs",
"$dir_pw_malloc_freelist:docs",
"$dir_pw_metric:docs",
Expand Down Expand Up @@ -451,6 +510,7 @@ declare_args() {
"$dir_pw_sync_zephyr:docs",
"$dir_pw_sys_io:docs",
"$dir_pw_sys_io_arduino:docs",
"$dir_pw_sys_io_baremetal_lm3s6965evb:docs",
"$dir_pw_sys_io_baremetal_stm32f429:docs",
"$dir_pw_sys_io_emcraft_sf2:docs",
"$dir_pw_sys_io_mcuxpresso:docs",
Expand All @@ -468,6 +528,7 @@ declare_args() {
"$dir_pw_tls_client_boringssl:docs",
"$dir_pw_tls_client_mbedtls:docs",
"$dir_pw_tokenizer:docs",
"$dir_pw_tool:docs",
"$dir_pw_toolchain:docs",
"$dir_pw_trace:docs",
"$dir_pw_trace_tokenized:docs",
Expand Down
32 changes: 9 additions & 23 deletions pw_build/py/pw_build/generate_modules_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pathlib import Path
import sys
import subprocess
from typing import Iterator, List, Optional, Sequence, Tuple
from typing import Iterator, Optional, Sequence

_COPYRIGHT_NOTICE = '''\
# Copyright 2022 The Pigweed Authors
Expand Down Expand Up @@ -98,24 +98,6 @@ def _module_list_warnings(root: Path, modules: Sequence[str]) -> Iterator[str]:
yield ''


# TODO(hepler): Add tests and docs targets to all modules.
def _find_tests_and_docs(
root: Path, modules: Sequence[str]) -> Tuple[List[str], List[str]]:
"""Lists "tests" and "docs" targets for modules that declare them."""
tests = []
docs = []

for module in modules:
build_gn_contents = root.joinpath(module, 'BUILD.gn').read_bytes()
if b'group("tests")' in build_gn_contents:
tests.append(f'"$dir_{module}:tests",')

if b'group("docs")' in build_gn_contents:
docs.append(f'"$dir_{module}:docs",')

return tests, docs


def _generate_modules_gni(root: Path, prefix: Path,
modules: Sequence[str]) -> Iterator[str]:
"""Generates a .gni file with variables and lists for Pigweed modules."""
Expand Down Expand Up @@ -157,16 +139,20 @@ def _generate_modules_gni(root: Path, prefix: Path,
yield ']'
yield ''

tests, docs = _find_tests_and_docs(root, modules)

yield f'# A list with all Pigweed module test groups. {_DO_NOT_SET}'
yield 'pw_module_tests = ['
yield from tests

for module in modules:
yield f'"$dir_{module}:tests",'

yield ']'
yield ''
yield f'# A list with all Pigweed modules docs groups. {_DO_NOT_SET}'
yield 'pw_module_docs = ['
yield from docs

for module in modules:
yield f'"$dir_{module}:docs",'

yield ']'
yield ''
yield '}'
Expand Down
4 changes: 4 additions & 0 deletions pw_build_info/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("//build_overrides/pigweed.gni")

import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

config("linker_script") {
inputs = [ "build_id_linker_snippet.ld" ]
Expand Down Expand Up @@ -73,3 +74,6 @@ pw_doc_group("docs") {
sources = [ "docs.rst" ]
inputs = [ "build_id_linker_snippet.ld" ]
}

pw_test_group("tests") {
}
4 changes: 4 additions & 0 deletions pw_build_mcuxpresso/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import("//build_overrides/pigweed.gni")

import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

pw_doc_group("docs") {
sources = [ "docs.rst" ]
}

pw_test_group("tests") {
}
Loading

0 comments on commit 8f42549

Please sign in to comment.