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 CommandLineParserAdapter for >=2.13.9 #1634

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions third_party/utils/src/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ scala_library(
any_3 = [
"io/bazel/rulesscala/utils/Scala3CompilerUtils.scala",
],
before_2_13_9 = [
"io/bazel/rulesscala/utils/CompilerAPICompat_before_2_13_9.scala",
],
between_2_13_9_and_3 = [
"io/bazel/rulesscala/utils/CompilerAPICompat_since_2_13_9.scala",
],
),
visibility = ["//visibility:public"],
deps = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.bazel.rulesscala.utils

import scala.tools.cmd.CommandLineParser

trait CompilerAPICompat {
def tokenize(cmd: String): List[String] = CommandLineParser.tokenize(cmd)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package scala {
package rulesscala {
// proxy to private[scala] compiler API
object Proxy {
def tokenize(cmd: String): List[String] = sys.process.Parser.tokenize(cmd)
}
}
}

package io.bazel.rulesscala.utils {
trait CompilerAPICompat {
def tokenize(cmd: String): List[String] = scala.rulesscala.Proxy.tokenize(cmd)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import scala.reflect.io.AbstractFile
import scala.reflect.io.Directory
import scala.reflect.io.PlainDirectory
import scala.reflect.io.VirtualDirectory
import scala.tools.cmd.CommandLineParser
import scala.tools.nsc.CompilerCommand
import scala.tools.nsc.Global
import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.StoreReporter
import io.bazel.rulesscala.dependencyanalyzer.DependencyTrackingMethod

object TestUtil {
object TestUtil extends CompilerAPICompat {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to make CompilerAPICompat an object instead of a trait? It's not a big deal I guess, but on the other hand you are adding tokenize to the api of TestUtil and I'm not sure it belongs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I was thinking about doing that, too, as I tend to prefer helper objects to mixins for similar reasons.

I also renamed it to CommandLineParserAdapter to reflect the very specific reason for its existence.

final val defaultTarget = "//..."

val isWindows: Boolean = System.getProperty("os.name").toLowerCase.contains("windows")
Expand Down Expand Up @@ -116,7 +115,7 @@ object TestUtil {
output: AbstractFile
): List[StoreReporter#Info] = {
// TODO: Optimize and cache global.
val options = CommandLineParser.tokenize(compileOptions)
val options = tokenize(compileOptions)
val reporter = new StoreReporter()
val settings = new Settings(println)
val _ = new CompilerCommand(options, settings)
Expand Down