-
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
Conversation
When the value of this flag is true, a host platform specific config section will be enabled if it exists. Bazel recognizes your host platform as linux, osx, windows or freebsd. It's equivalent to add --config=linux on Linux platforms and --config=windows on Windows, etc. Fixes bazelbuild#5055 RELNOTES[NEW]: Support --enable_platform_specific_config, you can use this flag to enable flags in bazelrc according to your host platform. GOOGLE:
How about this instead:
|
Great, thanks! |
OptionValueDescription enablePlatformSpecificConfigDescription, | ||
ListMultimap<String, RcChunkOfArgs> commandToRcArgs) { | ||
if (enablePlatformSpecificConfigDescription == null || | ||
!(boolean) enablePlatformSpecificConfigDescription.getValue()) { |
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
public Object getDefaultValue() { |
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!
src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java
Outdated
Show resolved
Hide resolved
// 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I actually don't know the reason..
src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java
Show resolved
Hide resolved
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, | ||
effectTags = {OptionEffectTag.UNKNOWN}, | ||
help = | ||
"When the value of this flag is true, a host platform specific config section will be " |
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.
When the value of this flag is true
Could be rewritten as "If true".
... a host platform specific config section will be enabled if it exists
I find that confusing. Using active voice and straight word order feels clearer to me. How about: "... Bazel picks up host-OS-specific config lines from the bazelrc files."
I feel like an example would greatly help too: "For example, if the host OS is Linux and you run bazel build, Bazel would pick up lines starting with build:linux"
linux, osx, windows
macOS is the official name so let's use "macos" instead of "osx".
It's equivalent to add --config=linux on Linux platforms and --config=windows on Windows, etc.
We could be a little clearer here: "Enabling this flag is equivalent to using --config=linux on Linux, --config=windows on Windows, etc."
Putting it together:
If true, Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS identifiers are linux, macos, windows, and freebsd. Enabling this flag is equivalent to using --config=linux on Linux, --config=windows on Windows, etc.
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.
Wow, thanks for helping with the documentation. This is great improvement!
As for the name for mac, it seems we still use osx
in a lot of places in our code base. For example,
Line 63 in 71a213c
actual = "@platforms//os:osx", |
It prefer to keep the consistence util we decided to migrate everything to macos
. WDYT?
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.
Could you please ask the Apple team what's their preference?
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.
LGTM modulo the "osx" vs "macos" question.
OptionValueDescription enablePlatformSpecificConfigDescription, | ||
ListMultimap<String, RcChunkOfArgs> commandToRcArgs) { | ||
if (enablePlatformSpecificConfigDescription == null || | ||
!(boolean) enablePlatformSpecificConfigDescription.getValue()) { |
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!
src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java
Show resolved
Hide resolved
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, | ||
effectTags = {OptionEffectTag.UNKNOWN}, | ||
help = | ||
"When the value of this flag is true, a host platform specific config section will be " |
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.
Could you please ask the Apple team what's their preference?
This was merged via 5975545. |
This looks quite useful to me. |
@gunan The documentation is here: https://docs.bazel.build/versions/master/command-line-reference.html#flag--enable_platform_specific_config Here is an example in
Then the corresponding option will be enabled for each platform. Be aware, Bazel will only enable those options based on your host platform, instead of execution platform or target platform. |
Is there a way to use this to change definition of certain build configs? such as: |
No, there is no way to do that currently. But it sounds like a very useful feature. |
When the value of this flag is true, a host platform specific config
section will be enabled if it exists. Bazel recognizes your host
platform as linux, osx, windows or freebsd. It's equivalent to add
--config=linux on Linux platforms and --config=windows on Windows, etc.
Fixes #5055
RELNOTES[NEW]: Platform-specific bazelrc: with --enable_platform_specific_config you can
enable flags in bazelrc according to your host platform.
GOOGLE: