Skip to content

Commit

Permalink
vendor env_execute
Browse files Browse the repository at this point in the history
  • Loading branch information
uhthomas committed May 4, 2023
1 parent f855461 commit 664aaee
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cue/cue.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@io_bazel_rules_go//go/private:common.bzl", "env_execute")

CuePkg = provider(
doc = "Collects files from cue_library for use in downstream cue_export",
fields = {
Expand Down Expand Up @@ -446,3 +444,22 @@ cue_repository = repository_rule(
"patch_cmds": attr.string_list(default = []),
},
)

def env_execute(ctx, arguments, environment = {}, **kwargs):
"""Executes a command in for a repository rule.
It prepends "env -i" to "arguments" before calling "ctx.execute".
Variables that aren't explicitly mentioned in "environment"
are removed from the environment. This should be preferred to "ctx.execute"
in most situations.
"""
if ctx.os.name.startswith("windows"):
return ctx.execute(arguments, environment = environment, **kwargs)
env_args = ["env", "-i"]
environment = dict(environment)
for var in ["TMP", "TMPDIR"]:
if var in ctx.os.environ and not var in environment:
environment[var] = ctx.os.environ[var]
for k, v in environment.items():
env_args.append("%s=%s" % (k, v))
arguments = env_args + arguments
return ctx.execute(arguments, **kwargs)

0 comments on commit 664aaee

Please sign in to comment.