-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bazelrc: support --enable_platform_specific_config #9246
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,15 @@ | |
import com.google.common.collect.ArrayListMultimap; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.ListMultimap; | ||
import com.google.devtools.build.lib.events.Event; | ||
import com.google.devtools.build.lib.events.EventHandler; | ||
import com.google.devtools.build.lib.events.ExtendedEventHandler; | ||
import com.google.devtools.build.lib.runtime.commands.ProjectFileSupport; | ||
import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; | ||
import com.google.devtools.build.lib.util.ExitCode; | ||
import com.google.devtools.build.lib.util.OS; | ||
import com.google.devtools.build.lib.vfs.FileSystemUtils; | ||
import com.google.devtools.build.lib.vfs.Path; | ||
import com.google.devtools.common.options.InvocationPolicyEnforcer; | ||
|
@@ -315,6 +317,27 @@ ExitCode parseOptions(List<String> args, ExtendedEventHandler eventHandler) { | |
return ExitCode.SUCCESS; | ||
} | ||
|
||
/** | ||
* If --enable_platform_specific_config is true and the corresponding config definition exists, | ||
* we should enable the platform specific config. | ||
*/ | ||
private boolean shouldEnablePlatformSpecificConfig( | ||
OptionValueDescription enablePlatformSpecificConfigDescription, | ||
ListMultimap<String, RcChunkOfArgs> commandToRcArgs) { | ||
if (enablePlatformSpecificConfigDescription == null || | ||
!(boolean) enablePlatformSpecificConfigDescription.getValue()) { | ||
return false; | ||
} | ||
|
||
for (String commandName : getCommandNamesToParse(commandAnnotation)) { | ||
String defaultConfigDef = commandName + ":" + OS.getCurrent().getCanonicalName(); | ||
if (commandToRcArgs.containsKey(defaultConfigDef)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Expand the values of --config according to the definitions provided in the rc files and the | ||
* applicable command. | ||
|
@@ -325,23 +348,30 @@ void expandConfigOptions( | |
|
||
OptionValueDescription configValueDescription = | ||
optionsParser.getOptionValueDescription("config"); | ||
if (configValueDescription == null || configValueDescription.getCanonicalInstances() == null) { | ||
// No --config values were set, we can avoid this whole thing. | ||
return; | ||
if (configValueDescription != null && configValueDescription.getCanonicalInstances() != null) { | ||
// Find the base set of configs. This does not include the config options that might be | ||
// recursively included. | ||
ImmutableList<ParsedOptionDescription> configInstances = | ||
ImmutableList.copyOf(configValueDescription.getCanonicalInstances()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why make a copy? (I realize this is old code, just asking.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I actually don't know the reason.. |
||
|
||
// Expand the configs that are mentioned in the input. Flatten these expansions before parsing | ||
// them, to preserve order. | ||
for (ParsedOptionDescription configInstance : configInstances) { | ||
String configValueToExpand = (String) configInstance.getConvertedValue(); | ||
List<String> expansion = getExpansion(eventHandler, commandToRcArgs, configValueToExpand); | ||
optionsParser.parseArgsAsExpansionOfOption( | ||
configInstance, String.format("expanded from --%s", configValueToExpand), expansion); | ||
} | ||
} | ||
|
||
// Find the base set of configs. This does not include the config options that might be | ||
// recursively incuded. | ||
ImmutableList<ParsedOptionDescription> configInstances = | ||
ImmutableList.copyOf(configValueDescription.getCanonicalInstances()); | ||
|
||
// Expand the configs that are mentioned in the input. Flatten these expansions before parsing | ||
// them, to preserve order. | ||
for (ParsedOptionDescription configInstance : configInstances) { | ||
String configValueToExpand = (String) configInstance.getConvertedValue(); | ||
List<String> expansion = getExpansion(eventHandler, commandToRcArgs, configValueToExpand); | ||
OptionValueDescription enablePlatformSpecificConfigDescription = | ||
optionsParser.getOptionValueDescription("enable_platform_specific_config"); | ||
if (shouldEnablePlatformSpecificConfig(enablePlatformSpecificConfigDescription, commandToRcArgs)) { | ||
List<String> expansion = getExpansion(eventHandler, commandToRcArgs, OS.getCurrent().getCanonicalName()); | ||
optionsParser.parseArgsAsExpansionOfOption( | ||
configInstance, String.format("expanded from --%s", configValueToExpand), expansion); | ||
Iterables.getOnlyElement(enablePlatformSpecificConfigDescription.getCanonicalInstances()), | ||
String.format("enabled by --enable_platform_specific_config"), | ||
expansion); | ||
} | ||
|
||
// At this point, we've expanded everything, identify duplicates, if any, to warn about | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this cast safe? Shouldn't it be
(Boolean)
and check for null?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as long as there is a default value, it won't be null and will be converted to the correct type.
See
bazel/src/main/java/com/google/devtools/common/options/OptionDefinition.java
Line 255 in 1f684e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!