-
Notifications
You must be signed in to change notification settings - Fork 80
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 core tests and test with bzlmod enabled #319
Conversation
The goal is to move the tests in rules_nixpkgs_core into this testing module for BCR compatibility. The tests in rules_nixpkgs_core incur extra dependencies that should not be part of rules_nixpkgs_core. In principle, such dependencies can be marked as dev-dependencies. However, since rules_nixpkgs only consists of repository rules (or in the future module extensions) those are easier to test in a dedicated module.
Requires a workaround for bzlmod module name mangling and remapping. For now this requires manual name mangling.
These require some workarounds for module mapping and equality not working on labels pointing to unknown external workspaces.
The labels as expected by the user are passed in as strings in a mapping to the actual labels which will be exposed with mangled names in the repository rule implementation. The mapping allows to map the user defined location variables to the corresponding paths without exposing mangled labels to the user.
Move the docstring to nixpkgs_package and reference it from the cc site.
Skylib offers diff_test for this exact purpose. It uses `diff` (or `fc.exe` on Windows) under the hood.
That test case had been forgotten in the test-target.
These have been moved to testing/core
bfc16a0
to
e26b6da
Compare
The file is needed by docs and propagated as a dependency to the other toolchains through docs/dependencies_2.bzl.
Setting these flags in `.bazelrc` incurred a required for a Java toolchain. This, in turn, would require a dependency on rules_nixpkgs_java from rules_nixpkgs_core to set up a Java toolchain. I'd like to avoid that kind of circular dependency.
The core module no longer contains any test targets, and unfortunately bazel test fails when there are no test targets defined.
Any Bazel workspace that has tests seems to depend on a JDK toolchain due to ``` ERROR: .../external/remote_coverage_tools/BUILD:10:12: While resolving toolchains for target @remote_coverage_tools//:Main: No matching toolchains found for types @bazel_tools//tools/jdk:runtime_toolchain_type. To debug, rerun with --toolchain_resolution_debug='@bazel_tools//tools/jdk:runtime_toolchain_type' If platforms or toolchains are a new concept for you, we'd encourage reading https://bazel.build/concepts/platforms-intro. ```
Bazel needs a Java runtime to execute tests.
e26b6da
to
bb96d1f
Compare
CI is finally green, so this is ready for review. |
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.
I gave this a try locally and it all looks good. Great to see the bzlmod-ularization of rules_nixpkgs progressing!
"nixpkgs_package", | ||
) | ||
|
||
def nixpkgs_repositories(*, bzlmod): |
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.
I see two invocations of this macro (one with bzlmod = True
and one with bzlmod = False
), but unless there's some magic going on it doesn't look like the parameter is actually used at the moment. Is it intended to be in the future?
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.
Good catch, it was needed at one point during development, but is no longer necessary here. I've removed it.
) | ||
|
||
### end dependencies for tests | ||
rules_nixpkgs_dependencies(toolchains = []) |
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.
I was going to ask why pass toolchains = []
explicitly instead of relying on the default of None
, but then I saw None
means load all toolchains.
@Mergifyio refresh |
✅ Pull request refreshed |
The renaming of the CI steps to capture workspace and bzlmod required an update to the Mergify config as well. Merging manually because of that. |
Related to #183.
This PR builds and tests
rules_nixpkgs_core
withbzlmod
enabled.Following the motivation laid out in tweag/rules_sh#41, this separates the tests out into a dedicated testing module,
testing/core
. The naming is chosen such that further testing modules can be added for other modules, e.g.testing/cc
.The CI workflow is extended to run both, the old tests in WORKSPACE mode, and to test
core
andtesting/core
with bzlmod enabled.The location expansion unit tests remain withincore
. The reason is that these are just unit-tests and don't require extra dependencies or module extensions. Andbazel test //...
(as run by the CI script) fails if there are no test targets, see bazelbuild/bazel#7291 (comment).The
core
module contains no more tests after this PR.bazel test
needs to resolve a Java runtime, meaningcore
would either have to depend onrules_nixpkgs_java
(problematic due to tweag/rules_sh#41) or pick a local or bindist Java runtime (problematic for hermeticity and on NixOS). Unfortunately,bazel test //...
fails when there are no test targets, so the CI script is adapted to runbazel build
incore
instead.The testing module
testing/core
configures a Java runtime usingrules_nixpkgs_java
. This uses theWORKSPACE.bzlmod
fall-back in when bzlmod is enabled asrules_nixpkgs_java
is not bzlmod compatible, yet.This does not yet add a module extension to
@rules_nixpkgs_core
. Instead,testing/core
uses an ad-hocnon_module_deps
module extension to invoke the repository rules provided by@rules_nixpkgs_core
. Creating actual module extensions will be done in a separate PR.Most of the functionality worked without change with bzlmod enabled. However, the location expansion feature for the
nixopts
attribute broke due to bzlmod's use of module remapping and workspace name mangling. This is addressed by passing the labels tonix_file_deps
in stringly form along their actual labels in a dictionary. This mapping is then used to resolve the stringly labels in the location expansion expressions to the actual file paths. This somewhat related to bazelbuild/bazel#17260. However, the newnative.package_relative_label
would probably not address this issue, as the labels in the location expressions need to be resolved to paths within thenixpkgs_package
repository rule implementation, not a macro.