From f79b8ae15ed63fb3daba768735a4b852d69281ca Mon Sep 17 00:00:00 2001 From: Andy Scott Date: Sat, 7 Dec 2019 14:46:18 -0800 Subject: [PATCH 1/5] expand locations in scalac options --- scala/private/rule_impls.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index f57f905e3..7f72f5a83 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -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) for v in toolchain.scalacopts + in_scalacopts] scalac_args = """ Classpath: {cp} From 8b64e6103195a2b52d99c0b0dca6b3f623da640d Mon Sep 17 00:00:00 2001 From: Andy Scott Date: Sat, 7 Dec 2019 14:50:22 -0800 Subject: [PATCH 2/5] allow plugins in expansion --- scala/private/rule_impls.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 7f72f5a83..fa48a7766 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -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 = [ctx.expand_location(v) for v in toolchain.scalacopts + in_scalacopts] + scalacopts = [ctx.expand_location(v, ctx.attr.plugins) for v in toolchain.scalacopts + in_scalacopts] scalac_args = """ Classpath: {cp} From 16b5e91f2c6f63d3f9b5ada96cb63146be78d9cd Mon Sep 17 00:00:00 2001 From: Andy Scott Date: Sun, 22 Dec 2019 13:37:29 -0800 Subject: [PATCH 3/5] add a happy path test --- test/plugins/BUILD | 40 +++++++++++++++++++++++++++++++++++++++ test/plugins/plugin.scala | 25 ++++++++++++++++++++++++ test/plugins/usage.scala | 3 +++ 3 files changed, 68 insertions(+) create mode 100644 test/plugins/BUILD create mode 100644 test/plugins/plugin.scala create mode 100644 test/plugins/usage.scala diff --git a/test/plugins/BUILD b/test/plugins/BUILD new file mode 100644 index 000000000..f48868165 --- /dev/null +++ b/test/plugins/BUILD @@ -0,0 +1,40 @@ +load("//scala:scala.bzl", "scala_library") + +scala_library( + name = "usage", + srcs = ["usage.scala"], + plugins = [ + ":plugin_deploy.jar", + ], + scalacopts = [ + "-P:diablerie:location=$(location :plugin_deploy.jar)", + ], +) + +scala_library( + name = "plugin", + srcs = [ + "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 + plugin.Plugin + +""" + +genrule( + name = "gen-scalac-plugin.xml", + outs = ["scalac-plugin.xml"], + cmd = _gen_plugin_xml_cmd, +) diff --git a/test/plugins/plugin.scala b/test/plugins/plugin.scala new file mode 100644 index 000000000..fc5f61289 --- /dev/null +++ b/test/plugins/plugin.scala @@ -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") + } + } +} diff --git a/test/plugins/usage.scala b/test/plugins/usage.scala new file mode 100644 index 000000000..25b40f0f2 --- /dev/null +++ b/test/plugins/usage.scala @@ -0,0 +1,3 @@ +package usage + +object Usage From 756ab9b36b369dc68c8fd595991eb92b75d77db4 Mon Sep 17 00:00:00 2001 From: Andy Scott Date: Sun, 22 Dec 2019 13:40:43 -0800 Subject: [PATCH 4/5] make the target names more obvious --- test/plugins/BUILD | 12 ++++++------ ...ugin.scala => check_expand_location_plugin.scala} | 0 test/plugins/{usage.scala => trivial.scala} | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename test/plugins/{plugin.scala => check_expand_location_plugin.scala} (100%) rename test/plugins/{usage.scala => trivial.scala} (100%) diff --git a/test/plugins/BUILD b/test/plugins/BUILD index f48868165..1a5cf607e 100644 --- a/test/plugins/BUILD +++ b/test/plugins/BUILD @@ -1,20 +1,20 @@ load("//scala:scala.bzl", "scala_library") scala_library( - name = "usage", - srcs = ["usage.scala"], + name = "check_expand_location", + srcs = ["trivial.scala"], plugins = [ - ":plugin_deploy.jar", + ":check_expand_location_plugin_deploy.jar", ], scalacopts = [ - "-P:diablerie:location=$(location :plugin_deploy.jar)", + "-P:diablerie:location=$(location :check_expand_location_plugin_deploy.jar)", ], ) scala_library( - name = "plugin", + name = "check_expand_location_plugin", srcs = [ - "plugin.scala", + "check_expand_location_plugin.scala", ], resource_strip_prefix = package_name(), resources = [ diff --git a/test/plugins/plugin.scala b/test/plugins/check_expand_location_plugin.scala similarity index 100% rename from test/plugins/plugin.scala rename to test/plugins/check_expand_location_plugin.scala diff --git a/test/plugins/usage.scala b/test/plugins/trivial.scala similarity index 100% rename from test/plugins/usage.scala rename to test/plugins/trivial.scala From 658104619df0e6fc0e95e6b7885d6a4a12b9869e Mon Sep 17 00:00:00 2001 From: Andy Scott Date: Sun, 22 Dec 2019 13:41:29 -0800 Subject: [PATCH 5/5] comment --- test/plugins/trivial.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/plugins/trivial.scala b/test/plugins/trivial.scala index 25b40f0f2..ed5e226bc 100644 --- a/test/plugins/trivial.scala +++ b/test/plugins/trivial.scala @@ -1,3 +1,5 @@ -package usage +package trivial -object Usage +object Trivial { + // feel free to reuse this file for other plugin tests +}