-
Notifications
You must be signed in to change notification settings - Fork 281
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
Testing toolchain and Junit deps #1102
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## Testing toolchain configuration | ||
|
||
Toolchain type `testing_toolchain_type` is used to set up test dependencies. | ||
|
||
### Example to set up JUnit dependencies | ||
|
||
`BUILD` file content in your prefered package: | ||
```starlark | ||
load("@io_bazel_rules_scala//scala:providers.bzl", "declare_deps_provider") | ||
load("@io_bazel_rules_scala//testing/toolchain:toolchain.bzl", "scala_testing_toolchain") | ||
|
||
scala_testing_toolchain( | ||
name = "testing_toolchains_with_junit", | ||
dep_providers = [ | ||
":junit_classpath_provider", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "testing_toolchain", | ||
toolchain = ":testing_toolchains_with_junit", | ||
toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
declare_deps_provider( | ||
name = "junit_classpath_provider", | ||
deps_id = "junit_classpath", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@my_hamcrest_core", | ||
"@my_junit", | ||
], | ||
) | ||
``` | ||
|
||
`junit_classpath_provider` (deps_id `junit_classpath`) is where classpath required for junit tests | ||
is defined. | ||
|
||
Toolchain must be registerd in your `WORKSPACE` file: | ||
```starlark | ||
register_toolchains('//my/package:testing_toolchain') | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ def junit_repositories(maven_servers = _default_maven_server_urls()): | |
name = "io_bazel_rules_scala/dependency/hamcrest/hamcrest_core", | ||
actual = "@io_bazel_rules_scala_org_hamcrest_hamcrest_core//jar", | ||
) | ||
|
||
native.register_toolchains("@io_bazel_rules_scala//testing:testing_toolchain") | ||
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. This is the default? For people who don't override? 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, but probably it will stay here only until Specs2 and ScalaTest will be migrated. Each test lib will have it's own configuration. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@io_bazel_rules_scala//scala:providers.bzl", "declare_deps_provider") | ||
load("@io_bazel_rules_scala//testing/toolchain:toolchain.bzl", "scala_testing_toolchain") | ||
|
||
scala_testing_toolchain( | ||
name = "testing_toolchains_with_all_deps_impl", | ||
dep_providers = [ | ||
":junit_classpath_provider", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "testing_toolchain", | ||
toolchain = ":testing_toolchains_with_all_deps_impl", | ||
toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
declare_deps_provider( | ||
name = "junit_classpath_provider", | ||
deps_id = "junit_classpath", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core", | ||
"//external:io_bazel_rules_scala/dependency/junit/junit", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@io_bazel_rules_scala//testing/toolchain:toolchain_deps.bzl", "testing_toolchain_deps") | ||
|
||
toolchain_type( | ||
name = "testing_toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
testing_toolchain_deps( | ||
name = "junit_classpath", | ||
deps_id = "junit_classpath", | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("//scala:providers.bzl", _DepsInfo = "DepsInfo") | ||
|
||
def _scala_toolchain_impl(ctx): | ||
toolchain = platform_common.ToolchainInfo( | ||
dep_providers = ctx.attr.dep_providers, | ||
) | ||
return [toolchain] | ||
|
||
scala_testing_toolchain = rule( | ||
_scala_toolchain_impl, | ||
attrs = { | ||
"dep_providers": attr.label_list( | ||
default = [ | ||
], | ||
providers = [_DepsInfo], | ||
), | ||
}, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load( | ||
"//scala/private/toolchain_deps:toolchain_deps.bzl", | ||
"expose_toolchain_deps", | ||
"java_info_for_deps", | ||
) | ||
|
||
_toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type" | ||
|
||
def _testing_toolchain_deps(ctx): | ||
return expose_toolchain_deps(ctx, _toolchain_type) | ||
|
||
testing_toolchain_deps = rule( | ||
implementation = _testing_toolchain_deps, | ||
attrs = { | ||
"deps_id": attr.string(mandatory = True), | ||
}, | ||
toolchains = [_toolchain_type], | ||
) |
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.
The idea is that Wix can set up a testing toolchain of junit and specs2, twitter of junit and scalatest and stripe only if scalatest?
Since unneeded rules won't be evaluated and the missing deps won't be a problem? If so it will probably be worthwhile to make sure that bazel toolchains actually works like that (for example move scalatest to this and see that Wix defines only specs2 + junit in the single testing toolchain and everything works).
Finally I think it's important in clarifying this idea.
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.
Toolchain only knows a list of labels, whether it correctly works depends on the actual rule that uses this toolchain and requests any of the dependencies. So if there is no rule that asks for JUnit, there's no need to add Junit deps to the toolchain.
Docs will be updated when there will be more rules that use it.
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 think there's value in explicitly specifying this issue of actual deps.
Most of our users will not understand toolchain in the same depths you do.