Skip to content

Commit

Permalink
Fix buildifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecornec committed Jun 16, 2023
1 parent 4323e56 commit 5532680
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ exports_files(
"BUILD.bazel",
"WORKSPACE",
"constants.bzl",
"non_module_dev_deps.bzl",
"non_module_dev_deps_2.bzl",
],
visibility = ["//buildifier:__pkg__"],
)
Expand Down
15 changes: 8 additions & 7 deletions buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")
load("@os_info//:os_info.bzl", "is_nixos")

buildifier_exclude_patterns = [
"./vendor/**",
]

# Buildifier does not work yet with bzlmod+nixos
# See https://github.com/bazelbuild/bazel-gazelle/issues/1469
manual_on_nixos = ["manual"] if is_nixos else []

# Run this to check for errors in BUILD files.
buildifier(
name = "buildifier",
exclude_patterns = buildifier_exclude_patterns,
mode = "check",
tags = ["manual"],
tags = manual_on_nixos,
)

# Run this to fix the errors in BUILD files.
buildifier(
name = "buildifier-fix",
exclude_patterns = buildifier_exclude_patterns,
mode = "fix",
tags = ["manual"],
tags = manual_on_nixos,
verbose = True,
)

Expand All @@ -33,7 +38,6 @@ buildifier_test(
"//buildifier:all_files",
"//debug/linking_utils:all_files",
"//docs:all_files",
"//extensions:all_files",
"//haskell:all_files",
"//nixpkgs:all_files",
"//rule_info:all_files",
Expand All @@ -44,10 +48,7 @@ buildifier_test(
"@tutorial//:all_files",
],
mode = "diff",
tags = [
"dont_test_on_windows",
"manual",
],
tags = ["dont_test_on_windows"] + manual_on_nixos,
)

filegroup(
Expand Down
1 change: 0 additions & 1 deletion rules_haskell_tests/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,3 @@ bind(
name = "python_headers",
actual = "@com_google_protobuf//util/python:python_headers",
)

14 changes: 8 additions & 6 deletions rules_haskell_tests/buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")
load("@os_info//:os_info.bzl", "is_nixos")

# Buildifier does not work yet with bzlmod+nixos
# See https://github.com/bazelbuild/bazel-gazelle/issues/1469
manual_on_nixos = ["manual"] if is_nixos else []

# Run this to check for errors in BUILD files.
buildifier(
name = "buildifier",
mode = "check",
tags = ["manual"],
tags = manual_on_nixos,
)

# Run this to fix the errors in BUILD files.
buildifier(
name = "buildifier-fix",
mode = "fix",
tags = ["manual"],
tags = manual_on_nixos,
verbose = True,
)

Expand All @@ -27,10 +32,7 @@ buildifier_test(
"//tests:all_files",
],
mode = "diff",
tags = [
"dont_test_on_windows",
"manual",
],
tags = ["dont_test_on_windows"] + manual_on_nixos,
)

filegroup(
Expand Down
3 changes: 3 additions & 0 deletions tools/os_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ is_linux = cpu_value == "k8" or cpu_value == "aarch64"
is_windows = cpu_value == "x64_windows"
nix_shell = {NIX_SHELL}
is_nix_shell = nix_shell != None
is_nixos = {IS_NIXOS}
"""

def _os_info_impl(repository_ctx):
Expand All @@ -22,9 +23,11 @@ def _os_info_impl(repository_ctx):
if cpu not in known_cpu_values:
fail("Unknown OS type {}, expected one of {}".format(cpu, ", ".join(known_cpu_values)))
nix_shell = repository_ctx.os.environ.get("IN_NIX_SHELL")
is_nixos = repository_ctx.execute(["test", "-e", "/etc/NIXOS"]).return_code == 0
os_info_substitutions = {
"CPU_VALUE": cpu,
"NIX_SHELL": repr(nix_shell),
"IS_NIXOS": is_nixos,
}
repository_ctx.file(
"os_info.bzl",
Expand Down

0 comments on commit 5532680

Please sign in to comment.