Skip to content

Commit d94b365

Browse files
Deprecate --incompatible_repo_env_ignores_action_env
1 parent bc7f267 commit d94b365

File tree

5 files changed

+11
-154
lines changed

5 files changed

+11
-154
lines changed

src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ If specified, the value of the cpu constraint (`@platforms//cpu:cpu`) of
463463
`=name`, which unsets the variable of that name. This option can be used
464464
multiple times; for options given for the same variable, the latest wins,
465465
options for different variables accumulate.
466-
467-
Note that unless `--incompatible_repo_env_ignores_action_env` is true, all `name=value`
468-
pairs will be available to repository rules.
469466
""")
470467
public List<Converters.EnvVar> actionEnvironment;
471468

src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,16 @@ public static final class AllCommandGraveyardOptions extends OptionsBase {
965965
effectTags = {OptionEffectTag.NO_OP},
966966
help = "No-op.")
967967
public boolean legacyLocalFallback;
968+
969+
@Deprecated
970+
@Option(
971+
name = "incompatible_repo_env_ignores_action_env",
972+
defaultValue = "true",
973+
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
974+
effectTags = {OptionEffectTag.NO_OP},
975+
metadataTags = {OptionMetadataTag.DEPRECATED},
976+
help = "No-op.")
977+
public boolean repoEnvIgnoresActionEnv;
968978
}
969979

970980
@Override

src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,12 @@ public void exit(AbruptExitException exception) {
358358
switch (envVar) {
359359
case Converters.EnvVar.Set(String name, String value) -> {
360360
visibleActionEnv.remove(name);
361-
if (!options.getOptions(CommonCommandOptions.class).repoEnvIgnoresActionEnv) {
362-
repoEnv.put(name, value);
363-
repoEnvFromOptions.put(name, value);
364-
}
365361
}
366362
case Converters.EnvVar.Inherit(String name) -> {
367363
visibleActionEnv.add(name);
368364
}
369365
case Converters.EnvVar.Unset(String name) -> {
370366
visibleActionEnv.remove(name);
371-
if (!options.getOptions(CommonCommandOptions.class).repoEnvIgnoresActionEnv) {
372-
repoEnv.remove(name);
373-
repoEnvFromOptions.remove(name);
374-
}
375367
}
376368
}
377369
}
@@ -988,9 +980,7 @@ public String determineOutputFileSystem() {
988980
}
989981

990982
/**
991-
* Returns the repository environment created from the client environment, {@code --repo_env}, and
992-
* {@code --action_env=NAME=VALUE} (when {@code
993-
* --incompatible_repo_env_ignores_action_env=false}).
983+
* Returns the repository environment created from the client environment and {@code --repo_env}.
994984
*/
995985
public Map<String, String> getRepoEnv() {
996986
return Collections.unmodifiableMap(repoEnv);

src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,6 @@ public String getTypeDescription() {
610610
""")
611611
public List<Converters.EnvVar> repositoryEnvironment;
612612

613-
@Option(
614-
name = "incompatible_repo_env_ignores_action_env",
615-
defaultValue = "true",
616-
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
617-
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
618-
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
619-
help =
620-
"""
621-
If true, <code>--action_env=NAME=VALUE</code> will no longer affect repository rule \
622-
and module extension environments.
623-
""")
624-
public boolean repoEnvIgnoresActionEnv;
625-
626613
@Option(
627614
name = "experimental_strict_repo_env",
628615
defaultValue = "false",

src/test/shell/bazel/starlark_repository_test.sh

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -582,37 +582,6 @@ function environ_invalidation_test_template() {
582582
assert_equals 6 $(cat "${execution_file}")
583583
}
584584

585-
function environ_invalidation_action_env_test_template() {
586-
local startup_flag="${1-}"
587-
local command_flag="--noincompatible_repo_env_ignores_action_env"
588-
setup_starlark_repository
589-
590-
# We use a counter to avoid other invalidation to hide repository
591-
# invalidation (e.g., --action_env=K=V will cause all repositories to re-run).
592-
local execution_file="$(setup_invalidation_test)"
593-
594-
# Set to FOO=BAZ BAR=FOO
595-
FOO=BAZ BAR=FOO bazel ${startup_flag} build "${command_flag}" @foo//:bar >& $TEST_log \
596-
|| fail "Failed to build"
597-
expect_log "<1> FOO=BAZ BAR=FOO BAZ=undefined"
598-
assert_equals 1 $(cat "${execution_file}")
599-
600-
# Test with changing using --action_env
601-
bazel ${startup_flag} build "${command_flag}" \
602-
--action_env FOO=BAZ --action_env BAR=FOO --action_env BEZ=BAR \
603-
@foo//:bar >& $TEST_log || fail "Failed to build"
604-
assert_equals 1 $(cat "${execution_file}")
605-
bazel ${startup_flag} build "${command_flag}" \
606-
--action_env FOO=BAZ --action_env BAR=FOO --action_env BAZ=BAR \
607-
@foo//:bar >& $TEST_log || fail "Failed to build"
608-
assert_equals 1 $(cat "${execution_file}")
609-
bazel ${startup_flag} build "${command_flag}" \
610-
--action_env FOO=BAR --action_env BAR=FOO --action_env BAZ=BAR \
611-
@foo//:bar >& $TEST_log || fail "Failed to build"
612-
expect_log "<2> FOO=BAR BAR=FOO BAZ=BAR"
613-
assert_equals 2 $(cat "${execution_file}")
614-
}
615-
616585
function test_starlark_repository_environ_invalidation() {
617586
environ_invalidation_test_template
618587
}
@@ -622,14 +591,6 @@ function test_starlark_repository_environ_invalidation_batch() {
622591
environ_invalidation_test_template --batch
623592
}
624593

625-
function test_starlark_repository_environ_invalidation_action_env() {
626-
environ_invalidation_action_env_test_template
627-
}
628-
629-
function test_starlark_repository_environ_invalidation_action_env_batch() {
630-
environ_invalidation_action_env_test_template --batch
631-
}
632-
633594
# Test invalidation based on change to the bzl files
634595
function bzl_invalidation_test_template() {
635596
local startup_flag="${1-}"
@@ -3016,94 +2977,6 @@ EOF
30162977
@repo//... &> $TEST_log || fail "expected Bazel to succeed"
30172978
}
30182979

3019-
function test_execute_environment_repo_env_ignores_action_env_off() {
3020-
cat >> $(setup_module_dot_bazel) <<'EOF'
3021-
my_repo = use_repo_rule("//:repo.bzl", "my_repo")
3022-
my_repo(name="repo")
3023-
EOF
3024-
touch BUILD
3025-
cat > repo.bzl <<'EOF'
3026-
def _impl(ctx):
3027-
st = ctx.execute(
3028-
["env"],
3029-
)
3030-
if st.return_code:
3031-
fail("Command did not succeed")
3032-
vars = {line.partition("=")[0]: line.partition("=")[-1] for line in st.stdout.strip().split("\n")}
3033-
if vars.get("ACTION_ENV_PRESENT") != "value1":
3034-
fail("ACTION_ENV_PRESENT has wrong value: " + vars.get("ACTION_ENV_PRESENT"))
3035-
ctx.file("BUILD", "exports_files(['data.txt'])")
3036-
my_repo = repository_rule(_impl)
3037-
EOF
3038-
3039-
bazel build \
3040-
--noincompatible_repo_env_ignores_action_env \
3041-
--action_env=ACTION_ENV_PRESENT=value1 \
3042-
@repo//... &> $TEST_log || fail "expected Bazel to succeed"
3043-
}
3044-
3045-
function test_execute_environment_repo_env_ignores_action_env_on() {
3046-
cat >> $(setup_module_dot_bazel) <<'EOF'
3047-
my_repo = use_repo_rule("//:repo.bzl", "my_repo")
3048-
my_repo(name="repo")
3049-
EOF
3050-
touch BUILD
3051-
cat > repo.bzl <<'EOF'
3052-
def _impl(ctx):
3053-
st = ctx.execute(
3054-
["env"],
3055-
)
3056-
if st.return_code:
3057-
fail("Command did not succeed")
3058-
vars = {line.partition("=")[0]: line.partition("=")[-1] for line in st.stdout.strip().split("\n")}
3059-
if "ACTION_ENV_REMOVED" in vars:
3060-
fail("ACTION_ENV_REMOVED should not be in the environment")
3061-
ctx.file("BUILD", "exports_files(['data.txt'])")
3062-
my_repo = repository_rule(_impl)
3063-
EOF
3064-
3065-
bazel build \
3066-
--incompatible_repo_env_ignores_action_env \
3067-
--action_env=ACTION_ENV_REMOVED=value1 \
3068-
@repo//... &> $TEST_log || fail "expected Bazel to succeed"
3069-
}
3070-
3071-
function test_execute_environment_strict_vars() {
3072-
cat >> $(setup_module_dot_bazel) <<'EOF'
3073-
my_repo = use_repo_rule("//:repo.bzl", "my_repo")
3074-
my_repo(name="repo")
3075-
EOF
3076-
touch BUILD
3077-
cat > repo.bzl <<'EOF'
3078-
def _impl(ctx):
3079-
st = ctx.execute(
3080-
["env"],
3081-
)
3082-
if st.return_code:
3083-
fail("Command did not succeed")
3084-
vars = {line.partition("=")[0]: line.partition("=")[-1] for line in st.stdout.strip().split("\n")}
3085-
if vars.get("CLIENT_ENV_PRESENT") != "value1":
3086-
fail("CLIENT_ENV_PRESENT has wrong value: " + vars.get("CLIENT_ENV_PRESENT"))
3087-
if "CLIENT_ENV_REMOVED" in vars:
3088-
fail("CLIENT_ENV_REMOVED should not be in the environment")
3089-
if vars.get("REPO_ENV_PRESENT") != "value3":
3090-
fail("REPO_ENV_PRESENT has wrong value: " + vars.get("REPO_ENV_PRESENT"))
3091-
if "PATH" not in vars:
3092-
fail("PATH should be in the environment")
3093-
if ctx.os.name.startswith("windows") and "PATHEXT" not in vars:
3094-
fail("PATHEXT should be in the environment (on Windows)")
3095-
ctx.file("BUILD", "exports_files(['data.txt'])")
3096-
my_repo = repository_rule(_impl)
3097-
EOF
3098-
3099-
CLIENT_ENV_PRESENT=value1 CLIENT_ENV_REMOVED=value2 PATHEXT=".COM;.EXE;.BAT;.CMD;"\
3100-
bazel build \
3101-
--experimental_strict_repo_env \
3102-
--repo_env=CLIENT_ENV_PRESENT \
3103-
--repo_env=REPO_ENV_PRESENT=value3 \
3104-
@repo//... &> $TEST_log || fail "expected Bazel to succeed"
3105-
}
3106-
31072980
function test_dependency_on_repo_with_invalid_name() {
31082981
cat >> $(setup_module_dot_bazel) <<'EOF'
31092982
my_repo = use_repo_rule("//:repo.bzl", "my_repo")

0 commit comments

Comments
 (0)