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

expand locations in scalacopts #890

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
2 changes: 1 addition & 1 deletion scala/private/rule_impls.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ CurrentTarget: {current_target}
compiler_classpath = _join_path(compiler_classpath_jars.to_list(), separator)

toolchain = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"]
scalacopts = toolchain.scalacopts + in_scalacopts
scalacopts = [ctx.expand_location(v, ctx.attr.plugins) for v in toolchain.scalacopts + in_scalacopts]

scalac_args = """
Classpath: {cp}
Expand Down
40 changes: 40 additions & 0 deletions test/plugins/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load("//scala:scala.bzl", "scala_library")

scala_library(
name = "check_expand_location",
srcs = ["trivial.scala"],
plugins = [
":check_expand_location_plugin_deploy.jar",
],
scalacopts = [
"-P:diablerie:location=$(location :check_expand_location_plugin_deploy.jar)",
],
)

scala_library(
name = "check_expand_location_plugin",
srcs = [
"check_expand_location_plugin.scala",
],
resource_strip_prefix = package_name(),
resources = [
":gen-scalac-plugin.xml",
],
deps = [
"@io_bazel_rules_scala_scala_compiler",
],
)

_gen_plugin_xml_cmd = """
cat > $@ << EOF
<plugin>
<name>plugin</name>
<classname>plugin.Plugin</classname>
</plugin>
"""

genrule(
name = "gen-scalac-plugin.xml",
outs = ["scalac-plugin.xml"],
cmd = _gen_plugin_xml_cmd,
)
25 changes: 25 additions & 0 deletions test/plugins/check_expand_location_plugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package plugin

import scala.tools.nsc.Global
import scala.tools.nsc.Phase
import scala.tools.nsc.plugins.{ Plugin => NscPlugin}
import scala.tools.nsc.plugins.PluginComponent

import java.io.File

final class Plugin(override val global: Global) extends NscPlugin {
override val name: String = "diablerie"
override val description: String = "just another plugin"
override val components: List[PluginComponent] = Nil

override def processOptions(options: List[String], error: String => Unit): Unit = {
options
.find(_.startsWith("location="))
.map(_.stripPrefix("location="))
.map(v => new File(v).exists) match {
case Some(true) => ()
case Some(false) => error("expanded location doesn't exist")
case None => error("missing location argument")
}
}
}
5 changes: 5 additions & 0 deletions test/plugins/trivial.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package trivial

object Trivial {
// feel free to reuse this file for other plugin tests
}