diff --git a/WORKSPACE b/WORKSPACE index 20df30744..b931f346d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -93,8 +93,8 @@ filegroup( ) local_repository( - name = "strip_resource_external_workspace", - path = "third_party/test/strip_resource_external_workspace", + name = "example_external_workspace", + path = "third_party/test/example_external_workspace", ) load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_unused_deps_toolchains") diff --git a/scala/private/phases/phase_runfiles.bzl b/scala/private/phases/phase_runfiles.bzl index f45fb5b43..0f0c1457f 100644 --- a/scala/private/phases/phase_runfiles.bzl +++ b/scala/private/phases/phase_runfiles.bzl @@ -13,7 +13,7 @@ def phase_runfiles_library(ctx, p): def phase_runfiles_scalatest(ctx, p): args = "\n".join([ "-R", - ctx.outputs.jar.short_path, + ctx.outputs.jar.short_path.replace("../", "external/"), _scala_test_flags(ctx), "-C", ctx.attr.reporter_class, diff --git a/scala/private/phases/phase_write_executable.bzl b/scala/private/phases/phase_write_executable.bzl index 395d83fd5..d728c2058 100644 --- a/scala/private/phases/phase_write_executable.bzl +++ b/scala/private/phases/phase_write_executable.bzl @@ -23,7 +23,7 @@ def phase_write_executable_scalatest(ctx, p): rjars = p.coverage_runfiles.rjars, jvm_flags = [ "-DRULES_SCALA_MAIN_WS_NAME=%s" % ctx.workspace_name, - "-DRULES_SCALA_ARGS_FILE=%s" % p.runfiles.args_file.short_path, + "-DRULES_SCALA_ARGS_FILE=%s" % p.runfiles.args_file.short_path.replace("../", "external/"), ] + expand_location(ctx, final_jvm_flags), use_jacoco = ctx.configuration.coverage_enabled, ) diff --git a/test/scala_test/BUILD b/test/scala_test/BUILD index 95908d112..f64508f93 100644 --- a/test/scala_test/BUILD +++ b/test/scala_test/BUILD @@ -19,3 +19,11 @@ scala_test( ], reporter_class = "test.scala_test.CustomReporter", ) + +# Check that we can run scala tests in external workspaces. +test_suite( + name = "external_scala_test", + tests = [ + "@example_external_workspace//test:empty_test", + ], +) diff --git a/test/src/main/scala/scalarules/test/resources/strip/BUILD b/test/src/main/scala/scalarules/test/resources/strip/BUILD index b13cb4542..02c14a54f 100644 --- a/test/src/main/scala/scalarules/test/resources/strip/BUILD +++ b/test/src/main/scala/scalarules/test/resources/strip/BUILD @@ -21,5 +21,5 @@ scala_specs2_junit_test( srcs = ["ResourceStripPrefixTest.scala"], suffixes = ["Test"], unused_dependency_checker_mode = "off", - deps = ["@strip_resource_external_workspace//strip:noSrcsWithResources"], + deps = ["@example_external_workspace//strip:noSrcsWithResources"], ) diff --git a/third_party/test/example_external_workspace/WORKSPACE b/third_party/test/example_external_workspace/WORKSPACE new file mode 100644 index 000000000..43ab12468 --- /dev/null +++ b/third_party/test/example_external_workspace/WORKSPACE @@ -0,0 +1,47 @@ +workspace(name = "example_external_workspace") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "bazel_skylib", + sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + ], +) + +local_repository( + name = "io_bazel_rules_scala", + path = "../../..", +) + +load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config") + +scala_config() + +load( + "@io_bazel_rules_scala//scala:scala.bzl", + "rules_scala_setup", + "rules_scala_toolchain_deps_repositories", +) + +rules_scala_setup() + +rules_scala_toolchain_deps_repositories(fetch_sources = True) + +load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") + +rules_proto_dependencies() + +rules_proto_toolchains() + +load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") + +scala_register_toolchains() + +load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain") + +scalatest_repositories() + +scalatest_toolchain() diff --git a/third_party/test/strip_resource_external_workspace/strip/BUILD.bazel b/third_party/test/example_external_workspace/strip/BUILD.bazel similarity index 100% rename from third_party/test/strip_resource_external_workspace/strip/BUILD.bazel rename to third_party/test/example_external_workspace/strip/BUILD.bazel diff --git a/third_party/test/strip_resource_external_workspace/strip/nosrc_jar_resource.txt b/third_party/test/example_external_workspace/strip/nosrc_jar_resource.txt similarity index 100% rename from third_party/test/strip_resource_external_workspace/strip/nosrc_jar_resource.txt rename to third_party/test/example_external_workspace/strip/nosrc_jar_resource.txt diff --git a/third_party/test/example_external_workspace/test/BUILD b/third_party/test/example_external_workspace/test/BUILD new file mode 100644 index 000000000..1b750d0bc --- /dev/null +++ b/third_party/test/example_external_workspace/test/BUILD @@ -0,0 +1,6 @@ +load("@io_bazel_rules_scala//scala:scala.bzl", "scala_test") + +scala_test( + name = "empty_test", + srcs = ["EmptyTest.scala"], +) diff --git a/third_party/test/example_external_workspace/test/EmptyTest.scala b/third_party/test/example_external_workspace/test/EmptyTest.scala new file mode 100644 index 000000000..28b0cea10 --- /dev/null +++ b/third_party/test/example_external_workspace/test/EmptyTest.scala @@ -0,0 +1,7 @@ +import org.scalatest.funsuite._ + +class EmptyTest extends AnyFunSuite { + test("empty test") { + assert(true) + } +} \ No newline at end of file diff --git a/third_party/test/strip_resource_external_workspace/WORKSPACE b/third_party/test/strip_resource_external_workspace/WORKSPACE deleted file mode 100644 index e5d127dc1..000000000 --- a/third_party/test/strip_resource_external_workspace/WORKSPACE +++ /dev/null @@ -1 +0,0 @@ -workspace(name = "strip_resource_external_workspace")