Skip to content

Commit c2bdd03

Browse files
chancilacopybara-github
authored andcommitted
Move --repo_env to common options
Move --repo_env into common options and inject the value through CommandEnvironment since CommonCommandOptions cannot be accessed in SkyframeExecutor directly due to a circular dependency in the build. Addresses #12689 Closes #13003. PiperOrigin-RevId: 365035772
1 parent b65e38d commit c2bdd03

File tree

8 files changed

+34
-38
lines changed

8 files changed

+34
-38
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,20 +366,6 @@ public String getTypeDescription() {
366366
+ " wins, options for different variables accumulate.")
367367
public List<Map.Entry<String, String>> hostActionEnvironment;
368368

369-
@Option(
370-
name = "repo_env",
371-
converter = Converters.OptionalAssignmentConverter.class,
372-
allowMultiple = true,
373-
defaultValue = "null",
374-
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
375-
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES},
376-
help =
377-
"Specifies additional environment variables to be available only for repository rules."
378-
+ " Note that repository rules see the full environment anyway, but in this way"
379-
+ " configuration information can be passed to repositories through options without"
380-
+ " invalidating the action graph.")
381-
public List<Map.Entry<String, String>> repositoryEnvironment;
382-
383369
@Option(
384370
name = "collect_code_coverage",
385371
defaultValue = "false",

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class CommandEnvironment {
9191
private final Set<String> visibleActionEnv = new TreeSet<>();
9292
private final Set<String> visibleTestEnv = new TreeSet<>();
9393
private final Map<String, String> repoEnv = new TreeMap<>();
94+
private final Map<String, String> repoEnvFromOptions = new TreeMap<>();
9495
private final TimestampGranularityMonitor timestampGranularityMonitor;
9596
private final Thread commandThread;
9697
private final Command command;
@@ -245,17 +246,15 @@ public void exit(AbruptExitException exception) {
245246
}
246247
}
247248

248-
CoreOptions configOpts = options.getOptions(CoreOptions.class);
249-
if (configOpts != null) {
250-
for (Map.Entry<String, String> entry : configOpts.repositoryEnvironment) {
251-
String name = entry.getKey();
252-
String value = entry.getValue();
253-
if (value == null) {
254-
value = System.getenv(name);
255-
}
256-
if (value != null) {
257-
repoEnv.put(name, value);
258-
}
249+
for (Map.Entry<String, String> entry : commandOptions.repositoryEnvironment) {
250+
String name = entry.getKey();
251+
String value = entry.getValue();
252+
if (value == null) {
253+
value = System.getenv(name);
254+
}
255+
if (value != null) {
256+
repoEnv.put(entry.getKey(), entry.getValue());
257+
repoEnvFromOptions.put(entry.getKey(), entry.getValue());
259258
}
260259
}
261260
}
@@ -709,6 +708,7 @@ public void syncPackageLoading(OptionsProvider options)
709708
options.getOptions(BuildLanguageOptions.class),
710709
getCommandId(),
711710
clientEnv,
711+
repoEnvFromOptions,
712712
timestampGranularityMonitor,
713713
options);
714714
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,20 @@ public String getTypeDescription() {
491491
+ "one.")
492492
public boolean keepStateAfterBuild;
493493

494+
@Option(
495+
name = "repo_env",
496+
converter = Converters.OptionalAssignmentConverter.class,
497+
allowMultiple = true,
498+
defaultValue = "null",
499+
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
500+
effectTags = {OptionEffectTag.ACTION_COMMAND_LINES},
501+
help =
502+
"Specifies additional environment variables to be available only for repository rules."
503+
+ " Note that repository rules see the full environment anyway, but in this way"
504+
+ " configuration information can be passed to repositories through options without"
505+
+ " invalidating the action graph.")
506+
public List<Map.Entry<String, String>> repositoryEnvironment;
507+
494508
/** The option converter to check that the user can only specify legal profiler tasks. */
495509
public static class ProfilerTaskConverter extends EnumConverter<ProfilerTask> {
496510
public ProfilerTaskConverter() {

src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public WorkspaceInfoFromDiff sync(
236236
BuildLanguageOptions buildLanguageOptions,
237237
UUID commandId,
238238
Map<String, String> clientEnv,
239+
Map<String, String> repoEnvOption,
239240
TimestampGranularityMonitor tsgm,
240241
OptionsProvider options)
241242
throws InterruptedException, AbruptExitException {
@@ -261,6 +262,7 @@ public WorkspaceInfoFromDiff sync(
261262
buildLanguageOptions,
262263
commandId,
263264
clientEnv,
265+
repoEnvOption,
264266
tsgm,
265267
options);
266268
long startTime = System.nanoTime();

src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,11 +2695,12 @@ public WorkspaceInfoFromDiff sync(
26952695
BuildLanguageOptions buildLanguageOptions,
26962696
UUID commandId,
26972697
Map<String, String> clientEnv,
2698+
Map<String, String> repoEnvOption,
26982699
TimestampGranularityMonitor tsgm,
26992700
OptionsProvider options)
27002701
throws InterruptedException, AbruptExitException {
27012702
getActionEnvFromOptions(options.getOptions(CoreOptions.class));
2702-
setRepoEnv(options.getOptions(CoreOptions.class));
2703+
PrecomputedValue.REPO_ENV.set(injectable(), new LinkedHashMap<>(repoEnvOption));
27032704
RemoteOptions remoteOptions = options.getOptions(RemoteOptions.class);
27042705
setRemoteExecutionEnabled(remoteOptions != null && remoteOptions.isRemoteExecutionEnabled());
27052706
syncPackageLoading(
@@ -2785,16 +2786,6 @@ public void setActionEnv(Map<String, String> actionEnv) {
27852786
PrecomputedValue.ACTION_ENV.set(injectable(), actionEnv);
27862787
}
27872788

2788-
private void setRepoEnv(CoreOptions opt) {
2789-
LinkedHashMap<String, String> repoEnv = new LinkedHashMap<>();
2790-
if (opt != null) {
2791-
for (Map.Entry<String, String> v : opt.repositoryEnvironment) {
2792-
repoEnv.put(v.getKey(), v.getValue());
2793-
}
2794-
}
2795-
PrecomputedValue.REPO_ENV.set(injectable(), repoEnv);
2796-
}
2797-
27982789
public PathPackageLocator createPackageLocator(
27992790
ExtendedEventHandler eventHandler, List<String> packagePaths, Path workingDirectory) {
28002791
return PathPackageLocator.create(

src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ protected void initTargetPatternEvaluator(ConfiguredRuleClassProvider ruleClassP
281281
this.toolsRepository = ruleClassProvider.getToolsRepository();
282282
skyframeExecutor = createSkyframeExecutor(ruleClassProvider);
283283
PackageOptions packageOptions = Options.getDefaults(PackageOptions.class);
284+
284285
packageOptions.defaultVisibility = ConstantRuleVisibility.PRIVATE;
285286
packageOptions.showLoadingProgress = true;
286287
packageOptions.globbingThreads = 7;
@@ -296,6 +297,7 @@ protected void initTargetPatternEvaluator(ConfiguredRuleClassProvider ruleClassP
296297
Options.getDefaults(BuildLanguageOptions.class),
297298
UUID.randomUUID(),
298299
ImmutableMap.<String, String>of(),
300+
ImmutableMap.<String, String>of(),
299301
new TimestampGranularityMonitor(BlazeClock.instance()),
300302
OptionsProvider.EMPTY);
301303
} catch (InterruptedException | AbruptExitException e) {

src/test/java/com/google/devtools/build/lib/skyframe/AbstractCollectPackagesUnderDirectoryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ private void initBuildDriver() throws AbruptExitException, InterruptedException,
310310
Options.getDefaults(BuildLanguageOptions.class),
311311
UUID.randomUUID(),
312312
/*clientEnv=*/ ImmutableMap.of(),
313+
/*repoEnvOption=*/ ImmutableMap.of(),
313314
new TimestampGranularityMonitor(BlazeClock.instance()),
314315
OptionsProvider.EMPTY);
315316
buildDriver = skyframeExecutor.getDriver();

src/test/shell/bazel/starlark_repository_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,9 @@ genrule(
887887
)
888888
EOF
889889
cat > .bazelrc <<EOF
890-
build:foo --repo_env=FOO=foo
890+
common:foo --repo_env=FOO=foo
891891
build:bar --repo_env=FOO=bar
892-
build:qux --repo_env=FOO
892+
common:qux --repo_env=FOO
893893
EOF
894894

895895
bazel build --config=foo //:repoenv //:unrelated

0 commit comments

Comments
 (0)