-
Notifications
You must be signed in to change notification settings - Fork 1
/
BUILD
158 lines (138 loc) · 5.92 KB
/
BUILD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Load various rules so that we can have bazel download
# various rulesets and dependencies.
# The `load` statement imports the symbol for the rule, in the defined
# ruleset. When the symbol is loaded you can use the rule.
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@pip//:requirements.bzl", "all_whl_requirements")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load("@rules_python_gazelle_plugin//manifest:defs.bzl", "gazelle_python_manifest")
load("@rules_python_gazelle_plugin//modules_mapping:def.bzl", "modules_mapping")
package(default_visibility = ["//visibility:private"])
exports_files(
[
".flake8",
".prettierrc",
".clang-format",
".clang-tidy",
"mypy.ini",
"pytest.ini",
"pyproject.toml",
],
visibility = ["//visibility:public"],
)
compile_pip_requirements(
name = "requirements",
# https://bazel.build/reference/be/common-definitions
size = "enormous",
timeout = "eternal", # 60m
requirements_in = "requirements.in",
requirements_txt = "requirements_lock.txt",
# Don't want to type-check requirements building
tags = ["no-mypy"],
)
# This repository rule fetches the metadata for python packages we
# depend on. That data is required for the gazelle_python_manifest
# rule to update our manifest file.
# To see what this rule does, try `bazel run @modules_map//:print`
modules_mapping(
name = "modules_map",
exclude_patterns = [
"^_|(\\._)+", # This is the default.
"(\\.tests)+", # Add a custom one to get rid of the psutil tests.
],
wheels = all_whl_requirements,
)
# Gazelle python extension needs a manifest file mapping from
# an import to the installed package that provides it.
# This macro produces two targets:
# - //:gazelle_python_manifest.update can be used with `bazel run`
# to recalculate the manifest
# - //:gazelle_python_manifest.test is a test target ensuring that
# the manifest doesn't need to be updated
gazelle_python_manifest(
name = "gazelle_python_manifest",
modules_mapping = ":modules_map",
pip_repository_name = "pip",
# NOTE: We can pass a list just like in `bzlmod_build_file_generation` example
# but we keep a single target here for regression testing.
requirements = "//:requirements_lock.txt",
)
gazelle_binary(
name = "gazelle_bin",
languages = [
"@bazel_gazelle//language/bazel/visibility", # bazel visibility rules
"@bazel_gazelle//language/go", # Built-in rule from gazelle for Golang
"@bazel_gazelle//language/proto", # Built-in rule from gazelle for Protos
# Any languages that depend on the proto plugin must come after it
"@rules_python_gazelle_plugin//python:python", # Use gazelle from rules_python
"@build_stack_rules_proto//language/protobuf", # Protobuf language generation
# TODO: Add buf suppport
# "@rules_buf//gazelle/buf:buf", # Generates buf lint and buf breaking detection rules
],
)
# Our gazelle target points to the python gazelle binary.
# This is the simple case where we only need one language supported.
# If you also had proto, go, or other gazelle-supported languages,
# you would also need a gazelle_binary rule.
# See https://github.com/bazelbuild/bazel-gazelle/blob/master/extend.rst#example
gazelle(
name = "gazelle",
args = [
"-proto_configs=gazelle_proto_config.yaml",
],
gazelle = ":gazelle_bin",
)
# https://github.com/bazelbuild/bazel-gazelle#directives
# https://github.com/bazelbuild/rules_python/blob/main/gazelle/README.md#directives
# Make a py_library per python file
# gazelle:python_generation_mode file
# Disable BUILD.bazel files
# gazelle:build_file_name BUILD
# Exclude these folders from gazelle generation
# gazelle:exclude venv
# Don't use go
# gazelle:go_generate_proto false
# Generate 1 proto rule per file
# gazelle:proto file
# Set default BUILD rule visibility
# gazelle:default_visibility //visibility:private
# Tell gazelle where to find imports
# gazelle:resolve py google.protobuf.message @com_google_protobuf//:protobuf_python
# Use our own rules
# gazelle:map_kind py_binary py_binary //bzl:py.bzl
# gazelle:map_kind py_library py_library //bzl:py.bzl
# gazelle:map_kind py_test py_test //bzl:py.bzl
# gazelle:map_kind grpc_py_library grpc_py_library //bzl:py.bzl
# gazelle:map_kind proto_py_library proto_py_library //bzl:py.bzl
# TODO: Figure out a way to not need these
# gazelle:resolve py hw_services.sbr.sbr_pb2 //hw_services/sbr:sbr_py_library
# gazelle:resolve py examples.basic.hello_pb2 //examples/basic:hello_py_library
# gazelle:resolve py examples.basic.hello_pb2_grpc //examples/basic:hello_grpc_py_library
# gazelle:resolve py third_party.bazel.src.main.protobuf.build_pb2 //third_party/bazel/src/main/protobuf:build_py_library
# gazelle:resolve py third_party.bazel.proto.build_event_stream_pb2 //third_party/bazel/proto:build_event_stream_py_library
# gazelle:resolve proto pw_protobuf_protos/common.proto @pigweed//pw_protobuf:common_proto
# gazelle:resolve py examples.pigweed.modules.blinky.blinky_pb2 //examples/pigweed/modules/blinky:blinky_pb2
# gazelle:resolve py pw_cli @pigweed//pw_system/py:pw_system_lib
# gazelle:resolve py pw_system.console @pigweed//pw_system/py:pw_system_lib
# gazelle:resolve py pw_system.device @pigweed//pw_system/py:pw_system_lib
# gazelle:resolve py pw_system.device_connection @pigweed//pw_system/py:pw_system_lib
npm_link_all_packages(name = "node_modules")
filegroup(
name = "python_source",
srcs = glob(
["*.py"],
allow_empty = True,
) + [
"//apps:python_source",
"//examples/basic:python_source",
"//examples/bazel:python_source",
"//examples/pigweed/modules/blinky:python_source",
"//third_party/pigweed/tools:python_source",
],
visibility = ["//visibility:public"],
)
alias(
name = "format",
actual = "//tools/format",
)