Skip to content

Commit a507673

Browse files
authored
feat(rules): add build_data_file field to PyExecutableInfo (bazel-contrib#2181)
PyExecutableInfo was added in bazel-contrib#2166 with the field `runfiles_without_exe` that intentionally excludes files that are specific to that target/executable, such as the build data file (which may contain the target name, or other target-specific information). However, consuming tools (such as ones used within Google) may need to derive a file from that build data, override it completely, or be happy with its content as is. To aid that case, expose it via PyExecutableInfo.
1 parent 53f7407 commit a507673

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

python/private/common/py_executable.bzl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ def _get_base_runfiles_for_binary(
426426
* data_runfiles: The data runfiles
427427
* runfiles_without_exe: The default runfiles, but without the executable
428428
or files specific to the original program/executable.
429+
* build_data_file: A file with build stamp information if stamping is enabled, otherwise
430+
None.
429431
"""
430432
common_runfiles_depsets = [main_py_files]
431433

@@ -465,33 +467,36 @@ def _get_base_runfiles_for_binary(
465467
data_runfiles = runfiles_with_exe
466468

467469
if is_stamping_enabled(ctx, semantics) and semantics.should_include_build_data(ctx):
468-
default_runfiles = runfiles_with_exe.merge(_create_runfiles_with_build_data(
470+
build_data_file, build_data_runfiles = _create_runfiles_with_build_data(
469471
ctx,
470472
semantics.get_central_uncachable_version_file(ctx),
471473
semantics.get_extra_write_build_data_env(ctx),
472-
))
474+
)
475+
default_runfiles = runfiles_with_exe.merge(build_data_runfiles)
473476
else:
477+
build_data_file = None
474478
default_runfiles = runfiles_with_exe
475479

476480
return struct(
477481
runfiles_without_exe = common_runfiles,
478482
default_runfiles = default_runfiles,
483+
build_data_file = build_data_file,
479484
data_runfiles = data_runfiles,
480485
)
481486

482487
def _create_runfiles_with_build_data(
483488
ctx,
484489
central_uncachable_version_file,
485490
extra_write_build_data_env):
486-
return ctx.runfiles(
487-
symlinks = {
488-
BUILD_DATA_SYMLINK_PATH: _write_build_data(
489-
ctx,
490-
central_uncachable_version_file,
491-
extra_write_build_data_env,
492-
),
493-
},
491+
build_data_file = _write_build_data(
492+
ctx,
493+
central_uncachable_version_file,
494+
extra_write_build_data_env,
494495
)
496+
build_data_runfiles = ctx.runfiles(symlinks = {
497+
BUILD_DATA_SYMLINK_PATH: build_data_file,
498+
})
499+
return build_data_file, build_data_runfiles
495500

496501
def _write_build_data(ctx, central_uncachable_version_file, extra_write_build_data_env):
497502
# TODO: Remove this logic when a central file is always available
@@ -829,6 +834,7 @@ def _create_providers(
829834
PyExecutableInfo(
830835
main = main_py,
831836
runfiles_without_exe = runfiles_details.runfiles_without_exe,
837+
build_data_file = runfiles_details.build_data_file,
832838
interpreter_path = runtime_details.executable_interpreter_path,
833839
),
834840
]

python/private/py_executable_info.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ This provider is for executable-specific information (e.g. tests and binaries).
1010
:::
1111
""",
1212
fields = {
13+
"build_data_file": """
14+
:type: None | File
15+
16+
A symlink to build_data.txt if stamping is enabled, otherwise None.
17+
""",
1318
"interpreter_path": """
1419
:type: None | str
1520

0 commit comments

Comments
 (0)