1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15load("@rules_python//python:defs.bzl", "py_library") 16load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") 17load("//pw_build:pw_py_importable_runfile.bzl", "pw_py_importable_runfile") 18load("//pw_build:python.bzl", "pw_py_binary", "pw_py_test") 19 20package(default_visibility = ["//visibility:public"]) 21 22licenses(["notice"]) 23 24py_library( 25 name = "pw_presubmit", 26 srcs = [ 27 "pw_presubmit/__init__.py", 28 "pw_presubmit/bazel_checks.py", 29 "pw_presubmit/bazel_parser.py", 30 "pw_presubmit/block_submission.py", 31 "pw_presubmit/build.py", 32 "pw_presubmit/cli.py", 33 "pw_presubmit/cpp_checks.py", 34 "pw_presubmit/format/__init__.py", 35 "pw_presubmit/format/bazel.py", 36 "pw_presubmit/format/core.py", 37 "pw_presubmit/format/cpp.py", 38 "pw_presubmit/format/gn.py", 39 "pw_presubmit/format/private/__init__.py", 40 "pw_presubmit/format/private/cli.py", 41 "pw_presubmit/format/private/cli_support.py", 42 "pw_presubmit/format/python.py", 43 "pw_presubmit/format/test_data/__init__.py", 44 "pw_presubmit/format_code.py", 45 "pw_presubmit/git_repo.py", 46 "pw_presubmit/gitmodules.py", 47 "pw_presubmit/inclusive_language.py", 48 "pw_presubmit/install_hook.py", 49 "pw_presubmit/javascript_checks.py", 50 "pw_presubmit/json_check.py", 51 "pw_presubmit/keep_sorted.py", 52 "pw_presubmit/module_owners.py", 53 "pw_presubmit/ninja_parser.py", 54 "pw_presubmit/npm_presubmit.py", 55 "pw_presubmit/owners_checks.py", 56 "pw_presubmit/pigweed_presubmit.py", 57 "pw_presubmit/presubmit.py", 58 "pw_presubmit/presubmit_context.py", 59 "pw_presubmit/python_checks.py", 60 "pw_presubmit/repo.py", 61 "pw_presubmit/rst_format.py", 62 "pw_presubmit/shell_checks.py", 63 "pw_presubmit/source_in_build.py", 64 "pw_presubmit/todo_check.py", 65 "pw_presubmit/tools.py", 66 ], 67 data = [ 68 "pw_presubmit/format/test_data/bazel_test_data.bazel", 69 "pw_presubmit/format/test_data/bazel_test_data_golden.bazel", 70 "pw_presubmit/format/test_data/clang_format_config", 71 "pw_presubmit/format/test_data/cpp_test_data.cc", 72 "pw_presubmit/format/test_data/cpp_test_data_golden.cc", 73 "pw_presubmit/format/test_data/gn_test_data.gn", 74 "pw_presubmit/format/test_data/gn_test_data_golden.gn", 75 "pw_presubmit/format/test_data/malformed_file.txt", 76 "pw_presubmit/format/test_data/python_test_data.py", 77 "pw_presubmit/format/test_data/python_test_data_golden.py", 78 ], 79 imports = ["."], 80 deps = [ 81 "//pw_cli/py:pw_cli", 82 "//pw_env_setup/py:pw_env_setup", 83 "//pw_package/py:pw_package", 84 "@rules_python//python/runfiles", 85 ], 86) 87 88py_library( 89 name = "format_core", 90 srcs = [ 91 "pw_presubmit/format/__init__.py", 92 "pw_presubmit/format/bazel.py", 93 "pw_presubmit/format/core.py", 94 "pw_presubmit/format/cpp.py", 95 "pw_presubmit/format/gn.py", 96 "pw_presubmit/format/private/__init__.py", 97 "pw_presubmit/format/private/cli.py", 98 "pw_presubmit/format/private/cli_support.py", 99 "pw_presubmit/format/python.py", 100 ], 101 imports = ["."], 102 visibility = ["//visibility:private"], 103 deps = [ 104 "//pw_cli/py:pw_cli", 105 ], 106) 107 108py_console_script_binary( 109 name = "black", 110 pkg = "@python_packages//black", 111 visibility = ["//visibility:private"], 112) 113 114pw_py_importable_runfile( 115 name = "black_runfiles", 116 src = ":black", 117 executable = True, 118 visibility = ["//visibility:private"], 119) 120 121pw_py_importable_runfile( 122 name = "buildifier_runfiles", 123 src = "@buildifier", 124 executable = True, 125 visibility = ["//visibility:private"], 126) 127 128pw_py_binary( 129 name = "format", 130 srcs = ["pigweed_format/__main__.py"], 131 main = "pigweed_format/__main__.py", 132 deps = [ 133 ":black_runfiles", 134 ":buildifier_runfiles", 135 "//pw_build/py:pw_build", 136 ] + select({ 137 "@platforms//os:macos": ["@llvm_toolchain_macos//:py_clang_format"], 138 "//conditions:default": ["@llvm_toolchain//:py_clang_format"], 139 }), 140) 141 142pw_py_test( 143 name = "bazel_parser_test", 144 srcs = ["bazel_parser_test.py"], 145 deps = [ 146 ":pw_presubmit", 147 ], 148) 149 150py_library( 151 name = "format_testing_utils", 152 srcs = ["format_testing_utils.py"], 153) 154 155pw_py_test( 156 name = "bazel_checks_test", 157 srcs = ["bazel_checks_test.py"], 158 deps = [":pw_presubmit"], 159) 160 161pw_py_test( 162 name = "bazel_format_test", 163 srcs = ["bazel_format_test.py"], 164 # TODO(b/314139942): Requires buildifier on the path. 165 tags = ["manual"], 166 deps = [ 167 ":format_testing_utils", 168 ":pw_presubmit", 169 ], 170) 171 172pw_py_test( 173 name = "context_test", 174 srcs = ["context_test.py"], 175 # TODO(b/374120469): Make PW_PROJECT_ROOT optional for pw presubmit 176 tags = ["manual"], 177 deps = [ 178 ":pw_presubmit", 179 ], 180) 181 182pw_py_test( 183 name = "cpp_checks_test", 184 srcs = ["cpp_checks_test.py"], 185 deps = [ 186 ":pw_presubmit", 187 ], 188) 189 190pw_py_test( 191 name = "cpp_format_test", 192 srcs = ["cpp_format_test.py"], 193 # TODO(b/314139942): Requires clang-format on the path. 194 tags = ["manual"], 195 deps = [ 196 ":format_testing_utils", 197 ":pw_presubmit", 198 ], 199) 200 201pw_py_test( 202 name = "format_core_test", 203 srcs = ["format_core_test.py"], 204 deps = [ 205 ":pw_presubmit", 206 ], 207) 208 209pw_py_test( 210 name = "gitmodules_test", 211 srcs = ["gitmodules_test.py"], 212 # TODO(b/314139942): Requires git on the path. 213 tags = ["manual"], 214 deps = [ 215 ":pw_presubmit", 216 ], 217) 218 219pw_py_test( 220 name = "gn_format_test", 221 srcs = ["gn_format_test.py"], 222 # TODO(b/314139942): Requires GN on the path. 223 tags = ["manual"], 224 deps = [ 225 ":format_testing_utils", 226 ":pw_presubmit", 227 ], 228) 229 230pw_py_test( 231 name = "inclusive_language_test", 232 srcs = ["inclusive_language_test.py"], 233 deps = [ 234 ":pw_presubmit", 235 ], 236) 237 238pw_py_test( 239 name = "keep_sorted_test", 240 srcs = ["keep_sorted_test.py"], 241 deps = [ 242 ":pw_presubmit", 243 ], 244) 245 246pw_py_test( 247 name = "ninja_parser_test", 248 srcs = ["ninja_parser_test.py"], 249 deps = [ 250 ":pw_presubmit", 251 ], 252) 253 254pw_py_test( 255 name = "presubmit_test", 256 srcs = ["presubmit_test.py"], 257 deps = [ 258 ":pw_presubmit", 259 ], 260) 261 262pw_py_test( 263 name = "python_format_test", 264 srcs = ["python_format_test.py"], 265 # TODO(b/314139942): Requires black on the path. 266 tags = ["manual"], 267 deps = [ 268 ":format_testing_utils", 269 ":pw_presubmit", 270 "@python_packages//black", 271 ], 272) 273 274pw_py_test( 275 name = "owners_checks_test", 276 srcs = ["owners_checks_test.py"], 277 deps = [ 278 ":pw_presubmit", 279 ], 280) 281 282pw_py_test( 283 name = "todo_check_test", 284 srcs = ["todo_check_test.py"], 285 deps = [ 286 ":pw_presubmit", 287 ], 288) 289 290pw_py_test( 291 name = "tools_test", 292 srcs = ["tools_test.py"], 293 deps = [ 294 ":pw_presubmit", 295 ], 296) 297