rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

plus-one dependency tracking does not handle custom rules

Open jdai8 opened this issue 3 years ago • 4 comments

The plus-one reduced classpath is implemented using an aspect that propagates along deps and exports. This doesn't work with custom rules that declare a custom attribute and call java_common.compile directly.

jdai8 avatar Aug 10 '22 18:08 jdai8

We can work around this by exporting the custom dependencies. This is not ideal for all cases though.

jdai8 avatar Aug 10 '22 18:08 jdai8

One potential solution is to expose a provider (maybe PlusOneDeps itself) so that custom rules can report their direct dependencies.

jdai8 avatar Aug 10 '22 18:08 jdai8

@jdai8 I'm not sure I fully follow your idea. Any chance you can make a small POC PR to demonstrate what you have in mind?

liucijus avatar Aug 11 '22 09:08 liucijus

Consider a custom rule my_java_rule with a custom_dep attribute:

def my_java_rule_impl(ctx):
  ...
  java_info = java_common.compile(
    ctx = ctx,
    source_files = ctx.attrs.srcs,
    deps = [ctx.attr.custom_dep[JavaInfo]],
    ...
  )

  return [java_info]
my_java_rule(
  name = "foo",
  ...
  custom_dep = "//:second_order_dep",
)
scala_library(
  name = "bar",
  srcs = ...,
  deps = [
    ":foo",
  ]
)

If we use the plus-one mode, I'd expect second_order_dep to be on the classpath for bar, but it's not.

jdai8 avatar Aug 15 '22 18:08 jdai8