Skip to content

feat: command_line_option transition support, default windows to enable_runfiles=true#3610

Open
rickeylev wants to merge 5 commits intobazel-contrib:mainfrom
rickeylev:feat.command_line_option.transition
Open

feat: command_line_option transition support, default windows to enable_runfiles=true#3610
rickeylev wants to merge 5 commits intobazel-contrib:mainfrom
rickeylev:feat.command_line_option.transition

Conversation

@rickeylev
Copy link
Collaborator

@rickeylev rickeylev commented Feb 18, 2026

In order to run a py_binary on Windows, runfiles need to be created. However, Bazel
defaults to --enable_runfiles=false for Windows.

To fix, make py_binary set enable_runfiles=true for Windows by default. This
is chosen because supporting a runfiles-less mode is quite invasive (many changes
to bootstraps, plus improving the existing "recreate venv at runtime" logic to
recreate the entire venv).

A complication is that the //command_line_option:... targets don't actually
exist, so they can't be passed as targets to the config_settings attribute
(Bazel special cases them in other contexts). To fix, fake alias targets are created,
and the py_binary transition logic is updated to treat those fakes as aliases
for the real ones.

To allow arbitrary //command_line_option flags to be transitioned on (using the
add_transition_label() apis), the parsing logic treats any label whose package
is command_line_option as such a special aliases.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rickeylev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces significant enhancements to how py_binary and py_test rules interact with Bazel's configuration system, specifically by enabling them to transition on //command_line_option settings. This change provides greater flexibility in defining target configurations and improves cross-platform compatibility, particularly for Windows environments. The modifications involve new Bazel BUILD files for command_line_option aliases, updates to configuration processing logic, and refactoring of rule macros for cleaner code.

Highlights

  • Command Line Option Transition Support: Introduced a new command_line_option package to provide aliases for Bazel's built-in //command_line_option pseudo-targets, enabling py_binary and py_test rules to transition on these settings.
  • Configuration Setting Handling: Modified the apply_config_settings_attr function to specially handle command_line_option labels, ensuring they are correctly mapped to Bazel's internal configuration settings.
  • Windows Compatibility Improvements: Enhanced the build_data_writer.ps1 script for robust file writing on Windows by using .NET methods, addressing encoding and file locking issues. Also, improved stage2_bootstrap_template.py to handle Windows path conversions and error reporting for BUILD_DATA_FILE.
  • Macro Refactoring: Refactored py_binary_macro and py_test_macro to utilize a common setup function, common_executable_macro_kwargs_setup, which now also applies default configuration settings.
  • New Labels and Debugging: Added new labels like BUILD_RUNFILE_LINKS, ENABLE_RUNFILES, and PLATFORMS_OS_WINDOWS to common_labels.bzl, and included additional verbose print statements in python_bootstrap_template.txt for debugging runtime environment variables.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • BUILD.bazel
    • Added //command_line_option:distribution to the filegroup for internal development dependencies.
  • command_line_option/BUILD.bazel
    • Added a new BUILD file defining alias targets for build_runfile_links and enable_runfiles under the command_line_option package, along with a filegroup for distribution.
  • docs/api/rules_python/command_line_option/index.md
    • Added new documentation for the //command_line_option package.
  • python/private/attributes.bzl
    • Added an important note explaining the special handling of command_line_option labels in config_settings.
    • Modified apply_config_settings_attr to convert command_line_option labels to their Bazel-builtin pseudo-target format.
  • python/private/build_data_writer.ps1
    • Refactored the PowerShell script to collect all output lines into an array and write them using .NET's WriteAllLines with UTF8 without BOM, improving encoding and avoiding locking issues.
    • Added logic to set file permissions to allow everyone read access to the output file.
  • python/private/common_labels.bzl
    • Added BUILD_RUNFILE_LINKS and ENABLE_RUNFILES labels, referencing the new command_line_option aliases.
    • Added PLATFORMS_OS_WINDOWS label for platform-specific selections.
  • python/private/py_binary_macro.bzl
    • Replaced the direct call to convert_legacy_create_init_to_int with common_executable_macro_kwargs_setup.
  • python/private/py_executable.bzl
    • Updated _create_stage1_bootstrap to use runfiles_root_path for stage2_bootstrap.
    • Added add_config_setting_defaults function to apply default config_settings based on platform.
    • Introduced common_executable_macro_kwargs_setup to encapsulate common macro setup logic, including convert_legacy_create_init_to_int and add_config_setting_defaults.
    • Expanded the inputs and outputs for the transition to include //command_line_option:build_runfile_links and //command_line_option:enable_runfiles.
  • python/private/py_test_macro.bzl
    • Replaced the direct call to convert_legacy_create_init_to_int with common_executable_macro_kwargs_setup.
  • python/private/python_bootstrap_template.txt
    • Added verbose print statements for various environment variables and paths to aid debugging.
    • Improved the error message when the Python binary cannot be found, including both PYTHON_BINARY and PYTHON_BINARY_ACTUAL.
  • python/private/stage2_bootstrap_template.py
    • Added a comment noting that BUILD_DATA_FILE uses forward slashes and needs conversion for Windows.
    • Modified get_build_data to handle Windows paths by replacing forward slashes with backslashes and normalizing the path.
    • Updated get_build_data to open files with utf-8-sig encoding to handle Windows BOM and added detailed error notes for debugging file access issues.
    • Added a comment to find_runfiles_root indicating that --enable_runfiles=false is likely set when runfiles cannot be found.
  • tests/bootstrap_impls/BUILD.bazel
    • Loaded py_binary and py_test rules.
    • Added a new py_test target named system_python_nodeps_test.
  • tests/bootstrap_impls/system_python_nodeps_test.py
    • Added a simple Python script for testing.
  • tests/pypi/whl_installer/wheel_installer_test.py
    • Modified the tearDown method to ignore errors when removing the wheel directory on Windows, addressing file locking issues.
  • tests/support/py_reconfig.bzl
    • Removed the direct processing of attr.config_settings from _perform_transition_impl.
    • Added //command_line_option:build_runfile_links and //command_line_option:stamp to _RECONFIG_INPUTS.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for //command_line_option transitions in py_binary and py_test rules, providing more flexible configurations. However, a critical security issue was identified in the PowerShell script (build_data_writer.ps1) used to write build data on Windows, as it explicitly grants global read access to the output file. This violates the principle of least privilege and requires remediation. Additionally, consider adding documentation for the new feature and a minor refactoring for improved code conciseness.

@rickeylev rickeylev changed the title feat: command_line_option transition support feat: command_line_option transition support, default windows to enable_runfiles=true Feb 18, 2026
@rickeylev rickeylev force-pushed the feat.command_line_option.transition branch from 23c21b1 to 4187c31 Compare February 18, 2026 02:31
@rickeylev rickeylev force-pushed the feat.command_line_option.transition branch from 4187c31 to a297813 Compare February 18, 2026 03:00
@rickeylev rickeylev enabled auto-merge February 18, 2026 03:05
@rickeylev rickeylev disabled auto-merge February 18, 2026 03:05
@rickeylev rickeylev force-pushed the feat.command_line_option.transition branch from a297813 to 9cd82dc Compare February 18, 2026 03:09
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

Comments