Skip to content

Commit 353593c

Browse files
authored
feat(builtin): expand make vars in nodejs_binary/test env attr (#3456)
1 parent 25fb8c1 commit 353593c

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

docs/Built-ins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ nodejs_binary(
144144
<h4 id="nodejs_binary-env">env</h4>
145145

146146
(*<a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a>*): Specifies additional environment variables to set when the target is executed, subject to location
147-
expansion.
147+
and make variable expansion.
148148

149149
Defaults to `{}`
150150

@@ -402,7 +402,7 @@ nodejs_binary(
402402
<h4 id="nodejs_test-env">env</h4>
403403

404404
(*<a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a>*): Specifies additional environment variables to set when the target is executed, subject to location
405-
expansion.
405+
and make variable expansion.
406406

407407
Defaults to `{}`
408408

docs/Cypress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Defaults to `@npm//@bazel/cypress/internal:run-cypress.js`
237237
<h4 id="cypress_web_test-env">env</h4>
238238

239239
(*<a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a>*): Specifies additional environment variables to set when the target is executed, subject to location
240-
expansion.
240+
and make variable expansion.
241241

242242
Defaults to `{}`
243243

internal/node/node.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def _nodejs_binary_impl(ctx, data = [], runfiles = [], expanded_args = []):
210210

211211
# Add all env vars from the ctx attr
212212
for [key, value] in ctx.attr.env.items():
213-
env_vars += "export %s=%s\n" % (key, expand_location_into_runfiles(ctx, value, data))
213+
env_vars += "export %s=%s\n" % (key, ctx.expand_make_variables("env", expand_location_into_runfiles(ctx, value, data), {}))
214214

215215
# While we can derive the workspace from the pwd when running locally
216216
# because it is in the execroot path `execroot/my_wksp`, on RBE the
@@ -502,7 +502,7 @@ nodejs_binary(
502502
),
503503
"env": attr.string_dict(
504504
doc = """Specifies additional environment variables to set when the target is executed, subject to location
505-
expansion.
505+
and make variable expansion.
506506
""",
507507
default = {},
508508
),

internal/node/test/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ nodejs_binary(
409409
entry_point = "dump_build_env.js",
410410
env = {
411411
"LOC": "$(location :dump_build_env.js)",
412+
"SOME_TEST_ENV": "$(SOME_TEST_ENV)",
412413
},
413414
)
414415

internal/node/test/env.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,9 @@ describe('launcher.sh environment', function() {
118118
expect(env['FOO']).toBe('BAR');
119119
expect(env['LOC']).toBe('build_bazel_rules_nodejs/internal/node/test/dump_build_env.js');
120120
});
121+
122+
it('should expand make variables from env attr', function() {
123+
const env = require(runfiles.resolvePackageRelative('dump_build_env_attr.json'));
124+
expect(env['SOME_TEST_ENV']).toBe('some_value')
125+
});
121126
});

0 commit comments

Comments
 (0)