Skip to content

Commit

Permalink
Move shell executable to its own configuration fragment.
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 191861074
  • Loading branch information
lberki authored and Copybara-Service committed Apr 6, 2018
1 parent 24f19ec commit 78651d4
Show file tree
Hide file tree
Showing 22 changed files with 512 additions and 377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ public RuleContext getRuleContextForTesting(
getPrerequisiteMapForTesting(
eventHandler, configuredTarget, configurations, toolchainContext))
.setConfigConditions(ImmutableMap.<Label, ConfigMatchingProvider>of())
.setUniversalFragment(ruleClassProvider.getUniversalFragment())
.setUniversalFragments(ruleClassProvider.getUniversalFragments())
.setToolchainContext(toolchainContext)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ public List<String> buildCommandLine(
private PathFragment shellPath(Map<String, String> executionInfo) {
// Use vanilla /bin/bash for actions running on mac machines.
return executionInfo.containsKey(ExecutionRequirements.REQUIRES_DARWIN)
? PathFragment.create("/bin/bash") : ruleContext.getConfiguration().getShellExecutable();
? PathFragment.create("/bin/bash")
: ruleContext.getConfiguration().getFragment(ShellConfiguration.class).getShellExecutable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ public static class Builder implements RuleDefinitionEnvironment {
private final Digraph<Class<? extends RuleDefinition>> dependencyGraph =
new Digraph<>();
private PatchTransition lipoDataTransition;
private Class<? extends BuildConfiguration.Fragment> universalFragment;
private List<Class<? extends BuildConfiguration.Fragment>> universalFragments =
new ArrayList<>();
private PrerequisiteValidator prerequisiteValidator;
private ImmutableMap.Builder<String, Object> skylarkAccessibleTopLevels =
ImmutableMap.builder();
Expand Down Expand Up @@ -340,9 +341,9 @@ public Builder addConfigurationFragment(ConfigurationFragmentFactory factory) {
return this;
}

public Builder setUniversalConfigurationFragment(
public Builder addUniversalConfigurationFragment(
Class<? extends BuildConfiguration.Fragment> fragment) {
this.universalFragment = fragment;
this.universalFragments.add(fragment);
return this;
}

Expand Down Expand Up @@ -456,7 +457,7 @@ public ConfiguredRuleClassProvider build() {
ImmutableList.copyOf(configurationOptions),
ImmutableList.copyOf(configurationFragmentFactories),
lipoDataTransition,
universalFragment,
ImmutableList.copyOf(universalFragments),
prerequisiteValidator,
skylarkAccessibleTopLevels.build(),
skylarkModules.build(),
Expand Down Expand Up @@ -555,10 +556,10 @@ public Label load(String from) {
private final PatchTransition lipoDataTransition;

/**
* A configuration fragment that should be available to all rules even when they don't
* Configuration fragments that should be available to all rules even when they don't
* explicitly require it.
*/
private final Class<? extends BuildConfiguration.Fragment> universalFragment;
private final ImmutableList<Class<? extends BuildConfiguration.Fragment>> universalFragments;

private final ImmutableList<BuildInfoFactory> buildInfoFactories;

Expand All @@ -583,7 +584,7 @@ private ConfiguredRuleClassProvider(
ImmutableList<Class<? extends FragmentOptions>> configurationOptions,
ImmutableList<ConfigurationFragmentFactory> configurationFragments,
PatchTransition lipoDataTransition,
Class<? extends BuildConfiguration.Fragment> universalFragment,
ImmutableList<Class<? extends BuildConfiguration.Fragment>> universalFragments,
PrerequisiteValidator prerequisiteValidator,
ImmutableMap<String, Object> skylarkAccessibleJavaClasses,
ImmutableList<Class<?>> skylarkModules,
Expand All @@ -600,7 +601,7 @@ private ConfiguredRuleClassProvider(
this.configurationOptions = configurationOptions;
this.configurationFragmentFactories = configurationFragments;
this.lipoDataTransition = lipoDataTransition;
this.universalFragment = universalFragment;
this.universalFragments = universalFragments;
this.prerequisiteValidator = prerequisiteValidator;
this.globals = createGlobals(skylarkAccessibleJavaClasses, skylarkModules);
this.nativeProviders = nativeProviders;
Expand Down Expand Up @@ -685,8 +686,8 @@ public RuleDefinition getRuleClassDefinition(String ruleClassName) {
* Returns the configuration fragment that should be available to all rules even when they
* don't explicitly require it.
*/
public Class<? extends BuildConfiguration.Fragment> getUniversalFragment() {
return universalFragment;
public ImmutableList<Class<? extends BuildConfiguration.Fragment>> getUniversalFragments() {
return universalFragments;
}

/**
Expand Down Expand Up @@ -808,7 +809,7 @@ public ImmutableSortedSet<Class<? extends BuildConfiguration.Fragment>> getAllFr
for (ConfigurationFragmentFactory factory : getConfigurationFragments()) {
fragmentsBuilder.add(factory.creates());
}
fragmentsBuilder.add(getUniversalFragment());
fragmentsBuilder.addAll(getUniversalFragments());
return fragmentsBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private ConfiguredTarget createRule(
.setVisibility(convertVisibility(prerequisiteMap, env.getEventHandler(), rule, null))
.setPrerequisites(prerequisiteMap)
.setConfigConditions(configConditions)
.setUniversalFragment(ruleClassProvider.getUniversalFragment())
.setUniversalFragments(ruleClassProvider.getUniversalFragments())
.setToolchainContext(toolchainContext)
.build();
if (ruleContext.hasErrors()) {
Expand Down Expand Up @@ -461,7 +461,7 @@ public ConfiguredAspect createAspect(
.setPrerequisites(prerequisiteMap)
.setAspectAttributes(aspectAttributes)
.setConfigConditions(configConditions)
.setUniversalFragment(ruleClassProvider.getUniversalFragment())
.setUniversalFragments(ruleClassProvider.getUniversalFragments())
.setToolchainContext(toolchainContext)
.build();
if (ruleContext.hasErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public ImmutableList<TransitiveInfoCollection> getFiles() {
private final BuildConfiguration hostConfiguration;
private final PatchTransition disableLipoTransition;
private final ConfigurationFragmentPolicy configurationFragmentPolicy;
private final Class<? extends BuildConfiguration.Fragment> universalFragment;
private final ImmutableList<Class<? extends BuildConfiguration.Fragment>> universalFragments;
private final ErrorReporter reporter;
@Nullable private final ToolchainContext toolchainContext;

Expand All @@ -199,7 +199,7 @@ private RuleContext(
ListMultimap<String, ConfiguredTargetAndData> targetMap,
ListMultimap<String, ConfiguredFilesetEntry> filesetEntryMap,
ImmutableMap<Label, ConfigMatchingProvider> configConditions,
Class<? extends BuildConfiguration.Fragment> universalFragment,
ImmutableList<Class<? extends BuildConfiguration.Fragment>> universalFragments,
String ruleClassNameForLogging,
ImmutableMap<String, Attribute> aspectAttributes,
@Nullable ToolchainContext toolchainContext) {
Expand All @@ -214,7 +214,7 @@ private RuleContext(
.map(a -> a.getDescriptor())
.collect(ImmutableList.toImmutableList());
this.configurationFragmentPolicy = builder.configurationFragmentPolicy;
this.universalFragment = universalFragment;
this.universalFragments = universalFragments;
this.targetMap = targetMap;
this.filesetEntryMap = filesetEntryMap;
this.configConditions = configConditions;
Expand Down Expand Up @@ -452,7 +452,7 @@ public ImmutableCollection<String> getSkylarkFragmentNames(ConfigurationTransiti

public <T extends Fragment> boolean isLegalFragment(
Class<T> fragment, ConfigurationTransition transition) {
return fragment == universalFragment
return universalFragments.contains(fragment)
|| fragment == PlatformConfiguration.class
|| configurationFragmentPolicy.isLegalConfigurationFragment(fragment, transition);
}
Expand Down Expand Up @@ -1405,7 +1405,7 @@ public static final class Builder implements RuleErrorConsumer {
private final AnalysisEnvironment env;
private final Rule rule;
private final ConfigurationFragmentPolicy configurationFragmentPolicy;
private Class<? extends BuildConfiguration.Fragment> universalFragment;
private ImmutableList<Class<? extends BuildConfiguration.Fragment>> universalFragments;
private final BuildConfiguration configuration;
private final BuildConfiguration hostConfiguration;
private PatchTransition disableLipoTransition;
Expand Down Expand Up @@ -1453,7 +1453,7 @@ RuleContext build() {
targetMap,
filesetEntryMap,
configConditions,
universalFragment,
universalFragments,
getRuleClassNameForLogging(),
aspectAttributes != null ? aspectAttributes : ImmutableMap.<String, Attribute>of(),
toolchainContext);
Expand Down Expand Up @@ -1498,12 +1498,13 @@ Builder setConfigConditions(ImmutableMap<Label, ConfigMatchingProvider> configCo
/**
* Sets the fragment that can be legally accessed even when not explicitly declared.
*/
Builder setUniversalFragment(Class<? extends BuildConfiguration.Fragment> fragment) {
Builder setUniversalFragments(
ImmutableList<Class<? extends BuildConfiguration.Fragment>> fragments) {
// TODO(bazel-team): Add this directly to ConfigurationFragmentPolicy, so we
// don't need separate logic specifically for checking this fragment. The challenge is
// that we need RuleClassProvider to figure out what this fragment is, and not every
// call state that creates ConfigurationFragmentPolicy has access to that.
this.universalFragment = fragment;
this.universalFragments = fragments;
return this;
}

Expand Down
Loading

0 comments on commit 78651d4

Please sign in to comment.