mirror of https://github.com/mongodb/mongo
SERVER-101031 Use rules_lint buildifier formatter (#32590)
GitOrigin-RevId: 0126d23afc2d113b65a1c4b8a25b49ddcfc8edf2
This commit is contained in:
parent
cc147d4fee
commit
e4015670c8
|
|
@ -70,7 +70,7 @@ prettier.prettier_binary(
|
|||
|
||||
alias(
|
||||
name = "format",
|
||||
actual = "//bazel/format",
|
||||
actual = "//bazel/format:rules_lint_format_wrapper",
|
||||
)
|
||||
|
||||
alias(
|
||||
|
|
|
|||
|
|
@ -366,3 +366,24 @@ filegroup(
|
|||
""",
|
||||
path = "mongot-localdev",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "buildifier_prebuilt",
|
||||
sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e",
|
||||
strip_prefix = "buildifier-prebuilt-6.4.0",
|
||||
urls = [
|
||||
"http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")
|
||||
|
||||
buildifier_prebuilt_deps()
|
||||
|
||||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
|
||||
|
||||
bazel_skylib_workspace()
|
||||
|
||||
load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")
|
||||
|
||||
buildifier_prebuilt_register_toolchains()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
load("@aspect_rules_lint//format:defs.bzl", "format_multirun", "format_test")
|
||||
|
||||
py_binary(
|
||||
name = "format",
|
||||
srcs = ["format.py"],
|
||||
name = "rules_lint_format_wrapper",
|
||||
srcs = ["rules_lint_format_wrapper.py"],
|
||||
args = [
|
||||
"--prettier",
|
||||
"$(location //:prettier)",
|
||||
|
|
@ -10,9 +10,12 @@ py_binary(
|
|||
"$(location //buildscripts:shellscripts_linters)",
|
||||
"--rules-lint-format",
|
||||
"$(location :rules_lint_format)",
|
||||
"--rules-lint-format-check",
|
||||
"$(location :rules_lint_format.check)",
|
||||
],
|
||||
data = [
|
||||
":rules_lint_format",
|
||||
":rules_lint_format.check",
|
||||
"//:prettier",
|
||||
"//buildscripts:shellscripts_linters",
|
||||
"@shfmt",
|
||||
|
|
@ -20,10 +23,10 @@ py_binary(
|
|||
env = {
|
||||
"SHFMT_PATH": "$(execpath @shfmt//:shfmt)",
|
||||
},
|
||||
main = "format.py",
|
||||
main = "rules_lint_format_wrapper.py",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//buildscripts:buildifier",
|
||||
"//buildscripts:unittest_grouper",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -34,9 +37,8 @@ format_multirun(
|
|||
html = "//:prettier",
|
||||
markdown = "//:prettier",
|
||||
sql = "//:prettier",
|
||||
starlark = "@buildifier_prebuilt//:buildifier",
|
||||
visibility = ["//visibility:public"],
|
||||
# TODO(SERVER-101031): Use rules_lint buildifier formatter once set up
|
||||
# starlark = "@buildifier_prebuilt//:buildifier",
|
||||
# TODO(SERVER-101033): Enable clang_format once a way to only format a user's changeset is set up
|
||||
# cc = "//:clang_format",
|
||||
# c = "//:clang_format",
|
||||
|
|
|
|||
|
|
@ -3,21 +3,21 @@ import os
|
|||
import pathlib
|
||||
import subprocess
|
||||
|
||||
from buildscripts import download_buildifier
|
||||
from buildscripts.buildifier import fix_all, lint_all
|
||||
from buildscripts.unittest_grouper import validate_bazel_groups
|
||||
|
||||
|
||||
def run_rules_lint(rules_lint_format_path: pathlib.Path, check: bool) -> bool:
|
||||
def run_rules_lint(
|
||||
rules_lint_format_path: pathlib.Path, rules_lint_format_check_path: pathlib.Path, check: bool
|
||||
) -> bool:
|
||||
try:
|
||||
command = [str(rules_lint_format_path)]
|
||||
env = os.environ
|
||||
if check:
|
||||
command = [str(rules_lint_format_check_path)]
|
||||
print("Running rules_lint formatter in check mode")
|
||||
env["mode"] = "check"
|
||||
else:
|
||||
command = [str(rules_lint_format_path)]
|
||||
print("Running rules_lint formatter")
|
||||
repo_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
subprocess.run(command, check=True, env=env, cwd=repo_path)
|
||||
subprocess.run(command, check=True, env=os.environ, cwd=repo_path)
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
return True
|
||||
|
|
@ -38,19 +38,6 @@ def run_shellscripts_linters(shellscripts_linters: pathlib.Path, check: bool) ->
|
|||
return True
|
||||
|
||||
|
||||
def run_buildifier(check: bool) -> bool:
|
||||
binary_path = os.path.join(os.curdir, "buildifier")
|
||||
if not os.path.exists(binary_path):
|
||||
download_buildifier.download(download_location=os.curdir)
|
||||
if check:
|
||||
print("Running buildifier linter")
|
||||
return lint_all(binary_path, generate_report=True)
|
||||
else:
|
||||
print("Running buildifier formatter")
|
||||
fix_all(binary_path)
|
||||
return True
|
||||
|
||||
|
||||
def run_prettier(prettier: pathlib.Path, check: bool) -> bool:
|
||||
# Explicitly ignore anything in the output directories or any symlinks in the root of the repository
|
||||
# to prevent bad symlinks from failing the run, see https://github.com/prettier/prettier/issues/11568 as
|
||||
|
|
@ -125,6 +112,12 @@ def main() -> int:
|
|||
required=True,
|
||||
type=pathlib.Path,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rules-lint-format-check",
|
||||
help="Set the path to rules_lint's formatter check script",
|
||||
required=True,
|
||||
type=pathlib.Path,
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
prettier_path: pathlib.Path = args.prettier.resolve()
|
||||
|
|
@ -132,12 +125,13 @@ def main() -> int:
|
|||
|
||||
os.chdir(default_dir)
|
||||
|
||||
validate_bazel_groups(generate_report=True, fix=not args.check)
|
||||
|
||||
return (
|
||||
0
|
||||
if run_rules_lint(args.rules_lint_format, args.check)
|
||||
if run_rules_lint(args.rules_lint_format, args.rules_lint_format_check, args.check)
|
||||
and run_shellscripts_linters(shellscripts_linters_path, args.check)
|
||||
and run_prettier(prettier_path, args.check)
|
||||
and run_buildifier(args.check)
|
||||
else 1
|
||||
)
|
||||
|
||||
|
|
@ -149,6 +149,7 @@ py_library(
|
|||
"typing-extensions",
|
||||
group = "core",
|
||||
),
|
||||
"simple_report",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue