How to retrieve the attributes of a Bazel workspace rule using aspects

793 views Asked by At

I'm writing a post-build tool that synthesizes maven pom files after a bazel build. I'm using aspects to gather relevant information on the various targets.

One of the features involves adding external jar dependencies to the relevant pom files.

Lets assume our workspace contains the following target:

maven_jar(
 name = "com_google_guava_guava",
 artifact = "com.google.guava:guava:19.0",
)

and one of our BUILD files contains a target which has guava as a dependency

scala_library(

name = "somename",
srcs = glob(["*.scala"]) + glob(["*.java"]),
deps = [
    "@com_google_guava_guava//jar:file" , 
],

In an aspect for this target how can one retrieve the attributes of maven_jar, specifically artifact?

(The closest I was able to get was:

[InputFileConfiguredTarget(@com_google_guava_guava//jar:guava-19.0.jar)]

Using ctx.rule.attr.srcs)

I could probably just parse the workspace external jars targets and get a map from the name to the artifact as a hybrid solution,

but a much more elegant solution would be for the aspect to provide the artifact by itself. Is it possible?

1

There are 1 answers

1
Damien Martin-Guillerez On

The "artifact" attribute is an attribute of a repository rule, which are not accessible from Skylark. The artifact seems like an information that could be integrated into the jar target in some way, feel free to file a feature request at https://github.com/bazelbuild/bazel/issues/new, with the reason why you need that.