File tree Expand file tree Collapse file tree 4 files changed +72
-1
lines changed Expand file tree Collapse file tree 4 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -239,7 +239,8 @@ CurrentTarget: {current_target}
239239 compiler_classpath = _join_path (compiler_classpath_jars .to_list (), separator )
240240
241241 toolchain = ctx .toolchains ["@io_bazel_rules_scala//scala:toolchain_type" ]
242- scalacopts = toolchain .scalacopts + in_scalacopts
242+ scalacopts_expansion_targets = getattr (ctx .attr , "plugins" , [])
243+ scalacopts = [ctx .expand_location (v , scalacopts_expansion_targets ) for v in toolchain .scalacopts + in_scalacopts ]
243244
244245 scalac_args = """
245246Classpath: {cp}
Original file line number Diff line number Diff line change 1+ load ("//scala:scala.bzl" , "scala_library" )
2+
3+ scala_library (
4+ name = "check_expand_location" ,
5+ srcs = ["trivial.scala" ],
6+ plugins = [
7+ ":check_expand_location_plugin_deploy.jar" ,
8+ ],
9+ scalacopts = [
10+ "-P:diablerie:location=$(location :check_expand_location_plugin_deploy.jar)" ,
11+ ],
12+ )
13+
14+ scala_library (
15+ name = "check_expand_location_plugin" ,
16+ srcs = [
17+ "check_expand_location_plugin.scala" ,
18+ ],
19+ resource_strip_prefix = package_name (),
20+ resources = [
21+ ":gen-scalac-plugin.xml" ,
22+ ],
23+ deps = [
24+ "@io_bazel_rules_scala_scala_compiler" ,
25+ ],
26+ )
27+
28+ _gen_plugin_xml_cmd = """
29+ cat > $@ << EOF
30+ <plugin>
31+ <name>plugin</name>
32+ <classname>plugin.Plugin</classname>
33+ </plugin>
34+ """
35+
36+ genrule (
37+ name = "gen-scalac-plugin.xml" ,
38+ outs = ["scalac-plugin.xml" ],
39+ cmd = _gen_plugin_xml_cmd ,
40+ )
Original file line number Diff line number Diff line change 1+ package plugin
2+
3+ import scala .tools .nsc .Global
4+ import scala .tools .nsc .Phase
5+ import scala .tools .nsc .plugins .{ Plugin => NscPlugin }
6+ import scala .tools .nsc .plugins .PluginComponent
7+
8+ import java .io .File
9+
10+ final class Plugin (override val global : Global ) extends NscPlugin {
11+ override val name : String = " diablerie"
12+ override val description : String = " just another plugin"
13+ override val components : List [PluginComponent ] = Nil
14+
15+ override def processOptions (options : List [String ], error : String => Unit ): Unit = {
16+ options
17+ .find(_.startsWith(" location=" ))
18+ .map(_.stripPrefix(" location=" ))
19+ .map(v => new File (v).exists) match {
20+ case Some (true ) => ()
21+ case Some (false ) => error(" expanded location doesn't exist" )
22+ case None => error(" missing location argument" )
23+ }
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package trivial
2+
3+ object Trivial {
4+ // feel free to reuse this file for other plugin tests
5+ }
You can’t perform that action at this time.
0 commit comments