feat: Add support for defining environment variables passed to extractors
This PR adds an `env` field to the `extractor_action` macro. This makes it possible to define extractor actions that require static environment variables. This functionality will be required for the new Rust extractor.
@@ -4,7 +4,7 @@ The extractor_action macro plumbs together a Kythe extractor to an extra_action
with an associated action_listener.
"""
-def extractor_action(name, extractor, args, mnemonics, output, needs_output = False, data = [], tags = []):
+def extractor_action(name, extractor, args, mnemonics, output, needs_output = False, data = [], tags = [], env = {}):
"""Creates an extra_action and an associated action_listener.
The action_listener is given the specified name and mnemonics.
@@ -23,15 +23,17 @@ def extractor_action(name, extractor, args, mnemonics, output, needs_output = Fa
output: The output file template (string).
data: A list of data dependencies (optional).
tags: A list of build tags (optional).
+ env: A dict of environment variables (optional).
"""
xa_name = name + "_extra_action"
+ env_vars = ["{}={}".format(*item) for item in env.items()]
native.extra_action(
name = xa_name,
data = data,
out_templates = [output],
tools = [extractor],
- cmd = " ".join(["$(location %s)" % extractor] + args),
+ cmd = " ".join(env_vars + ["$(location %s)" % extractor] + args),
tags = tags,
requires_action_output = needs_output,
)
