forked from bazelbuild/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing toolchain and Junit deps (bazelbuild#1102)
* Add testing toolchain with Junit deps * Add docs for junit * Update junit related aspect test deps
- Loading branch information
Vaidas Pilkauskas
authored and
Borja Lorente
committed
Nov 26, 2020
1 parent
bd63009
commit b9e7976
Showing
11 changed files
with
131 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
) |