Read sources in rule?

181 views
Skip to first unread message

Magnus Andersson

unread,
Nov 14, 2019, 4:15:05 PM11/14/19
to bazel-discuss
Hi,

Is it possible to read source files (that is, the files in parameter 'srcs') and use their contents in a Starlark rule?

We are writing rules for a proprietary DSL. Some information about dependencies are defined in the source files, and we wonder if will need to duplicate this information in our rules.

Thanks,
Magnus

Paul Johnston

unread,
Nov 14, 2019, 8:27:46 PM11/14/19
to bazel-discuss
To my knowledge, not in a *build rule*.  However, a *repository rule* can do arbitrary things that could include reading source files and generating starlark, which could then be consumed by build rules.

Austin Schuh

unread,
Nov 17, 2019, 12:41:26 AM11/17/19
to Paul Johnston, bazel-discuss
Magnus,

rules_go solves this problem with gazelle if you are looking for prior art.
> --
> You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/46d3f4b1-3d1b-41ef-9ec2-d7c71e3630e8%40googlegroups.com.

Jay Conrod

unread,
Nov 18, 2019, 10:35:48 AM11/18/19
to Austin Schuh, Paul Johnston, bazel-discuss
To expand on this, gazelle is an extensible build file generating tool. It has built-in support for Go and proto, and it can be extended to generate rules for other languages.

In the rule implementation though, there's no way to access contents of source files. Only actions declared by rules may access files.

Reply all
Reply to author
Forward
0 new messages