-
Notifications
You must be signed in to change notification settings - Fork 84
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
Separate testing module and bzlmod tests for toolchains/posix #323
Changes from 9 commits
de23563
82d9d6a
4db088f
5964681
b8a8e2a
f709937
2b813e5
0bd0f86
09c9d18
2db227b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,3 @@ | ||
build:bzlmod --enable_bzlmod | ||
|
||
build --host_platform=@rules_nixpkgs_core//platforms:host | ||
|
||
# Using toolchain resolution can lead to spurious dependencies on | ||
# `@local_config_cc//:builtin_include_directory_paths`. This needs to be | ||
# resolved before `--incompatible_enable_cc_toolchain_resolution` can be | ||
# recommended for `nixpkgs_cc_configure_hermetic`. | ||
# build --incompatible_enable_cc_toolchain_resolution | ||
|
||
build --java_runtime_version=nixpkgs_java_11 | ||
build --java_language_version=11 | ||
build --tool_java_runtime_version=nixpkgs_java_11 | ||
build --tool_java_language_version=11 | ||
|
||
# The following lines provide a workaround for a test failure in on the Java | ||
# toolchain on MacOS 11, documented here: https://github.com/tweag/rules_nixpkgs/issues/299. | ||
# They should be removed as soon as that issue has been resolved. | ||
build --enable_platform_specific_config | ||
build:macos --experimental_strict_java_deps=warn | ||
|
||
# User Configuration | ||
# ------------------ | ||
try-import %workspace%/.bazelrc.local | ||
import %workspace%/.bazelrc.common | ||
import %workspace%/.bazelrc.cc | ||
import %workspace%/.bazelrc.java | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build --crosstool_top=@nixpkgs_config_cc//:toolchain | ||
# Using toolchain resolution can lead to spurious dependencies on | ||
# `@local_config_cc//:builtin_include_directory_paths`. This needs to be | ||
# resolved before `--incompatible_enable_cc_toolchain_resolution` can be | ||
# recommended for `nixpkgs_cc_configure_hermetic`. | ||
# build --incompatible_enable_cc_toolchain_resolution | ||
|
||
# vim: ft=conf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
build --host_platform=@rules_nixpkgs_core//platforms:host | ||
|
||
build:bzlmod --enable_bzlmod | ||
build:bzlmod --registry=https://bcr.bazel.build | ||
|
||
# User Configuration | ||
# ------------------ | ||
try-import %workspace%/.bazelrc.local | ||
|
||
# vim: ft=conf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Bazel requires a Java runtime to run tests, so any module that contains tests | ||
# will need Java configuration. However, not all modules should have to depend | ||
# on rules_nixpkgs_java to provide a Java runtime, in particular the core | ||
# module should be free of this dependency. Hence, the Java configuration | ||
# exists in a separate configuration file. | ||
|
||
build --java_runtime_version=nixpkgs_java_11 | ||
build --java_language_version=11 | ||
build --tool_java_runtime_version=nixpkgs_java_11 | ||
build --tool_java_language_version=11 | ||
|
||
# The following lines provide a workaround for a test failure in on the Java | ||
# toolchain on MacOS 11, documented here: https://github.com/tweag/rules_nixpkgs/issues/299. | ||
# They should be removed as soon as that issue has been resolved. | ||
build --enable_platform_specific_config | ||
build:macos --experimental_strict_java_deps=warn | ||
|
||
# vim: ft=conf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
build:bzlmod --enable_bzlmod | ||
|
||
build --host_platform=@rules_nixpkgs_core//platforms:host | ||
|
||
# User Configuration | ||
# ------------------ | ||
try-import %workspace%/.bazelrc.local | ||
import %workspace%/../.bazelrc.common |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import %workspace%/../../.bazelrc.common | ||
import %workspace%/../../.bazelrc.java |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import %workspace%/../../.bazelrc.common | ||
import %workspace%/../../.bazelrc.java |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import %workspace%/../../.bazelrc.common | ||
import %workspace%/../../.bazelrc.java |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module(name = "rules_nixpkgs_posix_testing") | ||
|
||
bazel_dep(name = "rules_nixpkgs_posix") | ||
local_path_override( | ||
module_name = "rules_nixpkgs_posix", | ||
path = "../../toolchains/posix", | ||
) | ||
|
||
bazel_dep(name = "rules_nixpkgs_core") | ||
local_path_override( | ||
module_name = "rules_nixpkgs_core", | ||
path = "../../core", | ||
) | ||
|
||
bazel_dep(name = "rules_nixpkgs_java") | ||
local_path_override( | ||
module_name = "rules_nixpkgs_java", | ||
path = "../../toolchains/java", | ||
) | ||
|
||
bazel_dep(name = "bazel_skylib", version = "1.0.3") | ||
bazel_dep(name = "rules_sh", version = "0.3.0") | ||
|
||
# TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has | ||
# become a module extension in rules_nixpkgs_java. | ||
bazel_dep(name = "platforms", version = "0.0.4") | ||
bazel_dep(name = "rules_java", version = "4.0.0") | ||
|
||
java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") | ||
use_repo(java_toolchains, "remote_java_tools") | ||
|
||
non_module_deps = use_extension("//:non_module_deps.bzl", "non_module_deps") | ||
use_repo(non_module_deps, "nixpkgs") | ||
use_repo(non_module_deps, "nixpkgs_sh_posix_config") | ||
use_repo(non_module_deps, "nixpkgs_sh_posix_config_toolchain") | ||
register_toolchains("@nixpkgs_sh_posix_config_toolchain//:nixpkgs_sh_posix_toolchain") | ||
# Bazel requries a Java runtime to run tests. | ||
use_repo(non_module_deps, "nixpkgs_java_runtime_toolchain") | ||
register_toolchains("@nixpkgs_java_runtime_toolchain//:all") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
workspace(name = "rules_nixpkgs_posix_testing") | ||
|
||
local_repository( | ||
name = "rules_nixpkgs_posix", | ||
path = "../../toolchains/posix", | ||
) | ||
|
||
local_repository( | ||
name = "rules_nixpkgs_core", | ||
path = "../../core", | ||
) | ||
|
||
local_repository( | ||
name = "rules_nixpkgs_java", | ||
path = "../../toolchains/java", | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "bazel_skylib", | ||
sha256 = "f24ab666394232f834f74d19e2ff142b0af17466ea0c69a3f4c276ee75f6efce", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-1.4.0.tar.gz", | ||
], | ||
) | ||
|
||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") | ||
|
||
bazel_skylib_workspace() | ||
|
||
http_archive( | ||
name = "rules_sh", | ||
sha256 = "d668bb32f112ead69c58bde2cae62f6b8acefe759a8c95a2d80ff6a85af5ac5e", | ||
strip_prefix = "rules_sh-0.3.0", | ||
urls = ["https://github.com/tweag/rules_sh/archive/v0.3.0.tar.gz"], | ||
) | ||
|
||
load("@rules_sh//sh:repositories.bzl", "rules_sh_dependencies") | ||
|
||
rules_sh_dependencies() | ||
|
||
load( | ||
"//tests:nixpkgs_repositories.bzl", | ||
"nixpkgs_repositories", | ||
) | ||
|
||
nixpkgs_repositories(bzlmod = False) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../docs/nixpkgs.nix |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load( | ||
"//tests:nixpkgs_repositories.bzl", | ||
"nixpkgs_repositories", | ||
) | ||
|
||
def _non_module_deps_impl(ctx): | ||
nixpkgs_repositories(bzlmod = True) | ||
|
||
non_module_deps = module_extension( | ||
implementation = _non_module_deps_impl, | ||
) | ||
Comment on lines
+6
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is implied by your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly, that's the plan once #183 is implemented (or as part of it). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
load("@rules_nixpkgs_core//:nixpkgs.bzl", "nixpkgs_local_repository") | ||
load("@rules_nixpkgs_java//:java.bzl", "nixpkgs_java_configure") | ||
load("@rules_nixpkgs_posix//:posix.bzl", "nixpkgs_sh_posix_configure") | ||
|
||
def nixpkgs_repositories(*, bzlmod): | ||
nixpkgs_local_repository( | ||
name = "nixpkgs", | ||
nix_file = "//:nixpkgs.nix", | ||
nix_file_deps = ["//:flake.lock"], | ||
) | ||
|
||
nixpkgs_java_configure( | ||
name = "nixpkgs_java_runtime", | ||
attribute_path = "jdk11.home", | ||
repository = "@nixpkgs", | ||
toolchain = True, | ||
register = not bzlmod, | ||
toolchain_name = "nixpkgs_java", | ||
toolchain_version = "11", | ||
) | ||
|
||
nixpkgs_sh_posix_configure( | ||
name = "nixpkgs_sh_posix_config", | ||
repository = "@nixpkgs", | ||
register = not bzlmod, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") | ||
load("@nixpkgs_sh_posix_config//:nixpkgs_sh_posix.bzl", "discovered") | ||
|
||
ResolvedPosixToolchainInfo = provider() | ||
|
||
def _posix_toolchain_impl(ctx): | ||
posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"] | ||
return [ | ||
ResolvedPosixToolchainInfo(commands = posix.commands) | ||
] | ||
|
||
_posix_toolchain = rule( | ||
_posix_toolchain_impl, | ||
toolchains = ["@rules_sh//sh/posix:toolchain_type"], | ||
) | ||
|
||
def _posix_runtime_test_impl(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
commands = ctx.attr.toolchain[ResolvedPosixToolchainInfo].commands | ||
for (command, path) in commands.items(): | ||
asserts.equals(env, path, discovered.get(command), "expected path to {} to match".format(command)) | ||
|
||
return unittest.end(env) | ||
|
||
_posix_runtime_test = unittest.make( | ||
_posix_runtime_test_impl, | ||
attrs = { | ||
"toolchain": attr.label(), | ||
}, | ||
) | ||
|
||
def posix_test_suite(name): | ||
_posix_toolchain(name = "posix-toolchain") | ||
unittest.suite( | ||
name, | ||
lambda name: _posix_runtime_test(name = name, toolchain = ":posix-toolchain") | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
build --host_platform=@rules_nixpkgs_core//platforms:host | ||
|
||
build --crosstool_top=@nixpkgs_config_cc//:toolchain | ||
# Using toolchain resolution can lead to spurious dependencies on | ||
# `@local_config_cc//:builtin_include_directory_paths`. This needs to be | ||
# resolved before `--incompatible_enable_cc_toolchain_resolution` can be | ||
# recommended for `nixpkgs_cc_configure_hermetic`. | ||
# build --incompatible_enable_cc_toolchain_resolution | ||
|
||
build --java_runtime_version=nixpkgs_java_11 | ||
build --java_language_version=11 | ||
build --tool_java_runtime_version=nixpkgs_java_11 | ||
build --tool_java_language_version=11 | ||
|
||
# The following lines provide a workaround for a test failure in on the Java | ||
# toolchain on MacOS 11, documented here: https://github.com/tweag/rules_nixpkgs/issues/299. | ||
# They should be removed as soon as that issue has been resolved. | ||
build --enable_platform_specific_config | ||
build:macos --experimental_strict_java_deps=warn | ||
|
||
# User Configuration | ||
# ------------------ | ||
try-import %workspace%/.bazelrc.local | ||
import %workspace%/../../.bazelrc.common | ||
import %workspace%/../../.bazelrc.cc | ||
import %workspace%/../../.bazelrc.java |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
build --host_platform=@rules_nixpkgs_core//platforms:host | ||
|
||
build --crosstool_top=@nixpkgs_config_cc//:toolchain | ||
# Using toolchain resolution can lead to spurious dependencies on | ||
# `@local_config_cc//:builtin_include_directory_paths`. This needs to be | ||
# resolved before `--incompatible_enable_cc_toolchain_resolution` can be | ||
# recommended for `nixpkgs_cc_configure_hermetic`. | ||
# build --incompatible_enable_cc_toolchain_resolution | ||
|
||
build --java_runtime_version=nixpkgs_java_11 | ||
build --java_language_version=11 | ||
build --tool_java_runtime_version=nixpkgs_java_11 | ||
build --tool_java_language_version=11 | ||
|
||
# The following lines provide a workaround for a test failure in on the Java | ||
# toolchain on MacOS 11, documented here: https://github.com/tweag/rules_nixpkgs/issues/299. | ||
# They should be removed as soon as that issue has been resolved. | ||
build --enable_platform_specific_config | ||
build:macos --experimental_strict_java_deps=warn | ||
|
||
# User Configuration | ||
# ------------------ | ||
try-import %workspace%/.bazelrc.local | ||
import %workspace%/../../.bazelrc.common | ||
import %workspace%/../../.bazelrc.cc | ||
import %workspace%/../../.bazelrc.java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much cleaner.