Skip to content
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

feat(rules): add build_data_file field to PyExecutableInfo #2181

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions python/private/common/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ def _get_base_runfiles_for_binary(
* data_runfiles: The data runfiles
* runfiles_without_exe: The default runfiles, but without the executable
or files specific to the original program/executable.
* build_data_file: A file with build stamp information if stamping is enabled, otherwise
None.
"""
common_runfiles_depsets = [main_py_files]

Expand Down Expand Up @@ -465,33 +467,36 @@ def _get_base_runfiles_for_binary(
data_runfiles = runfiles_with_exe

if is_stamping_enabled(ctx, semantics) and semantics.should_include_build_data(ctx):
default_runfiles = runfiles_with_exe.merge(_create_runfiles_with_build_data(
build_data_file, build_data_runfiles = _create_runfiles_with_build_data(
ctx,
semantics.get_central_uncachable_version_file(ctx),
semantics.get_extra_write_build_data_env(ctx),
))
)
default_runfiles = runfiles_with_exe.merge(build_data_runfiles)
else:
build_data_file = None
default_runfiles = runfiles_with_exe

return struct(
runfiles_without_exe = common_runfiles,
default_runfiles = default_runfiles,
build_data_file = build_data_file,
data_runfiles = data_runfiles,
)

def _create_runfiles_with_build_data(
ctx,
central_uncachable_version_file,
extra_write_build_data_env):
return ctx.runfiles(
symlinks = {
BUILD_DATA_SYMLINK_PATH: _write_build_data(
ctx,
central_uncachable_version_file,
extra_write_build_data_env,
),
},
build_data_file = _write_build_data(
ctx,
central_uncachable_version_file,
extra_write_build_data_env,
)
build_data_runfiles = ctx.runfiles(symlinks = {
BUILD_DATA_SYMLINK_PATH: build_data_file,
})
return build_data_file, build_data_runfiles

def _write_build_data(ctx, central_uncachable_version_file, extra_write_build_data_env):
# TODO: Remove this logic when a central file is always available
Expand Down Expand Up @@ -829,6 +834,7 @@ def _create_providers(
PyExecutableInfo(
main = main_py,
runfiles_without_exe = runfiles_details.runfiles_without_exe,
build_data_file = runfiles_details.build_data_file,
interpreter_path = runtime_details.executable_interpreter_path,
),
]
Expand Down
5 changes: 5 additions & 0 deletions python/private/py_executable_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ This provider is for executable-specific information (e.g. tests and binaries).
:::
""",
fields = {
"build_data_file": """
:type: None | File

A symlink to build_data.txt if stamping is enabled, otherwise None.
""",
"interpreter_path": """
:type: None | str

Expand Down