Skip to content

run_binary does not include executable environment from RunEnvironmentInfo #1200

@brett-patterson-ent

Description

@brett-patterson-ent

If the tool provided to run_binary has a RunEnvironmentInfo provider, that environment is not included when running the tool. For example, this is how py_binary from rules_py sets provided environment variables.

This basic patch includes the environment and allows envs specified directly to run_binary to override the ones provided by the tool:

diff --git lib/private/run_binary.bzl lib/private/run_binary.bzl
index b480a27..9f12b21 100644
--- lib/private/run_binary.bzl
+++ lib/private/run_binary.bzl
@@ -51,6 +51,8 @@ Possible fixes:
     for a in ctx.attr.args:
         args.add_all(split_args(expand_variables(ctx, ctx.expand_location(a, targets = ctx.attr.srcs), inputs = ctx.files.srcs, outs = outputs)))
     envs = {}
+    if RunEnvironmentInfo in ctx.attr.tool:
+        envs = ctx.attr.tool[RunEnvironmentInfo].environment
     for k, v in ctx.attr.env.items():
         envs[k] = expand_variables(ctx, ctx.expand_location(v, targets = ctx.attr.srcs), inputs = ctx.files.srcs, outs = outputs, attribute_name = "env")

The patch is working for our use cases right now. Happy to submit it as a PR if the implementation seems generally correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions