Skip to content

prevent crash when migrated native flag gets deleted#27793

Closed
aranguyen wants to merge 0 commit intobazelbuild:masterfrom
aranguyen:master
Closed

prevent crash when migrated native flag gets deleted#27793
aranguyen wants to merge 0 commit intobazelbuild:masterfrom
aranguyen:master

Conversation

@aranguyen
Copy link
Contributor

@aranguyen aranguyen commented Nov 26, 2025

For native flags that are migrated with flag_alias in MODULE.bazel, bazel previously crashed with Unrecognized Option error if the native flags get deleted.

This PR prevents blaze from crashing in such scenario.

Copy link
Contributor

@gregestren gregestren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted your chat comment about startup_options_test failing. Do you have a link to the specific failure?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes in SkyframeExecutor unrelated to this PR?

parsedOptionName = name;
} else {
throw new OptionsParsingException("Invalid options syntax: " + arg, arg);
throw new OptionsParsingException("Invalid options syntax: " + arg, arg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

if (!isFirstParsing) {
throw new OptionsParsingException("Unrecognized option: " + arg + suggestion, arg);
} else {
swapShorthandAlias(arg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first thought is this wouldn't have any effect?

I'm I'm reading this right, we reach this line on --foo before MODULE.bazel has mapped --foo=--//actual. Wouldn't that mean there isn't yet any alias mapping for --foo so this function couldn't do anything?

PriorityCategory.COMPUTED_DEFAULT,
"Options required to fetch target",
ImmutableList.of("--nobuild"));
ImmutableList.of("--nobuild"), false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading correctly there's only one case where you want to skip failing on an unknown option, and all other parsing calls should behave as before.

since OptionsParser has a builder interface:

I'd consider making this boolean a property of the builder so it doesn't have to be passed around in so many places.

Default it to false unless explicitly set differently in a builder method.

I'd also use more direct behavioral wording than isFirstParsing, although I appreciate "first parsing" is the context that triggers the behavior. But I'd name the variable after the actual behavior, like failOnUnknownOptions. Then add a comment in the caller code that sets this to true explaining why the first parsing sets this field this way.

Note that the post-repo mapping parsing step at

optionsParser = optionsParser.toBuilder().withConversionContext(mainRepoMapping).build();
reconstructs the options parser with a new builder. So that can flip the original parser's true field back to false for the second parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh that's a really good idea to make it part of the Builder. I myself thought passing it around was not a good idea. And agree on the naming as well. Thanks!!!!

gregestren added a commit to gregestren/bazel that referenced this pull request Dec 3, 2025
They can't be deleted until bazelbuild#27793 merges.
copybara-service bot pushed a commit that referenced this pull request Dec 9, 2025
This removes hard-coded flags `--python_path`, `--experimental_python_import_all_repositories`, and `--incompatible_remove_ctx_bazel_py_fragment`.

The first two are redefined in `rules_python` 1.7.0+ and linked into Bazel in #27792. This PR graveyards them but we can delete them outright when #27793 merges.

`--incompatible_remove_ctx_bazel_py_fragment` was added in Bazel 9 to allow toggling between the native and Starlark definitions.

By removing `--incompatible_remove_ctx_bazel_py_fragment`, this change removes the ability to revert to native definitions for post-9 Bazel.

For #26521 and bazel-contrib/rules_python#3252.

Closes #27842.

PiperOrigin-RevId: 842305784
Change-Id: If55aa925d0cd546e0671ddcb44f9e2819697b22f
copybara-service bot pushed a commit that referenced this pull request Dec 12, 2025
Related to #27842.

This removes hard-coded flags `--build_python_zip`, `--incompatible_default_to_explicit_init_py`, `--python_native_rules_allowlist`, `incompatible_python_disallow_native_rules`, and `incompatible_remove_ctx_py_fragment`.

These flags are re-difined in rules_python 1.7.0+ and linked into Bazel in #27792. This PR graveyards them but we can delete them outright when #27793 merges.

By removing --incompatible_remove_ctx_py_fragment, this change removes the ability to revert to native definitions for post-9 Bazel.

For #26521 and bazel-contrib/rules_python#3252.

Closes #27900.

PiperOrigin-RevId: 843734148
Change-Id: I1bb9624b3e5a579f6aa50663eb63ef4d7d482b57
@aranguyen aranguyen closed this Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants