Skip to content
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

Refactoring for bzlmod #1905

Merged
merged 5 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
49 changes: 8 additions & 41 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")

exports_files(["start"])

exports_files(
Expand All @@ -11,9 +9,14 @@ exports_files(
visibility = ["//tests/shellcheck:__pkg__"],
)

buildifier_exclude_patterns = [
"./vendor/**",
]
exports_files(
[
"BUILD.bazel",
"WORKSPACE",
"constants.bzl",
],
visibility = ["//buildifier:__pkg__"],
)

filegroup(
name = "distribution",
Expand All @@ -36,39 +39,3 @@ filegroup(
],
visibility = ["//visibility:public"],
)

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

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

buildifier_test(
name = "buildifier_test",
srcs = [
"BUILD.bazel",
"WORKSPACE",
"constants.bzl",
"//debug/linking_utils:all_files",
"//docs:all_files",
"//haskell:all_files",
"//nixpkgs:all_files",
"//rule_info:all_files",
"//tests:all_files",
"//tools:all_files",
"@examples-arm//:all_files",
"@examples//:all_files",
"@tutorial//:all_files",
],
mode = "diff",
tags = ["dont_test_on_windows"],
)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,20 @@ on every development system (`python`, `ghc`, `go`, …).
To build and run tests locally, execute:

```
$ bazel test //...
$ bazel test //... && cd rules_haskell_tests && bazel test //...
```

Starlark code in this project is formatted according to the output of
[buildifier]. You can check that the formatting is correct using:

```
$ bazel run //:buildifier
$ bazel run //buildifier && cd rules_haskell_tests && bazel run //buildifier
```

If tests fail then run the following to fix the formatting:

```
$ git rebase --exec "bazel run //:buildifier-fix" <first commit>
$ git rebase --exec "bazel run //buildifier:buildifier-fix && cd rules_haskell_tests && bazel run //buildifier:buildifier-fix" <first commit>
```

where `<first commit>` is the first commit in your pull request.
Expand Down
58 changes: 58 additions & 0 deletions buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")

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

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

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

buildifier_test(
name = "buildifier_test",
srcs = [
"//:BUILD.bazel",
"//:WORKSPACE",
"//:constants.bzl",
"//:non_module_deps.bzl",
"//:non_module_dev_deps.bzl",
"//:non_module_dev_deps_2.bzl",
"//buildifier:all_files",
"//debug/linking_utils:all_files",
"//docs:all_files",
"//extensions:all_files",
"//haskell:all_files",
"//nixpkgs:all_files",
"//rule_info:all_files",
"//tests:all_files",
"//tools:all_files",
"@examples-arm//:all_files",
"@examples//:all_files",
"@tutorial//:all_files",
],
mode = "diff",
tags = [
"dont_test_on_windows",
"manual",
],
)

filegroup(
name = "all_files",
testonly = True,
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
45 changes: 25 additions & 20 deletions haskell/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ _rules_nixpkgs_sha256 = "a8f20854da16156bd4e0d53d13dfb0d3360ee43c5ce764f0dc60703
_rules_sh_version = "v0.3.0"
_rules_sh_sha256 = "d668bb32f112ead69c58bde2cae62f6b8acefe759a8c95a2d80ff6a85af5ac5e"

def rules_haskell_dependencies_bzlmod():
"""Provide rules_haskell dependencies which are not available as bzlmod modules."""

# Dependency of com_google_protobuf.
# TODO(judahjacobson): this is a bit of a hack.
# We can't call that repository's protobuf_deps() function
# from here, because load()ing it from this .bzl file would lead
# to a cycle:
# https://github.com/bazelbuild/bazel/issues/1550
# https://github.com/bazelbuild/bazel/issues/1943
# For now, just hard-code the subset that's needed to use `protoc`.
# Alternately, consider adding another function from another
# .bzl file that needs to be called from WORKSPACE, similar to:
# https://github.com/grpc/grpc/blob/8c9dcf7c35e489c2072a9ad86635dbc4e28f88ea/bazel/grpc_extra_deps.bzl#L10
maybe(
http_archive,
name = "zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff",
strip_prefix = "zlib-1.2.11",
urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"],
)

def rules_haskell_dependencies():
"""Provide all repositories that are necessary for `rules_haskell` to function."""
if "bazel_version" in dir(native):
Expand Down Expand Up @@ -108,26 +131,6 @@ def rules_haskell_dependencies():
],
)

# Dependency of com_google_protobuf.
# TODO(judahjacobson): this is a bit of a hack.
# We can't call that repository's protobuf_deps() function
# from here, because load()ing it from this .bzl file would lead
# to a cycle:
# https://github.com/bazelbuild/bazel/issues/1550
# https://github.com/bazelbuild/bazel/issues/1943
# For now, just hard-code the subset that's needed to use `protoc`.
# Alternately, consider adding another function from another
# .bzl file that needs to be called from WORKSPACE, similar to:
# https://github.com/grpc/grpc/blob/8c9dcf7c35e489c2072a9ad86635dbc4e28f88ea/bazel/grpc_extra_deps.bzl#L10
maybe(
http_archive,
name = "zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff",
strip_prefix = "zlib-1.2.11",
urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"],
)

maybe(
http_archive,
name = "aspect_rules_js",
Expand All @@ -136,6 +139,8 @@ def rules_haskell_dependencies():
url = "https://github.com/aspect-build/rules_js/releases/download/v1.23.1/rules_js-v1.23.1.tar.gz",
)

rules_haskell_dependencies_bzlmod()

def haskell_repositories():
"""Alias for rules_haskell_dependencies

Expand Down
27 changes: 6 additions & 21 deletions rules_haskell_tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")

# Run this to check for errors in BUILD files.
buildifier(
name = "buildifier",
mode = "check",
)

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

buildifier_test(
name = "buildifier_test",
srcs = [
exports_files(
[
"BUILD.bazel",
"WORKSPACE",
"//tests:all_files",
"non_module_deps.bzl",
"non_module_deps_1.bzl",
"non_module_deps_2.bzl",
],
mode = "diff",
tags = ["dont_test_on_windows"],
visibility = ["//buildifier:__pkg__"],
)
25 changes: 25 additions & 0 deletions rules_haskell_tests/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ load("non_module_deps_2.bzl", repositories_2 = "repositories")

repositories_2(bzlmod = False)

load(
"@rules_haskell//haskell/asterius:repositories.bzl",
"asterius_dependencies_bindist",
"asterius_dependencies_nix",
)
load(
"@rules_nixpkgs_core//:nixpkgs.bzl",
"nixpkgs_package",
)

asterius_dependencies_nix(
nix_repository = "@nixpkgs_default",
nixpkgs_package_rule = nixpkgs_package,
) if is_nix_shell else asterius_dependencies_bindist()

load("@rules_haskell_npm//:repositories.bzl", "npm_repositories")

npm_repositories()
Expand All @@ -117,6 +132,15 @@ jvm_maven_import_external(
server_urls = ["https://repo.maven.apache.org/maven2"],
)

http_archive(
name = "io_bazel_stardoc",
sha256 = "3fd8fec4ddec3c670bd810904e2e33170bedfe12f90adf943508184be458c8bb",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz",
],
)

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()
Expand Down Expand Up @@ -166,3 +190,4 @@ bind(
name = "python_headers",
actual = "@com_google_protobuf//util/python:python_headers",
)

41 changes: 41 additions & 0 deletions rules_haskell_tests/buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")

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

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

buildifier_test(
name = "buildifier_test",
srcs = [
"//:BUILD.bazel",
"//:WORKSPACE",
"//:non_module_deps.bzl",
"//:non_module_deps_1.bzl",
"//:non_module_deps_2.bzl",
"//buildifier:all_files",
"//tests:all_files",
],
mode = "diff",
tags = [
"dont_test_on_windows",
"manual",
],
)

filegroup(
name = "all_files",
testonly = True,
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
10 changes: 0 additions & 10 deletions rules_haskell_tests/non_module_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ cc_library(
],
)

# Does not support bzlmod yet
http_archive(
name = "io_bazel_stardoc",
sha256 = "3fd8fec4ddec3c670bd810904e2e33170bedfe12f90adf943508184be458c8bb",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz",
],
)

def _non_module_deps_impl(_ctx):
repositories(bzlmod = True)

Expand Down
10 changes: 1 addition & 9 deletions rules_haskell_tests/non_module_deps_1.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ load(
load("@rules_nixpkgs_python//:python.bzl", "nixpkgs_python_configure")
load("@rules_nixpkgs_go//:go.bzl", "nixpkgs_go_configure")
load("@rules_nixpkgs_cc//:cc.bzl", "nixpkgs_cc_configure")
load("@os_info//:os_info.bzl", "is_linux", "is_nix_shell", "is_windows")
load("@os_info//:os_info.bzl", "is_linux", "is_windows")
load(
"@rules_haskell//haskell/asterius:repositories.bzl",
"asterius_dependencies_bindist",
"asterius_dependencies_nix",
"rules_haskell_asterius_toolchains",
"toolchain_libraries",
)
Expand Down Expand Up @@ -105,12 +103,6 @@ filegroup(
register = not bzlmod,
)

asterius_dependencies_nix(
nix_repository = "@nixpkgs_default",
nixpkgs_package_rule = nixpkgs_package,
register = not bzlmod,
) if is_nix_shell else asterius_dependencies_bindist(register = not bzlmod)

rules_haskell_asterius_toolchains(
cabalopts = test_cabalopts,
ghcopts = test_ghcopts,
Expand Down