Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions third_party/utils/src/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ scala_library(
any_3 = [
"io/bazel/rulesscala/utils/Scala3CompilerUtils.scala",
],
between_2_13_9_and_3 = [
"scala/tools/cmd/Scala_2_13_9_CommandLineParser.scala",
],
),
visibility = ["//visibility:public"],
deps = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scala.tools.cmd;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be unlikely but in theory some other compiler plugin might define the same workaround. Have you maybe considered creating a dedicated proxy explicitly for rulesscala to decrease chances of name clash?

I had this issue recently when starting work on dependency analyzer plugin port to Scala 3. I've defined it there as following:
For Scala 2.13.10+

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)
  }
}

For other versions:

package io.bazel.rulesscala.utils

import scala.tools.cmd.CommandLineParser

trait CompilerAPICompat {
  def tokenize(cmd: String): List[String] = CommandLineParser.tokenize(cmd)
}

Then I've redefined object TestUtil to extend this trait and used a proxy method instead of depending on compiler internals

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, this is better. I haven't actually done much Scala in a while, so this approach didn't occur to me, but it's definitely better than monkeypatching scala.tools.cmd.

I didn't see your original code in the existing code base, so I literally copied and pasted it into a new commit (crediting you, of course).

If this should live somewhere else, or you're about to check it in somewhere else (a quick find | xargs grep didn't turn it up), let me know.


// Hack due to CommandLineParser disappearing in Scala 2.13.9:
// https://github.com/scala/scala/pull/10057
object CommandLineParser {
def tokenize(line: String): List[String] = scala.sys.process.Parser
.tokenize(line)
}