Skip to content

Commit

Permalink
Replace relative paths to ../ with external/ (#1500)
Browse files Browse the repository at this point in the history
* Replace relative paths to ../ with external

* Add test case for external test
prebeta authored Jun 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7b25715 commit d6b81c8
Showing 11 changed files with 73 additions and 6 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion scala/private/phases/phase_runfiles.bzl
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion scala/private/phases/phase_write_executable.bzl
Original file line number Diff line number Diff line change
@@ -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,
)
8 changes: 8 additions & 0 deletions test/scala_test/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)
2 changes: 1 addition & 1 deletion test/src/main/scala/scalarules/test/resources/strip/BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
47 changes: 47 additions & 0 deletions third_party/test/example_external_workspace/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions third_party/test/example_external_workspace/test/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_test")

scala_test(
name = "empty_test",
srcs = ["EmptyTest.scala"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.scalatest.funsuite._

class EmptyTest extends AnyFunSuite {
test("empty test") {
assert(true)
}
}

This file was deleted.

0 comments on commit d6b81c8

Please sign in to comment.