From 8c2a5358477964dc342c0fb47aff9689cedd91a5 Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Mon, 21 Sep 2020 10:57:51 +0300 Subject: [PATCH 1/5] Add scalatest deps to testing toolchain --- scala/private/rules/scala_test.bzl | 4 ++-- scala/scalatest/BUILD | 8 ++------ scala/support/BUILD | 2 +- src/java/io/bazel/rulesscala/scala_test/BUILD | 2 +- testing/BUILD | 11 +++++++++++ testing/toolchain/BUILD | 6 ++++++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/scala/private/rules/scala_test.bzl b/scala/private/rules/scala_test.bzl index be119900c..23481d28b 100644 --- a/scala/private/rules/scala_test.bzl +++ b/scala/private/rules/scala_test.bzl @@ -59,7 +59,7 @@ _scala_test_attrs = { "jvm_flags": attr.string_list(), "_scalatest": attr.label( default = Label( - "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", + "@io_bazel_rules_scala//testing/toolchain:scalatest_classpath", ), ), "_scalatest_runner": attr.label( @@ -84,7 +84,7 @@ _test_resolve_deps = { "@io_bazel_rules_scala//scala/private/toolchain_deps:scala_library_classpath", ), Label( - "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", + "@io_bazel_rules_scala//testing/toolchain:scalatest_classpath", ), ], allow_files = False, diff --git a/scala/scalatest/BUILD b/scala/scalatest/BUILD index 4e7439e96..fe9c52e93 100644 --- a/scala/scalatest/BUILD +++ b/scala/scalatest/BUILD @@ -2,11 +2,7 @@ package(default_visibility = ["//visibility:public"]) load("//scala:scala_import.bzl", "scala_import") -scala_import( +alias( name = "scalatest", - jars = [], - exports = [ - "//external:io_bazel_rules_scala/dependency/scala/scalactic/scalactic", - "//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", - ], + actual = "//testing/toolchain:scalatest_classpath", ) diff --git a/scala/support/BUILD b/scala/support/BUILD index d6e557705..0ab782154 100644 --- a/scala/support/BUILD +++ b/scala/support/BUILD @@ -24,7 +24,7 @@ scala_library( ], visibility = ["//visibility:public"], deps = [ - "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", "//scala/private/toolchain_deps:scala_xml", + "//testing/toolchain:scalatest_classpath", ], ) diff --git a/src/java/io/bazel/rulesscala/scala_test/BUILD b/src/java/io/bazel/rulesscala/scala_test/BUILD index ba02286d8..52fc1f136 100644 --- a/src/java/io/bazel/rulesscala/scala_test/BUILD +++ b/src/java/io/bazel/rulesscala/scala_test/BUILD @@ -5,7 +5,7 @@ java_library( srcs = ["Runner.java"], visibility = ["//visibility:public"], deps = [ - "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", + "//testing/toolchain:scalatest_classpath", "@bazel_tools//tools/java/runfiles", ], ) diff --git a/testing/BUILD b/testing/BUILD index 1d52ca4b9..116110c9c 100644 --- a/testing/BUILD +++ b/testing/BUILD @@ -5,6 +5,7 @@ scala_testing_toolchain( name = "testing_toolchains_with_all_deps_impl", dep_providers = [ ":junit_classpath_provider", + ":scalatest_classpath_provider", ], visibility = ["//visibility:public"], ) @@ -25,3 +26,13 @@ declare_deps_provider( "//external:io_bazel_rules_scala/dependency/junit/junit", ], ) + +declare_deps_provider( + name = "scalatest_classpath_provider", + deps_id = "scalatest_classpath", + visibility = ["//visibility:public"], + deps = [ + "//external:io_bazel_rules_scala/dependency/scala/scalactic/scalactic", + "//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", + ], +) diff --git a/testing/toolchain/BUILD b/testing/toolchain/BUILD index 9ec4ece6e..3b2a81945 100644 --- a/testing/toolchain/BUILD +++ b/testing/toolchain/BUILD @@ -10,3 +10,9 @@ testing_toolchain_deps( deps_id = "junit_classpath", visibility = ["//visibility:public"], ) + +testing_toolchain_deps( + name = "scalatest_classpath", + deps_id = "scalatest_classpath", + visibility = ["//visibility:public"], +) From a8fcd9e1e177ec481c7adfe390d431de01c92ef9 Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Mon, 21 Sep 2020 13:32:46 +0300 Subject: [PATCH 2/5] Update testing docs, toolchain and repository loading --- WORKSPACE | 2 ++ docs/testing.md | 47 +++++++++++++++++++++++++++++++++++++++-- junit/junit.bzl | 2 -- specs2/specs2_junit.bzl | 2 +- testing/BUILD | 30 ++++++++++++++++++++++++++ testing/junit.bzl | 7 ++++++ testing/scalatest.bzl | 6 ++++++ 7 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 testing/junit.bzl create mode 100644 testing/scalatest.bzl diff --git a/WORKSPACE b/WORKSPACE index 95cfe5a0e..f00abef1e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -47,6 +47,8 @@ load("//specs2:specs2_junit.bzl", "specs2_junit_repositories") specs2_junit_repositories() +register_toolchains("//testing:testing_toolchain") + load("//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories") scalafmt_default_config() diff --git a/docs/testing.md b/docs/testing.md index b94c6f68b..600ed9d20 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -4,7 +4,7 @@ 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: +`BUILD` file content in your preferred 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") @@ -38,8 +38,51 @@ declare_deps_provider( `junit_classpath_provider` (deps_id `junit_classpath`) is where classpath required for junit tests is defined. -Toolchain must be registerd in your `WORKSPACE` file: +ScalaTest support can be enabled by configuring a provider with an id `scalatest_classpath`: + +```starlark +scala_testing_toolchain( + name = "testing_toolchains_with_scalatest", + dep_providers = [ + ":scalatest_classpath_provider", + ], + visibility = ["//visibility:public"], +) + +toolchain( + name = "testing_toolchain", + toolchain = ":testing_toolchains_with_scalatest", + toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type", + visibility = ["//visibility:public"], +) + +declare_deps_provider( + name = "scalatest_classpath_provider", + deps_id = "junit_classpath", + visibility = ["//visibility:public"], + deps = [ + "@scalactic", + "@scalatest", + ], +) +``` + +Toolchain must be registered in your `WORKSPACE` file: ```starlark register_toolchains('//my/package:testing_toolchain') ``` +Single toolchain can be used to configure multiple testing rules (JUnit 4, ScalaTest). Default +repositories and toolchains in your `WORKSPACE` can be loaded via: +```starlark +# JUnit 4 +load("//testing:junit.bzl", "junit_repositories", "junit_toolchain") +junit_repositories() +junit_toolchain() + +# ScalaTest +load("//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain") +scalatest_repositories() +scalatest_toolchain() +``` + diff --git a/junit/junit.bzl b/junit/junit.bzl index 6acaa9881..7ea79f617 100644 --- a/junit/junit.bzl +++ b/junit/junit.bzl @@ -31,5 +31,3 @@ 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") diff --git a/specs2/specs2_junit.bzl b/specs2/specs2_junit.bzl index 9c9885b2c..9ef64897a 100644 --- a/specs2/specs2_junit.bzl +++ b/specs2/specs2_junit.bzl @@ -4,7 +4,7 @@ load( "specs2_repositories", "specs2_version", ) -load("//junit:junit.bzl", "junit_repositories") +load("//testing:junit.bzl", "junit_repositories") load( "//scala:scala_cross_version.bzl", _default_maven_server_urls = "default_maven_server_urls", diff --git a/testing/BUILD b/testing/BUILD index 116110c9c..b2b4c9d29 100644 --- a/testing/BUILD +++ b/testing/BUILD @@ -17,6 +17,36 @@ toolchain( visibility = ["//visibility:public"], ) +scala_testing_toolchain( + name = "scalatest_toolchain_impl", + dep_providers = [ + ":scalatest_classpath_provider", + ], + visibility = ["//visibility:public"], +) + +toolchain( + name = "scalatest_toolchain", + toolchain = ":scalatest_toolchain_impl", + toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type", + visibility = ["//visibility:public"], +) + +scala_testing_toolchain( + name = "junit_toolchain_impl", + dep_providers = [ + ":junit_classpath_provider", + ], + visibility = ["//visibility:public"], +) + +toolchain( + name = "junit_toolchain", + toolchain = ":junit_toolchain_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", diff --git a/testing/junit.bzl b/testing/junit.bzl new file mode 100644 index 000000000..a87ac6817 --- /dev/null +++ b/testing/junit.bzl @@ -0,0 +1,7 @@ +load("//junit:junit.bzl", _repositories = "junit_repositories") + +def junit_repositories(): + _repositories() + +def junit_toolchain(): + native.register_toolchains("@io_bazel_rules_scala//testing:junit_toolchain") diff --git a/testing/scalatest.bzl b/testing/scalatest.bzl new file mode 100644 index 000000000..e432fff1c --- /dev/null +++ b/testing/scalatest.bzl @@ -0,0 +1,6 @@ +def scalatest_repositories(): + # currently ScalaTest dependencies are already loaded via //scala:scala.bzl#scala_repositories() + pass + +def scalatest_toolchain(): + native.register_toolchain("//testing:scalatest_toolchain") From d0468aef6c88d96ca11136795e4a52d28f6a5e11 Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Mon, 21 Sep 2020 14:54:23 +0300 Subject: [PATCH 3/5] Fix aspect test --- test/aspect/aspect.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/aspect/aspect.bzl b/test/aspect/aspect.bzl index 1ba60b1ce..60e4078d2 100644 --- a/test/aspect/aspect.bzl +++ b/test/aspect/aspect.bzl @@ -28,7 +28,7 @@ def _rule_impl(ctx): "scala_test": [ "//test/aspect:scala_test", "//scala/private/toolchain_deps:scala_library_classpath", - "@io_bazel_rules_scala//scala/scalatest:scalatest", + "//testing/toolchain:scalatest_classpath", ], "scala_junit_test": [ "//test/aspect:scala_junit_test", From c4fd8f5523b36ca2e84a309adf9cdcb8f6086ff9 Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Tue, 22 Sep 2020 09:42:50 +0300 Subject: [PATCH 4/5] Add testing toolchain to version tests WORKSPACE --- test_version/WORKSPACE.template | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_version/WORKSPACE.template b/test_version/WORKSPACE.template index 3817a09ed..e4101b962 100644 --- a/test_version/WORKSPACE.template +++ b/test_version/WORKSPACE.template @@ -54,6 +54,8 @@ load("@io_bazel_rules_scala//specs2:specs2_junit.bzl", "specs2_junit_repositorie specs2_junit_repositories(scala_version) +register_toolchains("@io_bazel_rules_scala//testing:testing_toolchain") + load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_unused_deps_toolchains") scala_register_unused_deps_toolchains() From 9a72f5e0757c0708bc454e81f5308ce79693e697 Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Fri, 2 Oct 2020 17:41:09 +0300 Subject: [PATCH 5/5] Update testing toolchain docs --- docs/testing.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index 600ed9d20..ec3d638bb 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1,6 +1,20 @@ ## Testing toolchain configuration -Toolchain type `testing_toolchain_type` is used to set up test dependencies. +Toolchain type `testing_toolchain_type` is used to set up test dependencies. You can customize +test dependencies by defining a custom testing toolchain. + +In your `WORKSPACE` default repositories and toolchains can be loaded via: +```starlark +# JUnit 4 +load("@io_bazel_rules_scala//testing:junit.bzl", "junit_repositories", "junit_toolchain") +junit_repositories() +junit_toolchain() + +# ScalaTest +load(""@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain") +scalatest_repositories() +scalatest_toolchain() +``` ### Example to set up JUnit dependencies @@ -72,17 +86,4 @@ Toolchain must be registered in your `WORKSPACE` file: register_toolchains('//my/package:testing_toolchain') ``` -Single toolchain can be used to configure multiple testing rules (JUnit 4, ScalaTest). Default -repositories and toolchains in your `WORKSPACE` can be loaded via: -```starlark -# JUnit 4 -load("//testing:junit.bzl", "junit_repositories", "junit_toolchain") -junit_repositories() -junit_toolchain() - -# ScalaTest -load("//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain") -scalatest_repositories() -scalatest_toolchain() -``` - +Single toolchain can be used to configure multiple testing rules (JUnit 4, ScalaTest).