Skip to content

Commit a587390

Browse files
authored
Configure major scala version via repo_env (#1259)
* Configure major scala version via repo_env * Supply input values in all tests and do not rely on defaults * Assert on io_bazel_rules_scala_config/config.bzl content
1 parent b85d122 commit a587390

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

scala_config.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ def _default_scala_version():
55
return "2.12.11"
66

77
def _store_config(repository_ctx):
8-
repository_ctx.file("BUILD", "exports_files(['def.bzl'])")
8+
scala_version = repository_ctx.os.environ.get(
9+
"SCALA_VERSION",
10+
repository_ctx.attr.scala_version,
11+
)
912

10-
scala_version = repository_ctx.attr.scala_version
1113
scala_major_version = extract_major_version(scala_version)
1214

1315
config_file_content = "\n".join([
@@ -16,6 +18,7 @@ def _store_config(repository_ctx):
1618
])
1719

1820
repository_ctx.file("config.bzl", config_file_content)
21+
repository_ctx.file("BUILD")
1922

2023
_config_repository = repository_rule(
2124
implementation = _store_config,
@@ -24,6 +27,7 @@ _config_repository = repository_rule(
2427
mandatory = True,
2528
),
2629
},
30+
environ = ["SCALA_VERSION"],
2731
)
2832

2933
def scala_config(scala_version = _default_scala_version()):

test/shell/test_scala_config.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# shellcheck source=./test_runner.sh
2+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3+
. "${dir}"/test_runner.sh
4+
. "${dir}"/test_helper.sh
5+
runner=$(get_test_runner "${1:-local}")
6+
7+
test_classpath_contains_2_12() {
8+
bazel aquery 'mnemonic("Javac", //src/java/io/bazel/rulesscala/scalac:scalac)' \
9+
--repo_env=SCALA_VERSION=2.12.x \
10+
| grep scala-library-2.12
11+
}
12+
13+
test_classpath_contains_2_13() {
14+
bazel aquery 'mnemonic("Javac", //src/java/io/bazel/rulesscala/scalac:scalac)' \
15+
--repo_env=SCALA_VERSION=2.13.x \
16+
| grep scala-library-2.13
17+
}
18+
19+
test_scala_config_content() {
20+
bazel build --repo_env=SCALA_VERSION=0.0.0 @io_bazel_rules_scala_config//:all 2> /dev/null
21+
grep "SCALA_MAJOR_VERSION='0.0'" $(bazel info output_base)/external/io_bazel_rules_scala_config/config.bzl
22+
}
23+
24+
$runner test_classpath_contains_2_12
25+
$runner test_classpath_contains_2_13
26+
$runner test_scala_config_content

test_rules_scala.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ $runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one
3737
. "${test_dir}"/test_scala_binary.sh
3838
. "${test_dir}"/test_scalac_jvm_flags.sh
3939
. "${test_dir}"/test_scala_classpath.sh
40+
. "${test_dir}"/test_scala_config.sh
4041
. "${test_dir}"/test_scala_import_source_jar.sh
4142
. "${test_dir}"/test_scala_jvm_flags.sh
4243
. "${test_dir}"/test_scala_jacocorunner.sh

0 commit comments

Comments
 (0)