pw_build: Introduce pw_py_test to bazel

- pw_py_test wraps py_test and defaults to setting
  'target_compatible_with' to host only
- updates all uses of py_test to use pw_py_test

Change-Id: I6414f3c1ea9e887202e476ff24f97a57b7d44fdf
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/215258
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Dave Roth <davidroth@google.com>
Reviewed-by: Ted Pudlik <tpudlik@google.com>
This commit is contained in:
Dave Roth 2024-06-10 22:25:45 +00:00 committed by CQ Bot Account
parent 51e996e5c2
commit b5068bcebc
25 changed files with 147 additions and 92 deletions

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -35,7 +36,7 @@ py_library(
imports = ["."],
)
py_test(
pw_py_test(
name = "builder_test",
size = "small",
srcs = [
@ -47,7 +48,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "file_operations_test",
size = "small",
srcs = [

View File

@ -13,8 +13,8 @@ microcontrollers.
Wrapper rules
-------------
The common configuration for Bazel for all modules is in the ``pigweed.bzl``
file. The built-in Bazel rules ``cc_binary``, ``cc_test`` are wrapped with
``pw_cc_binary`` and ``pw_cc_test``.
file. The built-in Bazel rules ``cc_binary``, ``cc_test`` and ``py_test`` are
wrapped with ``pw_cc_binary``, ``pw_cc_test`` and ``pw_py_test``.
.. _module-pw_build-bazel-pw_linker_script:

36
pw_build/python.bzl Normal file
View File

@ -0,0 +1,36 @@
# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Pigweed python build environment for bazel."""
load("@rules_python//python:defs.bzl", "py_test")
load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT")
def pw_py_test(**kwargs):
"""Wrapper for py_test providing some defaults.
Specifically, this wrapper,
* Defaults to setting `target_compatible_with` to
`select(TARGET_COMPATIBLE_WITH_HOST_SELECT)`
Args:
**kwargs: Passed to py_test.
"""
# Python tests are always host only, but allow a user to override
# the default value.
if kwargs.get("target_compatible_with") == None:
kwargs["target_compatible_with"] = select(TARGET_COMPATIBLE_WITH_HOST_SELECT)
py_test(**kwargs)

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -28,7 +29,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "timestamp_analyzer_test",
srcs = [
"timestamp_analyzer_test.py",

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -54,7 +55,7 @@ py_binary(
],
)
py_test(
pw_py_test(
name = "envparse_test",
size = "small",
srcs = [
@ -65,7 +66,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "file_filter_test",
size = "small",
srcs = [
@ -76,7 +77,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "git_repo_test",
size = "small",
srcs = [
@ -87,7 +88,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "plugins_test",
size = "small",
srcs = [
@ -98,7 +99,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "plural_test",
size = "small",
srcs = [
@ -109,7 +110,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "tool_runner_test",
size = "small",
srcs = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -32,7 +33,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "yaml_config_loader_mixin_test",
size = "small",
srcs = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -123,7 +124,7 @@ py_binary(
],
)
py_test(
pw_py_test(
name = "command_runner_test",
size = "small",
srcs = [
@ -134,7 +135,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "console_app_test",
size = "small",
srcs = [
@ -145,7 +146,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "console_prefs_test",
size = "small",
srcs = [
@ -156,7 +157,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "help_window_test",
size = "small",
srcs = [
@ -167,7 +168,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "log_filter_test",
size = "small",
srcs = [
@ -179,7 +180,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "log_store_test",
size = "small",
srcs = [
@ -190,7 +191,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "log_view_test",
size = "small",
srcs = [
@ -202,7 +203,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "socket_client_test",
size = "small",
srcs = [
@ -213,7 +214,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "repl_pane_test",
size = "small",
srcs = [
@ -224,7 +225,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "table_test",
size = "small",
srcs = [
@ -236,7 +237,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "text_formatting_test",
size = "small",
srcs = [
@ -248,7 +249,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "window_manager_test",
size = "small",
srcs = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -45,7 +46,7 @@ py_binary(
],
)
py_test(
pw_py_test(
name = "exception_analyzer_test",
size = "small",
srcs = ["exception_analyzer_test.py"],

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -34,7 +35,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "exception_analyzer_test",
size = "small",
srcs = ["exception_analyzer_test.py"],

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -46,7 +47,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "config_file_test",
srcs = ["config_file_test.py"],
deps = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -36,7 +37,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "encode_test",
size = "small",
srcs = [
@ -47,7 +48,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "decode_test",
size = "small",
srcs = [
@ -59,7 +60,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "rpc_test",
size = "small",
srcs = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -33,7 +34,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "log_decoder_test",
srcs = [
"log_decoder_test.py",

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -31,7 +32,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "rpc_log_stream_test",
srcs = [
"rpc_log_stream_test.py",

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
py_library(
name = "pw_log_tokenized",
@ -21,14 +22,14 @@ py_library(
visibility = ["//visibility:public"],
)
py_test(
pw_py_test(
name = "format_string_test",
size = "small",
srcs = ["format_string_test.py"],
deps = [":pw_log_tokenized"],
)
py_test(
pw_py_test(
name = "metadata_test",
size = "small",
srcs = ["metadata_test.py"],

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -32,7 +33,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "metric_parser_test",
size = "small",
srcs = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -33,7 +34,7 @@ py_library(
deps = ["//pw_cli/py:pw_cli"],
)
py_test(
pw_py_test(
name = "seed_test",
size = "small",
srcs = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -29,7 +30,7 @@ py_library(
imports = ["."],
)
py_test(
pw_py_test(
name = "compiled_protos_test",
size = "small",
srcs = [
@ -43,7 +44,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "compiled_nanopb_protos_test",
size = "small",
srcs = [
@ -58,7 +59,7 @@ py_test(
)
# TODO(tonymd) Find out how to make protoc available in the bazel sandbox.
# py_test(
# pw_py_test(
# name = "python_protos_test",
# size = "small",
# srcs = [

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -102,7 +102,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "callback_client_test",
size = "small",
srcs = [
@ -114,7 +114,6 @@ py_test(
env = {
"PROTOC": "$(location @com_google_protobuf//:protoc)",
},
target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
deps = [
":pw_rpc",
"//pw_protobuf_compiler:pw_protobuf_compiler_protos_py_pb2",
@ -123,7 +122,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "client_test",
size = "small",
srcs = [
@ -135,7 +134,6 @@ py_test(
env = {
"PROTOC": "$(location @com_google_protobuf//:protoc)",
},
target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
deps = [
":pw_rpc",
"//pw_rpc:internal_packet_proto_pb2",
@ -143,7 +141,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "descriptors_test",
size = "small",
srcs = [
@ -155,7 +153,6 @@ py_test(
env = {
"PROTOC": "$(location @com_google_protobuf//:protoc)",
},
target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
deps = [
":pw_rpc",
"//pw_protobuf_compiler:pw_protobuf_compiler_protos_py_pb2",
@ -163,7 +160,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "ids_test",
size = "small",
srcs = [
@ -176,7 +173,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "packets_test",
size = "small",
srcs = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -32,7 +33,7 @@ py_library(
imports = ["."],
)
py_test(
pw_py_test(
name = "validator_test",
srcs = ["validator_test.py"],
deps = [

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -50,7 +51,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "metadata_test",
srcs = ["metadata_test.py"],
deps = [
@ -60,7 +61,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "processor_test",
srcs = ["processor_test.py"],

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -26,7 +27,7 @@ py_library(
imports = ["."],
)
py_test(
pw_py_test(
name = "symbolizer_test",
size = "small",
srcs = ["symbolizer_test.py"],

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -31,7 +32,7 @@ py_library(
)
# TODO: b/241307309 - Requires injection of a `llvm-symbolizer` tool to pass.
py_test(
pw_py_test(
name = "thread_analyzer_test",
srcs = [
"thread_analyzer_test.py",

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_python//python:proto.bzl", "py_proto_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -55,7 +56,7 @@ filegroup(
# deps = [":pw_tokenizer"],
)
py_test(
pw_py_test(
name = "decode_test",
srcs = [
"decode_test.py",
@ -65,7 +66,7 @@ py_test(
deps = [":pw_tokenizer"],
)
py_test(
pw_py_test(
name = "detokenize_proto_test",
srcs = [
"detokenize_proto_test.py",
@ -96,7 +97,7 @@ filegroup(
srcs = ["example_binary_with_tokenized_strings.elf"],
)
py_test(
pw_py_test(
name = "detokenize_test",
srcs = ["detokenize_test.py"],
data = [
@ -107,7 +108,7 @@ py_test(
],
)
py_test(
pw_py_test(
name = "elf_reader_test",
srcs = ["elf_reader_test.py"],
data = [
@ -141,7 +142,7 @@ filegroup(
],
)
py_test(
pw_py_test(
name = "encode_test",
srcs = [
"encode_test.py",
@ -150,7 +151,7 @@ py_test(
deps = [":pw_tokenizer"],
)
py_test(
pw_py_test(
name = "tokens_test",
srcs = ["tokens_test.py"],
deps = [":pw_tokenizer"],

View File

@ -13,9 +13,10 @@
# the License.
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_python//python:proto.bzl", "py_proto_library")
load("//pw_build:pigweed.bzl", "pw_cc_binary")
load("//pw_build:python.bzl", "pw_py_test")
load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT")
pw_cc_binary(
@ -47,7 +48,7 @@ py_binary(
],
)
py_test(
pw_py_test(
name = "proxy_test",
srcs = [
"proxy.py",
@ -129,7 +130,7 @@ py_library(
)
# Uses ports 3310 and 3311.
py_test(
pw_py_test(
name = "cross_language_large_write_test",
# Actually 1 hour, see
# https://docs.bazel.build/versions/main/test-encyclopedia.html#role-of-the-test-runner
@ -149,7 +150,7 @@ py_test(
)
# Uses ports 3306 and 3307.
py_test(
pw_py_test(
name = "cross_language_large_read_test",
# Actually 1 hour, see
# https://docs.bazel.build/versions/main/test-encyclopedia.html#role-of-the-test-runner
@ -169,7 +170,7 @@ py_test(
)
# Uses ports 3304 and 3305.
py_test(
pw_py_test(
name = "cross_language_medium_read_test",
timeout = "moderate",
srcs = [
@ -187,7 +188,7 @@ py_test(
)
# Uses ports 3316 and 3317.
py_test(
pw_py_test(
name = "cross_language_medium_write_test",
timeout = "long",
srcs = [
@ -205,7 +206,7 @@ py_test(
)
# Uses ports 3302 and 3303.
py_test(
pw_py_test(
name = "cross_language_small_test",
timeout = "moderate",
srcs = [
@ -222,7 +223,7 @@ py_test(
)
# Uses ports 3308 and 3309.
py_test(
pw_py_test(
name = "multi_transfer_test",
timeout = "moderate",
srcs = [
@ -239,7 +240,7 @@ py_test(
)
# Uses ports 3312 and 3313.
py_test(
pw_py_test(
name = "expected_errors_test",
timeout = "long",
srcs = ["expected_errors_test.py"],
@ -256,7 +257,7 @@ py_test(
)
# Uses ports 3314 and 3315.
py_test(
pw_py_test(
name = "legacy_binaries_test",
timeout = "moderate",
srcs = ["legacy_binaries_test.py"],

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_test")
package(default_visibility = ["//visibility:public"])
@ -34,7 +35,7 @@ py_library(
],
)
py_test(
pw_py_test(
name = "transfer_test",
size = "small",
srcs = [