Skip to content

Commit cf40df3

Browse files
authored
Add CommandLineParserAdapter for >=2.13.9 (#1634)
* Add scala.tools.cmd.CommandLineParser for >=2.13.9 Fixes //third_party/utils/src/test:test_util for Scala 2.13.9 and later by providing a thin `scala.tools.cmd.CommandLineParser` adapter. Before this change, building under Scala 2.13.14 produced: ```txt $ bazel build --repo_env=SCALA_VERSION=2.13.14 \ //third_party/utils/src/test:test_util ERROR: .../third_party/utils/src/test/BUILD:6:14: scala @@//third_party/utils/src/test:test_util failed: (Exit 1): scalac failed: error executing Scalac command (from target //third_party/utils/src/test:test_util) bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/src/java/io/bazel/rulesscala/scalac/scalac @bazel-out/darwin_arm64-fastbuild/bin/third_party/utils/src/test/test_util.jar-0.params third_party/utils/src/test/io/bazel/rulesscala/utils/TestUtil.scala:10: error: object cmd is not a member of package tools import scala.tools.cmd.CommandLineParser ^ third_party/utils/src/test/io/bazel/rulesscala/utils/TestUtil.scala:119: error: not found: value CommandLineParser val options = CommandLineParser.tokenize(compileOptions) ^ ``` Turns out `CommandLineParser` disappered in Scala 2.13.9, and its `Parser` replacement is private: - scala/scala#10057 * Use local proxy instead of scala.tools.cmd patch Copied the `CompilerAPICompat` code verbatim from @WojciechMazur's suggestion on #1634. Definitely seems more robust than injecting `CommandLineParser` directly into `scala.tools.cmd`. * Convert CompilerAPICompat trait to adapter object Requested by @simuons in #1634. Renamed it as well to reflect its very specific function.
1 parent 6a23700 commit cf40df3

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

third_party/utils/src/test/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ scala_library(
1313
any_3 = [
1414
"io/bazel/rulesscala/utils/Scala3CompilerUtils.scala",
1515
],
16+
before_2_13_9 = [
17+
"io/bazel/rulesscala/utils/CommandLineParserAdapter_before_2_13_9.scala",
18+
],
19+
between_2_13_9_and_3 = [
20+
"io/bazel/rulesscala/utils/CommandLineParserAdapter_since_2_13_9.scala",
21+
],
1622
),
1723
visibility = ["//visibility:public"],
1824
deps = [
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.bazel.rulesscala.utils
2+
3+
import scala.tools.cmd.CommandLineParser
4+
5+
object CommandLineParserAdapter {
6+
def tokenize(cmd: String): List[String] = CommandLineParser.tokenize(cmd)
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala {
2+
package rulesscala {
3+
// proxy to private[scala] compiler API
4+
object Proxy {
5+
def tokenize(cmd: String): List[String] = sys.process.Parser.tokenize(cmd)
6+
}
7+
}
8+
}
9+
10+
package io.bazel.rulesscala.utils {
11+
object CommandLineParserAdapter {
12+
def tokenize(cmd: String): List[String] =
13+
scala.rulesscala.Proxy.tokenize(cmd)
14+
}
15+
}

third_party/utils/src/test/io/bazel/rulesscala/utils/TestUtil.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import scala.reflect.io.AbstractFile
77
import scala.reflect.io.Directory
88
import scala.reflect.io.PlainDirectory
99
import scala.reflect.io.VirtualDirectory
10-
import scala.tools.cmd.CommandLineParser
1110
import scala.tools.nsc.CompilerCommand
1211
import scala.tools.nsc.Global
1312
import scala.tools.nsc.Settings
@@ -116,7 +115,7 @@ object TestUtil {
116115
output: AbstractFile
117116
): List[StoreReporter#Info] = {
118117
// TODO: Optimize and cache global.
119-
val options = CommandLineParser.tokenize(compileOptions)
118+
val options = CommandLineParserAdapter.tokenize(compileOptions)
120119
val reporter = new StoreReporter()
121120
val settings = new Settings(println)
122121
val _ = new CompilerCommand(options, settings)

0 commit comments

Comments
 (0)