Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples/overridden_artifacts and test #1713

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/overridden_artifacts/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ../../.bazelrc
1 change: 1 addition & 0 deletions examples/overridden_artifacts/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.5.0
12 changes: 12 additions & 0 deletions examples/overridden_artifacts/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_scala//scala:scala.bzl", "scala_library", "scala_test")

scala_library(
name = "hello",
srcs = ["Hello.scala"],
)

scala_test(
name = "hello-test",
srcs = ["HelloTest.scala"],
deps = [":hello"],
)
4 changes: 4 additions & 0 deletions examples/overridden_artifacts/Hello.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package overriddenartifactstest

class Hello(version: String):
def greetings(): String = "Hello, World! This is Scala " + version + "."
12 changes: 12 additions & 0 deletions examples/overridden_artifacts/HelloTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package overriddenartifactstest

import org.scalatest.funsuite.AnyFunSuite

class HelloTest extends AnyFunSuite:
test("greetings includes the correct Scala version number") {
val hello = new Hello(util.Properties.versionNumberString)

// Apparently Scala 3 code will still return a Scala 2 version number:
// - https://users.scala-lang.org/t/what-scala-library-version-is-used-by-which-scala-3-version/9999
assert(hello.greetings().endsWith("2.13.14."))
}
98 changes: 98 additions & 0 deletions examples/overridden_artifacts/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
workspace(name = "overridden_artifacts")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

local_repository(
name = "rules_scala",
path = "../..",
)

load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")

rules_scala_dependencies()

load(
"@rules_java//java:repositories.bzl",
"rules_java_dependencies",
"rules_java_toolchains",
)

rules_java_dependencies()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "rules_python",
sha256 = "ca2671529884e3ecb5b79d6a5608c7373a82078c3553b1fa53206e6b9dddab34",
strip_prefix = "rules_python-0.38.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.38.0/rules_python-0.38.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

rules_java_toolchains()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

rules_proto_dependencies()

load("@rules_proto//proto:setup.bzl", "rules_proto_setup")

rules_proto_setup()

load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")

rules_proto_toolchains()

load("@rules_scala//:scala_config.bzl", "scala_config")

scala_config(scala_version = "3.3.5")

load(
"@rules_scala//scala:toolchains.bzl",
"scala_register_toolchains",
"scala_toolchains",
)

scala_toolchains(
# Deliberately set for Scala 3.3 and 2.13 versions less than the most
# recently supported. See the `scala_version` setting at the top of
# `third_party/repositories/scala_{2_13,3_3}.bzl`.
overridden_artifacts = {
"io_bazel_rules_scala_scala_library": {
"artifact": "org.scala-lang:scala3-library_3:3.3.4",
"sha256": "d95184acfcd814da2e051378e4962c653f4b468f4086452ab427af030482bd3c",
},
"io_bazel_rules_scala_scala_compiler": {
"artifact": "org.scala-lang:scala3-compiler_3:3.3.4",
"sha256": "2cca65fdb92e2cc393786cae61b4f7bcb9032ad4be61f9cebae1dca72997e52f",
# These are _not_ strictly required in this case, but we want to
# test that nothing breaks when they're specified.
"deps": [
"@io_bazel_rules_scala_scala_asm",
"@io_bazel_rules_scala_scala_interfaces",
"@io_bazel_rules_scala_scala_library",
"@io_bazel_rules_scala_scala_tasty_core",
"@org_jline_jline_reader",
"@org_jline_jline_terminal",
"@org_jline_jline_terminal_jni",
"@org_scala_sbt_compiler_interface",
],
},
"io_bazel_rules_scala_scala_library_2": {
"artifact": "org.scala-lang:scala-library:2.13.14",
"sha256": "43e0ca1583df1966eaf02f0fbddcfb3784b995dd06bfc907209347758ce4b7e3",
},
},
scalatest = True,
)

scala_register_toolchains()
4 changes: 2 additions & 2 deletions scala/private/macros/scala_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _validate_scalac_srcjar(srcjar):
oneof = ["url", "urls", "label"]
count = 0
for key in oneof:
if key in srcjar:
if srcjar.get(key):
count += 1
return count == 1

Expand Down Expand Up @@ -94,7 +94,7 @@ def dt_patched_compiler_setup(scala_version, scala_compiler_srcjar = None):
("scala_compiler_srcjar invalid, must be a dict with exactly one of \"label\", \"url\"" +
" or \"urls\" keys, got: ") + repr(srcjar),
)
if "label" in srcjar:
if srcjar.get("label"):
dt_patched_compiler(
name = "scala_compiler_source" + version_suffix(scala_version),
build_file_content = build_file_content,
Expand Down
8 changes: 7 additions & 1 deletion test/shell/test_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function cross_build_example() {
test_example examples/crossbuild "bazel build //..."
}

function overridden_artifacts_example() {
test_example examples/overridden_artifacts \
"bazel test --test_output=errors //..."
}

$runner scalatest_repositories_example
$runner specs2_junit_repositories_example
$runner multi_framework_toolchain_example
Expand All @@ -77,4 +82,5 @@ $runner scala3_3_example
$runner scala3_4_example
$runner scala3_5_example
$runner scala3_6_example
$runner cross_build_example
$runner cross_build_example
$runner overridden_artifacts_example