Skip to content

Commit d6b81c8

Browse files
author
Tony Liang
authored
Replace relative paths to ../ with external/ (#1500)
* Replace relative paths to ../ with external * Add test case for external test
1 parent 7b25715 commit d6b81c8

File tree

11 files changed

+73
-6
lines changed

11 files changed

+73
-6
lines changed

WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ filegroup(
9393
)
9494

9595
local_repository(
96-
name = "strip_resource_external_workspace",
97-
path = "third_party/test/strip_resource_external_workspace",
96+
name = "example_external_workspace",
97+
path = "third_party/test/example_external_workspace",
9898
)
9999

100100
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_unused_deps_toolchains")

scala/private/phases/phase_runfiles.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def phase_runfiles_library(ctx, p):
1313
def phase_runfiles_scalatest(ctx, p):
1414
args = "\n".join([
1515
"-R",
16-
ctx.outputs.jar.short_path,
16+
ctx.outputs.jar.short_path.replace("../", "external/"),
1717
_scala_test_flags(ctx),
1818
"-C",
1919
ctx.attr.reporter_class,

scala/private/phases/phase_write_executable.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def phase_write_executable_scalatest(ctx, p):
2323
rjars = p.coverage_runfiles.rjars,
2424
jvm_flags = [
2525
"-DRULES_SCALA_MAIN_WS_NAME=%s" % ctx.workspace_name,
26-
"-DRULES_SCALA_ARGS_FILE=%s" % p.runfiles.args_file.short_path,
26+
"-DRULES_SCALA_ARGS_FILE=%s" % p.runfiles.args_file.short_path.replace("../", "external/"),
2727
] + expand_location(ctx, final_jvm_flags),
2828
use_jacoco = ctx.configuration.coverage_enabled,
2929
)

test/scala_test/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ scala_test(
1919
],
2020
reporter_class = "test.scala_test.CustomReporter",
2121
)
22+
23+
# Check that we can run scala tests in external workspaces.
24+
test_suite(
25+
name = "external_scala_test",
26+
tests = [
27+
"@example_external_workspace//test:empty_test",
28+
],
29+
)

test/src/main/scala/scalarules/test/resources/strip/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ scala_specs2_junit_test(
2121
srcs = ["ResourceStripPrefixTest.scala"],
2222
suffixes = ["Test"],
2323
unused_dependency_checker_mode = "off",
24-
deps = ["@strip_resource_external_workspace//strip:noSrcsWithResources"],
24+
deps = ["@example_external_workspace//strip:noSrcsWithResources"],
2525
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
workspace(name = "example_external_workspace")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "bazel_skylib",
7+
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
8+
urls = [
9+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
10+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
11+
],
12+
)
13+
14+
local_repository(
15+
name = "io_bazel_rules_scala",
16+
path = "../../..",
17+
)
18+
19+
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
20+
21+
scala_config()
22+
23+
load(
24+
"@io_bazel_rules_scala//scala:scala.bzl",
25+
"rules_scala_setup",
26+
"rules_scala_toolchain_deps_repositories",
27+
)
28+
29+
rules_scala_setup()
30+
31+
rules_scala_toolchain_deps_repositories(fetch_sources = True)
32+
33+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
34+
35+
rules_proto_dependencies()
36+
37+
rules_proto_toolchains()
38+
39+
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
40+
41+
scala_register_toolchains()
42+
43+
load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")
44+
45+
scalatest_repositories()
46+
47+
scalatest_toolchain()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_test")
2+
3+
scala_test(
4+
name = "empty_test",
5+
srcs = ["EmptyTest.scala"],
6+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import org.scalatest.funsuite._
2+
3+
class EmptyTest extends AnyFunSuite {
4+
test("empty test") {
5+
assert(true)
6+
}
7+
}

0 commit comments

Comments
 (0)