forked from bazelbuild/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expand locations in scalacopts (bazelbuild#890)
* expand locations in scalac options * allow plugins in expansion * add a happy path test * make the target names more obvious * comment
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |