Skip to content

Enable default buildifier lint warnings and clean up #2323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
82b94a8
Enable default lint warnings with some disabled
avdv Aug 1, 2025
4226e72
Suppress print linter warnings
avdv Aug 1, 2025
2c860de
Fix no-effect lint warning
avdv Aug 1, 2025
6c9a8fc
Suppress no-effect warning
avdv Aug 1, 2025
5fb6cc7
Fix no-effect warnings
avdv Aug 1, 2025
0b999bb
Fix return-value warnings
avdv Aug 1, 2025
6a89172
Fix uninitialized warning
avdv Aug 1, 2025
07ee9a7
Fix uninitialized warning
avdv Aug 1, 2025
27ca344
Fix uninitialized warning
avdv Aug 1, 2025
f3e7187
Accept hexadecimal field keys in dynamic section
avdv Aug 2, 2025
06284a6
Explicitly depend on rules_shell
avdv Aug 4, 2025
9d37bf4
Auto-fix warnings
avdv Aug 4, 2025
841a5e4
rules_haskell_nix: Always enable bzlmod
avdv Aug 4, 2025
4f800a3
rules_haskell_nix: Override path to rules_haskell
avdv Aug 4, 2025
c002648
rules_haskell_nix: Update dependencies
avdv Aug 4, 2025
b68c7b4
Fix positional-args warning
avdv Aug 5, 2025
2b95128
Fix name-conventions warnings
avdv Aug 5, 2025
bfe8a58
Fix confusing-name warnings
avdv Aug 5, 2025
6cc5ce1
Fix depset-union warning
avdv Aug 5, 2025
0032dbc
Fix overly-nested-depset warnings
avdv Aug 5, 2025
3fe8bbf
Remove `hie_bios_path_prefix` attr from `haskell_repl`
avdv Aug 5, 2025
72b9d0a
Fix unnamed-macro warnings
avdv Aug 8, 2025
0dd61cd
Disable provider-params warnings
avdv Aug 8, 2025
29fa920
Disable bzl-visibility warnings
avdv Aug 8, 2025
3f40c24
Load `sh_test` and `sh_binary` rules from rules_shell
avdv Aug 8, 2025
f7f1d0e
Add dependency on rules_shell to workspace
avdv Aug 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ bazel_dep(
name = "rules_python",
version = "0.21.0",
)
bazel_dep(
name = "rules_shell",
version = "0.2.0",
)
bazel_dep(
name = "bazel_skylib",
version = "1.5.0",
Expand Down
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ load("//haskell:repositories.bzl", "rules_haskell_dependencies")

rules_haskell_dependencies()

load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")

rules_shell_dependencies()

rules_shell_toolchains()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
Expand Down Expand Up @@ -85,6 +91,7 @@ load(
"nixpkgs_package",
)

# buildifier: disable=no-effect
asterius_dependencies_nix(
nix_repository = "@nixpkgs_default",
nixpkgs_package_rule = nixpkgs_package,
Expand Down
16 changes: 14 additions & 2 deletions buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ buildifier_exclude_patterns = [
]

_lint_warnings = [
"load",
"unused-variable",
"-function-docstring", # TODO
"-function-docstring-args", # TODO
"-function-docstring-header", # TODO
"-function-docstring-return", # TODO
"-native-cc-common",
"-native-cc-info",
"-native-cc-library",
"-native-cc-shared-library-info",
"-native-java-common",
"-native-java-info",
"-native-proto",
"-native-proto-common",
"-native-proto-info",
"-module-docstring",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will get to fixing them eventually, but I disabled them for now. I'll add an issue to work on the TODOs after this is merged.

]

# Run this to fix the errors in BUILD files.
Expand Down
7 changes: 5 additions & 2 deletions debug/linking_utils/ldd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def memoized(cache, f, arg):

### IO functions that find elf dependencies

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

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

def __query_dynamic_fields(df, key):
Expand Down
2 changes: 2 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bzl_library(
deps = [
":haskell_nix",
"//haskell",
"@rules_shell//shell:rules_bzl",
],
),
# Generate markdown API documentation.
Expand All @@ -78,6 +79,7 @@ bzl_library(
deps = [
":haskell_nix",
"//haskell",
"@rules_shell//shell:rules_bzl",
],
),
# Convert markdown to html.
Expand Down
1 change: 1 addition & 0 deletions haskell/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ load(
"haskell_toolchain_info",
)
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

exports_files(
glob(["*.bzl"]) + [
Expand Down
12 changes: 7 additions & 5 deletions haskell/asterius/asterius_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ npm_repositories()
def asterius_dependencies_nix(
nix_repository,
nixpkgs_package_rule,
name = "rules_haskell",
nixpkgs_nodejs = DEFAULT_NIXPKGS_NODEJS,
register = True):
"""Install asterius dependencies based on nix.
Expand All @@ -87,22 +88,23 @@ npm_repositories()

_nixpkgs_nodejs(nixpkgs_nodejs, nix_repository, nixpkgs_package_rule)

node_toolchain_name = name + "_nix_node_toolchain"
_declare_nix_node_toolchain(
name = "rules_haskell_nix_node_toolchain",
name = node_toolchain_name,
nixpkgs_nodejs = nixpkgs_nodejs,
)
if register:
native.register_toolchains("@rules_haskell_nix_node_toolchain//:node_nixpkgs_toolchain")
native.register_toolchains("@{}//:node_nixpkgs_toolchain".format(node_toolchain_name))
npm_translate_lock(
name = "rules_haskell_npm",
name = name + "_npm",
pnpm_lock = DEFAULT_PNPM_LOCK,
verify_node_modules_ignored = "@rules_haskell//:.bazelignore",
link_workspace = "rules_haskell",
)
_ahc_target_build_setting(name = "rules_haskell_asterius_build_setting")
_ahc_target_build_setting(name = name + "_asterius_build_setting")

_declare_webpack(
name = "rules_haskell_asterius_webpack",
name = name + "_asterius_webpack",
)

def asterius_dependencies_custom(webpack_cli_package_json_bzl):
Expand Down
4 changes: 2 additions & 2 deletions haskell/asterius/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ browser_transition = rule(
doc = "Wrapper rule used to execute webpack and its ahc_dist dependency in a configuration where asterius targets the browser",
)

def _name_of_label(l):
return l.split(":")[-1]
def _name_of_label(label):
return label.split(":")[-1]

def asterius_webpack(name, ahc_dist_dep, entry_point, tags = [], srcs = [], **kwargs):
"""
Expand Down
5 changes: 3 additions & 2 deletions haskell/asterius/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def rules_haskell_asterius_toolchain(
native.register_toolchains("@{}//:wasm_cc_toolchain".format(toolchain_name))

def rules_haskell_asterius_toolchains(
name = "asterius",
version = AHC_DEFAULT_VERSION,
ghcopts = [],
cabalopts = [],
Expand All @@ -297,7 +298,7 @@ def rules_haskell_asterius_toolchains(
fail("Binary distribution of Asterius {} not available.".format(version))
for platform in AHC_BINDIST[version]:
# Download the asterius bundle.
bundle_repo_name = "asterius_bundle_{}".format(platform)
bundle_repo_name = "{}_bundle_{}".format(name, platform)
_asterius_bundle(
name = bundle_repo_name,
version = version,
Expand All @@ -319,7 +320,7 @@ def rules_haskell_asterius_toolchains(
(asterius_lib_setting_file, ahc_pkg, asterius_binaries, full_bundle, wasm_cc_toolchain) = _labels_from_bundle_name(bundle_repo_name, version)

rules_haskell_asterius_toolchain(
"{}_asterius".format(platform),
"{}_{}".format(platform, name),
version,
exec_constraints,
asterius_lib_setting_file,
Expand Down
14 changes: 8 additions & 6 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def _cabal_tool_flag(tool):
"""Return a --with-PROG=PATH flag if input is a recognized Cabal tool. None otherwise."""
if tool.basename in _CABAL_TOOLS:
return "--with-{}={}".format(tool.basename, tool.path)
return None

def _binary_paths(binaries):
return [binary.dirname for binary in binaries.to_list()]
Expand Down Expand Up @@ -2333,13 +2334,13 @@ _stack_update = repository_rule(
# Marked as local so that stack update is always executed before
# _stack_snapshot is executed.
local = True,
)
"""Execute stack update.
doc = """Execute stack update.

This is extracted into a singleton repository rule to avoid concurrent
invocations of stack update.
See https://github.com/tweag/rules_haskell/issues/1090
"""
""",
)

def _get_platform(repository_ctx):
"""Map OS name and architecture to Stack platform identifiers."""
Expand Down Expand Up @@ -2387,8 +2388,8 @@ def _fetch_stack_impl(repository_ctx):
if not error:
repository_ctx.symlink(stack_cmd, "stack")
return
print(error)
print("Downloading Stack {} ...".format(_STACK_DEFAULT_VERSION))
print(error) # buildifier: disable=print
print("Downloading Stack {} ...".format(_STACK_DEFAULT_VERSION)) # buildifier: disable=print
(os, arch) = _get_platform(repository_ctx)
version = _STACK_DEFAULT_VERSION
(url, sha256) = _STACK_BINDISTS[version]["{}-{}".format(os, arch)]
Expand Down Expand Up @@ -2424,8 +2425,9 @@ _fetch_stack = repository_rule(
_fetch_stack_impl,
configure = True,
environ = ["PATH"],
doc =
"""Find a suitably recent local Stack or download it.""",
)
"""Find a suitably recent local Stack or download it."""

def stack_snapshot(
name,
Expand Down
6 changes: 5 additions & 1 deletion haskell/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ load(
_haskell_test_impl = "haskell_test_impl",
_haskell_toolchain_library_impl = "haskell_toolchain_library_impl",
)
load(
":providers.bzl",
"HaskellLibraryInfo",
)
load(
":repl.bzl",
_haskell_repl = "haskell_repl",
Expand Down Expand Up @@ -194,7 +198,7 @@ _haskell_library = rule(
attrs = dict(
_haskell_common_attrs,
hidden_modules = attr.string_list(),
reexported_modules = attr.label_keyed_string_dict(),
reexported_modules = attr.label_keyed_string_dict(providers = [HaskellLibraryInfo]),
exports = attr.label_list(
default = [],
aspects = [haskell_cc_libraries_aspect],
Expand Down
7 changes: 4 additions & 3 deletions haskell/doctest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ omitted, all exposed modules provided by `deps` will be tested.
"@rules_haskell//haskell:doctest-toolchain",
"@rules_sh//sh/posix:toolchain_type",
],
)
"""Run doctest test on targets in `deps`.
doc =
"""Run doctest test on targets in `deps`.

Note that your toolchain must be equipped with `doctest` executable, i.e.
you should specify location of the executable using the `doctest` attribute
of `haskell_doctest_toolchain`.
"""
""",
)
34 changes: 17 additions & 17 deletions haskell/experimental/private/module.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ def _build_haskell_module(
"""

version = getattr(ctx.attr, "version", None)
moduleAttr = module[HaskellModuleInfo].attr
module_attr = module[HaskellModuleInfo].attr

# Collect dependencies
src = moduleAttr.src.files.to_list()[0]
extra_srcs = [f for t in moduleAttr.extra_srcs + ctx.attr.extra_srcs for f in t.files.to_list()]
src = module_attr.src.files.to_list()[0]
extra_srcs = [f for t in module_attr.extra_srcs + ctx.attr.extra_srcs for f in t.files.to_list()]

user_ghcopts = []
user_ghcopts += haskell_library_expand_make_variables("ghcopts", ctx, ctx.attr.ghcopts)

module_extra_attrs = [
[moduleAttr.src],
moduleAttr.extra_srcs,
moduleAttr.plugins,
moduleAttr.tools,
[module_attr.src],
module_attr.extra_srcs,
module_attr.plugins,
module_attr.tools,
]

user_compile_flags = expand_make_variables("ghcopts", ctx, moduleAttr.ghcopts, module_extra_attrs)
user_compile_flags = expand_make_variables("ghcopts", ctx, module_attr.ghcopts, module_extra_attrs)
user_ghcopts += user_compile_flags

import_dir = None
Expand All @@ -168,13 +168,13 @@ def _build_haskell_module(
import_dir = idir

# Note [Plugin order]
plugin_decl = reversed(ctx.attr.plugins + moduleAttr.plugins)
plugin_decl = reversed(ctx.attr.plugins + module_attr.plugins)
plugin_dep_info = gather_dep_info(
moduleAttr.name,
module_attr.name,
[dep for plugin in plugin_decl for dep in plugin[GhcPluginInfo].deps],
)
plugins = [resolve_plugin_tools(ctx, plugin[GhcPluginInfo]) for plugin in plugin_decl]
(preprocessors_inputs, preprocessors_input_manifests) = ctx.resolve_tools(tools = ctx.attr.tools + moduleAttr.tools)
(preprocessors_inputs, preprocessors_input_manifests) = ctx.resolve_tools(tools = ctx.attr.tools + module_attr.tools)

# TODO[AH] Support additional outputs such as `.hie`.

Expand All @@ -185,14 +185,14 @@ def _build_haskell_module(
main_function = getattr(ctx.attr, "main_function", None)

if main_function:
if moduleAttr.module_name:
guess_module_name = moduleAttr.module_name
if module_attr.module_name:
guess_module_name = module_attr.module_name
else:
guess_module_name = get_module_path_from_target(module).replace("/", ".")

main_file = getattr(ctx.attr, "main_file", None)
main_function_module = infer_main_module(main_function)
if (moduleAttr.src == main_file or main_function_module == guess_module_name):
if (module_attr.src == main_file or main_function_module == guess_module_name):
args.add_all(["-main-is", ctx.attr.main_function])

args.add_all([
Expand Down Expand Up @@ -319,11 +319,11 @@ def _build_haskell_module(

outputs = [module_outputs.hi, module_outputs.abi]
if module_outputs.o:
outputs += [module_outputs.o]
outputs.append(module_outputs.o)
if with_shared:
outputs += [module_outputs.dyn_hi]
outputs.append(module_outputs.dyn_hi)
if module_outputs.dyn_o:
outputs += [module_outputs.dyn_o]
outputs.append(module_outputs.dyn_o)

input_files = [src] + extra_srcs + [optp_args_file]
if enable_th and extra_ldflags_file:
Expand Down
12 changes: 6 additions & 6 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,25 @@ def _ghc_bindist_impl(ctx):
# the raw distribution.
unpack_dir = "bindist_unpacked" if os != "windows" else ""

stripPrefix = "ghc-" + version
strip_prefix = "ghc-" + version
if GHC_BINDIST_STRIP_PREFIX.get(version) != None and GHC_BINDIST_STRIP_PREFIX[version].get(target) != None:
stripPrefix = GHC_BINDIST_STRIP_PREFIX[version][target]
strip_prefix = GHC_BINDIST_STRIP_PREFIX[version][target]
else:
arch_suffix = {"arm64": "aarch64", "amd64": "x86_64"}.get(arch)

if os == "windows" and version_tuple >= (9, 0, 1):
stripPrefix += "-{}-unknown-mingw32".format(arch_suffix)
strip_prefix += "-{}-unknown-mingw32".format(arch_suffix)
elif os == "darwin" and version_tuple >= (9, 0, 2):
stripPrefix += "-{}-apple-darwin".format(arch_suffix)
strip_prefix += "-{}-apple-darwin".format(arch_suffix)
elif os == "linux" and version_tuple >= (9, 4, 1):
stripPrefix += "-{}-unknown-linux".format(arch_suffix)
strip_prefix += "-{}-unknown-linux".format(arch_suffix)

ctx.download_and_extract(
url = url,
output = unpack_dir,
sha256 = sha256,
type = "tar.xz",
stripPrefix = stripPrefix,
stripPrefix = strip_prefix,
)

if os == "windows":
Expand Down
4 changes: 3 additions & 1 deletion haskell/platforms/list.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ARCH = {
"x86_64": "x86_64",
}

def declare_config_settings():
def declare_config_settings(name = None):
for os, constraint_value in OS.items():
if constraint_value:
native.config_setting(
Expand All @@ -54,6 +54,7 @@ def os_of_constraints(constraints):
for c in constraints:
if c.package == "os":
return find(OS, c.name)
return None

def arch_of_constraints(constraints):
""" Returns the architecture corresponding to the first arch constraint.
Expand All @@ -62,6 +63,7 @@ def arch_of_constraints(constraints):
for c in constraints:
if c.package == "cpu":
return find(ARCH, c.name)
return None

def platform_of_constraints(constraints):
os = os_of_constraints(constraints)
Expand Down
Loading