Skip to content

Commit c82a048

Browse files
authored
Merge pull request #2323 from tweag/cb/fix-lint-warnings
Enable default buildifier lint warnings and clean up
2 parents 8deb784 + e6e0771 commit c82a048

File tree

54 files changed

+209
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+209
-134
lines changed

MODULE.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ bazel_dep(
3232
name = "rules_python",
3333
version = "0.21.0",
3434
)
35+
bazel_dep(
36+
name = "rules_shell",
37+
version = "0.2.0",
38+
)
3539
bazel_dep(
3640
name = "bazel_skylib",
3741
version = "1.5.0",

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ load("//haskell:repositories.bzl", "rules_haskell_dependencies")
99

1010
rules_haskell_dependencies()
1111

12+
load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")
13+
14+
rules_shell_dependencies()
15+
16+
rules_shell_toolchains()
17+
1218
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1319

1420
http_archive(
@@ -85,6 +91,7 @@ load(
8591
"nixpkgs_package",
8692
)
8793

94+
# buildifier: disable=no-effect
8895
asterius_dependencies_nix(
8996
nix_repository = "@nixpkgs_default",
9097
nixpkgs_package_rule = nixpkgs_package,

buildifier/BUILD.bazel

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ buildifier_exclude_patterns = [
55
]
66

77
_lint_warnings = [
8-
"load",
9-
"unused-variable",
8+
"-function-docstring", # TODO
9+
"-function-docstring-args", # TODO
10+
"-function-docstring-header", # TODO
11+
"-function-docstring-return", # TODO
12+
"-native-cc-common",
13+
"-native-cc-info",
14+
"-native-cc-library",
15+
"-native-cc-shared-library-info",
16+
"-native-java-common",
17+
"-native-java-info",
18+
"-native-proto",
19+
"-native-proto-common",
20+
"-native-proto-info",
21+
"-module-docstring",
1022
]
1123

1224
# Run this to fix the errors in BUILD files.

debug/linking_utils/ldd.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def memoized(cache, f, arg):
4444

4545
### IO functions that find elf dependencies
4646

47-
_field_matcher = re.compile(b" ([A-Z0-9_]+) +(.*)$")
47+
_field_matcher = re.compile(b" ([A-Zx0-9_]+) +(.*)$")
4848

4949
def read_dynamic_fields(elf_path):
5050
"""Read the dynamic header fields from an elf binary
@@ -70,7 +70,10 @@ def read_dynamic_fields(elf_path):
7070
dyn_section = to_end[: 1 + to_end.find(b"\n\n")]
7171
def read_dynamic_field(s):
7272
"""return (field_key, field_value)"""
73-
return _field_matcher.match(s).groups()
73+
m = _field_matcher.match(s)
74+
if not m:
75+
raise Exception("{}: could not match {}".format(elf_path, s))
76+
return m.groups()
7477
return list(map(read_dynamic_field, dyn_section.splitlines(True)))
7578

7679
def __query_dynamic_fields(df, key):

docs/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bzl_library(
6262
deps = [
6363
":haskell_nix",
6464
"//haskell",
65+
"@rules_shell//shell:rules_bzl",
6566
],
6667
),
6768
# Generate markdown API documentation.
@@ -78,6 +79,7 @@ bzl_library(
7879
deps = [
7980
":haskell_nix",
8081
"//haskell",
82+
"@rules_shell//shell:rules_bzl",
8183
],
8284
),
8385
# Convert markdown to html.

haskell/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ load(
2323
"haskell_toolchain_info",
2424
)
2525
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
26+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
2627

2728
exports_files(
2829
glob(["*.bzl"]) + [

haskell/asterius/asterius_dependencies.bzl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ npm_repositories()
6767
def asterius_dependencies_nix(
6868
nix_repository,
6969
nixpkgs_package_rule,
70+
name = "rules_haskell",
7071
nixpkgs_nodejs = DEFAULT_NIXPKGS_NODEJS,
7172
register = True):
7273
"""Install asterius dependencies based on nix.
@@ -87,22 +88,23 @@ npm_repositories()
8788

8889
_nixpkgs_nodejs(nixpkgs_nodejs, nix_repository, nixpkgs_package_rule)
8990

91+
node_toolchain_name = name + "_nix_node_toolchain"
9092
_declare_nix_node_toolchain(
91-
name = "rules_haskell_nix_node_toolchain",
93+
name = node_toolchain_name,
9294
nixpkgs_nodejs = nixpkgs_nodejs,
9395
)
9496
if register:
95-
native.register_toolchains("@rules_haskell_nix_node_toolchain//:node_nixpkgs_toolchain")
97+
native.register_toolchains("@{}//:node_nixpkgs_toolchain".format(node_toolchain_name))
9698
npm_translate_lock(
97-
name = "rules_haskell_npm",
99+
name = name + "_npm",
98100
pnpm_lock = DEFAULT_PNPM_LOCK,
99101
verify_node_modules_ignored = "@rules_haskell//:.bazelignore",
100102
link_workspace = "rules_haskell",
101103
)
102-
_ahc_target_build_setting(name = "rules_haskell_asterius_build_setting")
104+
_ahc_target_build_setting(name = name + "_asterius_build_setting")
103105

104106
_declare_webpack(
105-
name = "rules_haskell_asterius_webpack",
107+
name = name + "_asterius_webpack",
106108
)
107109

108110
def asterius_dependencies_custom(webpack_cli_package_json_bzl):

haskell/asterius/defs.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ browser_transition = rule(
334334
doc = "Wrapper rule used to execute webpack and its ahc_dist dependency in a configuration where asterius targets the browser",
335335
)
336336

337-
def _name_of_label(l):
338-
return l.split(":")[-1]
337+
def _name_of_label(label):
338+
return label.split(":")[-1]
339339

340340
def asterius_webpack(name, ahc_dist_dep, entry_point, tags = [], srcs = [], **kwargs):
341341
"""

haskell/asterius/repositories.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def rules_haskell_asterius_toolchain(
274274
native.register_toolchains("@{}//:wasm_cc_toolchain".format(toolchain_name))
275275

276276
def rules_haskell_asterius_toolchains(
277+
name = "asterius",
277278
version = AHC_DEFAULT_VERSION,
278279
ghcopts = [],
279280
cabalopts = [],
@@ -297,7 +298,7 @@ def rules_haskell_asterius_toolchains(
297298
fail("Binary distribution of Asterius {} not available.".format(version))
298299
for platform in AHC_BINDIST[version]:
299300
# Download the asterius bundle.
300-
bundle_repo_name = "asterius_bundle_{}".format(platform)
301+
bundle_repo_name = "{}_bundle_{}".format(name, platform)
301302
_asterius_bundle(
302303
name = bundle_repo_name,
303304
version = version,
@@ -319,7 +320,7 @@ def rules_haskell_asterius_toolchains(
319320
(asterius_lib_setting_file, ahc_pkg, asterius_binaries, full_bundle, wasm_cc_toolchain) = _labels_from_bundle_name(bundle_repo_name, version)
320321

321322
rules_haskell_asterius_toolchain(
322-
"{}_asterius".format(platform),
323+
"{}_{}".format(platform, name),
323324
version,
324325
exec_constraints,
325326
asterius_lib_setting_file,

haskell/cabal.bzl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def _cabal_tool_flag(tool):
144144
"""Return a --with-PROG=PATH flag if input is a recognized Cabal tool. None otherwise."""
145145
if tool.basename in _CABAL_TOOLS:
146146
return "--with-{}={}".format(tool.basename, tool.path)
147+
return None
147148

148149
def _binary_paths(binaries):
149150
return [binary.dirname for binary in binaries.to_list()]
@@ -2333,13 +2334,13 @@ _stack_update = repository_rule(
23332334
# Marked as local so that stack update is always executed before
23342335
# _stack_snapshot is executed.
23352336
local = True,
2336-
)
2337-
"""Execute stack update.
2337+
doc = """Execute stack update.
23382338
23392339
This is extracted into a singleton repository rule to avoid concurrent
23402340
invocations of stack update.
23412341
See https://github.com/tweag/rules_haskell/issues/1090
2342-
"""
2342+
""",
2343+
)
23432344

23442345
def _get_platform(repository_ctx):
23452346
"""Map OS name and architecture to Stack platform identifiers."""
@@ -2387,8 +2388,8 @@ def _fetch_stack_impl(repository_ctx):
23872388
if not error:
23882389
repository_ctx.symlink(stack_cmd, "stack")
23892390
return
2390-
print(error)
2391-
print("Downloading Stack {} ...".format(_STACK_DEFAULT_VERSION))
2391+
print(error) # buildifier: disable=print
2392+
print("Downloading Stack {} ...".format(_STACK_DEFAULT_VERSION)) # buildifier: disable=print
23922393
(os, arch) = _get_platform(repository_ctx)
23932394
version = _STACK_DEFAULT_VERSION
23942395
(url, sha256) = _STACK_BINDISTS[version]["{}-{}".format(os, arch)]
@@ -2424,8 +2425,9 @@ _fetch_stack = repository_rule(
24242425
_fetch_stack_impl,
24252426
configure = True,
24262427
environ = ["PATH"],
2428+
doc =
2429+
"""Find a suitably recent local Stack or download it.""",
24272430
)
2428-
"""Find a suitably recent local Stack or download it."""
24292431

24302432
def stack_snapshot(
24312433
name,

0 commit comments

Comments
 (0)