extra_action support for rules written in Skylark
Based on src/main/protobuf/extra_actions_base.proto, it seems that extra_action support is hardcoded for native Bazel rules only.
Kythe would find it helpful to support extra_actions for custom rules written in Skylark so that we can extract/analyze compilations from a broader range of languages.
Spawn actions have built-in support for extra actions; whenever a skylark rule generates a spawn action, it immediately becomes available to kythe. I was wondering if we should actually remove the language-specific extra actions for C++ and Java (at least) and use the spawn action extra actions instead.
On Thu, Apr 16, 2015 at 12:41 AM, Cody Schroeder [email protected] wrote:
Based on src/main/protobuf/extra_actions_base.proto https://github.com/google/bazel/blob/f7afc7ace96c042ec3d1aafd158ae19fcb41446e/src/main/protobuf/extra_actions_base.proto, it seems that extra_action support is hardcoded for native Bazel rules only.
Kythe would find it helpful to support extra_actions for custom rules written in Skylark so that we can extract/analyze compilations from a broader range of languages.
— Reply to this email directly or view it on GitHub https://github.com/google/bazel/issues/124.
I'm trying to do something like this and it doesn't seem to work.
kythe/go/util/tools/BUILD
action_listener(
name = "print_extra_actions",
extra_actions = [":printer"],
mnemonics = [
"GoCompile", # the actual mnemonic I'm looking for
"SpawnAction", "Unknown", # me trying to grep for anything
],
)
extra_action(
name = "printer",
cmd = "$(location :print_extra_action) $(EXTRA_ACTION_FILE)",
tools = [":print_extra_action"],
)
go_binary(
name = "print_extra_action",
srcs = ["print_extra_action/print_extra_action.go"],
deps = [
"//third_party/bazel:extra_actions_base_proto",
"//third_party/go:protobuf",
],
)
go.bzl (highly elided)
def go_library_impl(ctx):
# ...
ctx.action(
inputs = inputs,
outputs = outs,
mnemonic = "GoCompile", # removing this doesn't allow the action to be caught by the "Unknown" mnemonic
command = cmd,
use_default_shell_env = True)
return struct(
# ...
)
# ...
go_library = rule(
go_library_impl,
attrs = base_attrs + {
"package": attr.string(),
},
outputs = {"archive": "%{name}.a"},
)
bazel build --experimental_action_listener=//kythe/go/util/tools:print_extra_actions //...
# nothing is printed
# however, adding "Javac" or "CppCompile" to "print_extra_actions" ensures that java/c++ actions are printed
Also, I'm in favor of removing the language-specific extra_actions. As long as all of the current information in JavaCompileInfo/CppCompileInfo is still accessible.
Just as a thought from someone not thoroughly versed on Bazel, I was thinking that is may be useful to embed a Map<string, Any> proto field in the ExtraActionInfo and allow the export of arbitrary information like the JavaCompilationArgs from Java rules and arbitrary lists/sets from Skylark. It could possibly be directly linked to a rule's providers instead of being a different mechanism.
I don't know what's going on there. Skylark rules should be generating spawn actions, and they should automatically get extra actions.
I don't think we pass any information that isn't in the command-line, but I could be wrong. If I'm right, then you can always parse the command line and get all the information back. In the Java case, you can use the parser from JavaBuilder. However, in the C++ case, you'll need a parser that is compatible with gcc and / or clang. Having a map would avoid requiring a parser in some cases because the data is more structured.
Are there any updates on fixing the extra_action support for Skylark spawn actions?
We're having this same issue with our own Lisp build rules. My own extra_action is not invoked when using our own mnemonic, LispCompile, while it does get invoked when trying with CppCompile. Can someone please take a look?
I have a fix, to be submitted in a few days.
Sorry for the delay!
I believe this is now fixed.