Repository navigation
feat(rules): describe runfiles groups for rules_runfiles_group #4254
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
Open
FrankPortman
wants to merge
8
commits into
bazel-contrib:main
Choose a base branch
from
FrankPortman:runfiles_group_describers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+935
−45
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d291a5b
feat(rules): describe runfiles groups for rules_runfiles_group
FrankPortman 4b536eb
Merge remote-tracking branch 'upstream/main' into runfiles_group_desc…
FrankPortman 0339706
feat(rules): move runfiles groups to the toolchain-walking describer API
FrankPortman b43012b
DO NOT MERGE: use the rules_runfiles_group dev registry in nested wor…
FrankPortman 951b17b
chore: bump rules_runfiles_group to 99.0.0-dev.20261019.1.1cee2dd
FrankPortman d206a54
fix(rules): load only the describer side of rules_runfiles_group
FrankPortman 5878802
style: sort the runfiles group attributes, name the Bazel versions fo…
FrankPortman a87d772
Merge remote-tracking branch 'upstream/main' into runfiles_group_desc…
FrankPortman 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # https://docs.bazel.build/versions/main/best-practices.html#using-the-bazelrc-file | ||
| try-import %workspace%/user.bazelrc | ||
| common --incompatible_python_disallow_native_rules | ||
|
|
||
| # TODO: Delete before merging; see the root .bazelrc. | ||
| common --registry=https://bazel-contrib.github.io/rules_runfiles_group --registry=https://bcr.bazel.build |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| (rules) Added {obj}`PyInfo.direct_implicit_pyc_files` and | ||
| {obj}`PyExecutableInfo.venv_runfiles`. |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| (rules) `py_binary` and `py_test` describe their runfiles groups for | ||
| [rules_runfiles_group](https://github.com/bazel-contrib/rules_runfiles_group), | ||
| so packaging rules like rules_img's `image_from_binary` can put the runtime, | ||
| each PyPI package and each library in a layer of its own. Needs Bazel 8.8 or | ||
| later ([#3757](https://github.com/bazel-contrib/rules_python/issues/3757)). | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ load( | |
| "is_bool", | ||
| "is_windows_platform", | ||
| "maybe_create_repo_mapping", | ||
| "py_info_runfiles_files", | ||
| "relative_path", | ||
| "runfiles_root_path", | ||
| ) | ||
|
|
@@ -92,10 +93,17 @@ EXECUTABLE_ATTRS = dicts.add( | |
| WINDOWS_CONSTRAINTS_ATTRS, | ||
| # starlark flags attributes | ||
| { | ||
| # Read by rules_runfiles_group's packaging aspects; see runfiles_groups.bzl. | ||
| "_aspect_rule_hints": attr.label_list(default = [ | ||
| "//python/private:py_executable_runfiles_group_describer", | ||
| # What //python:toolchain_type is an alias of. | ||
| "@bazel_tools//tools/python:toolchain_type", | ||
|
Collaborator
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. IIRC there is an alias for this in our own repo, please use that. |
||
| ]), | ||
| "_build_python_zip_flag": attr.label(default = "//python/config_settings:build_python_zip"), | ||
| "_default_to_explicit_init_py_flag": attr.label(default = "//python/config_settings:incompatible_default_to_explicit_init_py"), | ||
| "_python_import_all_repositories_flag": attr.label(default = "//python/config_settings:experimental_python_import_all_repositories"), | ||
| "_python_path_flag": attr.label(default = "//python/config_settings:python_path"), | ||
| "_runfiles_group_attrs": attr.string_list(default = ["_debugger_flag", "data", "deps", "srcs"]), | ||
| }, | ||
| { | ||
| "interpreter_args": lambda: attrb.StringList( | ||
|
|
@@ -364,11 +372,8 @@ def _create_executable( | |
| venv = venv, | ||
| build_data_file = runfiles_details.build_data_file, | ||
| ) | ||
| extra_runfiles = ctx.runfiles( | ||
| [stage2_bootstrap] + ( | ||
| venv.files_without_interpreter if venv else [] | ||
| ), | ||
| ).merge(venv.lib_runfiles) | ||
| venv_runfiles = ctx.runfiles(venv.files_without_interpreter).merge(venv.lib_runfiles) | ||
| extra_runfiles = ctx.runfiles([stage2_bootstrap]).merge(venv_runfiles) | ||
| zip_main = _create_zip_main( | ||
| ctx, | ||
| stage2_bootstrap = stage2_bootstrap, | ||
|
|
@@ -377,6 +382,7 @@ def _create_executable( | |
| ) | ||
| else: | ||
| stage2_bootstrap = None | ||
| venv_runfiles = None | ||
| extra_runfiles = ctx.runfiles() | ||
| zip_main = ctx.actions.declare_file(base_executable_name + ".temp", sibling = executable) | ||
| _create_stage1_bootstrap( | ||
|
|
@@ -495,9 +501,8 @@ WARNING: Target: {} | |
|
|
||
| app_runfiles = builders.RunfilesBuilder() | ||
| app_runfiles.add(runfiles_details.app_runfiles) | ||
| if venv: | ||
| app_runfiles.add(venv.files_without_interpreter) | ||
| app_runfiles.add(venv.lib_runfiles) | ||
| if venv_runfiles: | ||
| app_runfiles.add(venv_runfiles) | ||
|
|
||
| # The interpreter is added this late in the process so that it isn't | ||
| # added to the zipped files. | ||
|
|
@@ -524,6 +529,8 @@ WARNING: Target: {} | |
| venv_python_exe = venv.interpreter if venv else None, | ||
| # runfiles|None; runfiles in the venv for the interpreter | ||
| venv_interpreter_runfiles = venv.interpreter_runfiles if venv else None, | ||
| # runfiles|None; runfiles in the venv for the application | ||
| venv_runfiles = venv_runfiles, | ||
| # depset[ExplicitSymlink]|None; symlinks that should be created | ||
| venv_interpreter_symlinks = venv.interpreter_symlinks if venv else None, | ||
| ) | ||
|
|
@@ -1317,6 +1324,7 @@ def py_executable_base_impl(ctx, *, semantics, is_test, inherited_environment = | |
| venv_interpreter_runfiles = exec_result.venv_interpreter_runfiles, | ||
| venv_interpreter_symlinks = exec_result.venv_interpreter_symlinks, | ||
| venv_python_exe = exec_result.venv_python_exe, | ||
| venv_runfiles = exec_result.venv_runfiles, | ||
| ) | ||
| _add_provider_py_runtime_info(providers, runtime_details) | ||
| _add_provider_py_cc_link_params_info(providers, cc_details.cc_info_for_propagating) | ||
|
|
@@ -1444,19 +1452,7 @@ def _get_runtime_details(ctx): | |
| fail("'python_path' must be an absolute path or a name to be resolved from the system PATH (e.g., 'python', 'python3').") | ||
|
|
||
| effective_runtime = _maybe_get_runtime_from_ctx(ctx) | ||
|
|
||
| direct = [] # List of files | ||
| transitive = [] # List of depsets | ||
| if effective_runtime.interpreter: | ||
| direct.append(effective_runtime.interpreter) | ||
| transitive.append(effective_runtime.files) | ||
|
|
||
| if ctx.configuration.coverage_enabled: | ||
| if effective_runtime.coverage_tool: | ||
| direct.append(effective_runtime.coverage_tool) | ||
| if effective_runtime.coverage_files: | ||
| transitive.append(effective_runtime.coverage_files) | ||
| runtime_files = depset(direct = direct, transitive = transitive) | ||
| runtime_files = get_runtime_files(ctx, effective_runtime) | ||
|
|
||
| executable_interpreter_path = _get_interpreter_path( | ||
| ctx, | ||
|
|
@@ -1478,6 +1474,29 @@ def _get_runtime_details(ctx): | |
| runfiles = ctx.runfiles(transitive_files = runtime_files), | ||
| ) | ||
|
|
||
| def get_runtime_files(ctx, runtime): | ||
| """Returns the runtime files an executable puts into its runfiles. | ||
|
|
||
| Args: | ||
| ctx: The rule or aspect ctx. | ||
| runtime: PyRuntimeInfo; the runtime of the executable. | ||
|
|
||
| Returns: | ||
| depset[File] | ||
| """ | ||
| direct = [] # List of files | ||
| transitive = [] # List of depsets | ||
| if runtime.interpreter: | ||
| direct.append(runtime.interpreter) | ||
| transitive.append(runtime.files) | ||
|
|
||
| if ctx.configuration.coverage_enabled: | ||
| if runtime.coverage_tool: | ||
| direct.append(runtime.coverage_tool) | ||
| if runtime.coverage_files: | ||
| transitive.append(runtime.coverage_files) | ||
| return depset(direct = direct, transitive = transitive) | ||
|
|
||
| def _maybe_get_runtime_from_ctx(ctx): | ||
| """Finds the PyRuntimeInfo from the toolchain or attribute, if available. | ||
|
|
||
|
|
@@ -1556,17 +1575,7 @@ def _get_base_runfiles_for_binary( | |
| if not (PyInfo in dep or (BuiltinPyInfo != None and BuiltinPyInfo in dep)): | ||
| continue | ||
| info = dep[PyInfo] if PyInfo in dep else dep[BuiltinPyInfo] | ||
| app_runfiles.files.add(info.transitive_sources) | ||
|
|
||
| # Everything past this won't work with BuiltinPyInfo | ||
| if not hasattr(info, "transitive_pyc_files"): | ||
| continue | ||
|
|
||
| app_runfiles.files.add(info.transitive_pyc_files) | ||
| if pyc_collection_enabled: | ||
| app_runfiles.files.add(info.transitive_implicit_pyc_files) | ||
| else: | ||
| app_runfiles.files.add(info.transitive_implicit_pyc_source_files) | ||
| app_runfiles.files.add(py_info_runfiles_files(info, pyc_collection_enabled)) | ||
|
|
||
| app_runfiles.runfiles.append(collect_runfiles(ctx)) | ||
| if extra_deps: | ||
|
|
@@ -2017,7 +2026,8 @@ def _add_provider_py_executable_info( | |
| venv_app_symlinks, | ||
| venv_interpreter_runfiles, | ||
| venv_interpreter_symlinks, | ||
| venv_python_exe): | ||
| venv_python_exe, | ||
| venv_runfiles): | ||
| """Adds the PyExecutableInfo provider. | ||
|
|
||
| Args: | ||
|
|
@@ -2034,6 +2044,7 @@ def _add_provider_py_executable_info( | |
| venv_interpreter_runfiles: runfiles; runfiles specific to the interpreter for the venv. | ||
| venv_interpreter_symlinks: depset[ExplicitSymlink]; interpreter-specific symlinks to create for the venv. | ||
| venv_python_exe: File; the python executable in the venv. | ||
| venv_runfiles: runfiles; the venv's files for the application. | ||
| """ | ||
| providers.append(PyExecutableInfo( | ||
| app_runfiles = app_runfiles, | ||
|
|
@@ -2047,6 +2058,7 @@ def _add_provider_py_executable_info( | |
| venv_interpreter_runfiles = venv_interpreter_runfiles, | ||
| venv_interpreter_symlinks = venv_interpreter_symlinks, | ||
| venv_python_exe = venv_python_exe, | ||
| venv_runfiles = venv_runfiles, | ||
| )) | ||
|
|
||
| def _add_provider_py_runtime_info(providers, runtime_details): | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
I am not sure if this is ideal, but it can be a good default.