From 15c566ffda0c04a4def1f32db05029e43e069a2b Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Wed, 4 Sep 2024 22:09:42 +0200 Subject: [PATCH 1/3] feat(rules): add build_data_file field to PyExecutableInfo PyExecutableInfo was added in https://github.com/bazelbuild/rules_python/pull/2166 with the field `runfiles_without_exe` that intentionally excludes unrelated files. But, within Google we found that we need to pick up the file with build stamp information at that stage as well, so it is being additionally exposed. --- python/private/common/py_executable.bzl | 10 ++++++++-- python/private/py_executable_info.bzl | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/python/private/common/py_executable.bzl b/python/private/common/py_executable.bzl index 1437e2eb1d..4fe82fde32 100644 --- a/python/private/common/py_executable.bzl +++ b/python/private/common/py_executable.bzl @@ -426,6 +426,7 @@ 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] @@ -465,17 +466,21 @@ 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_runfiles = _create_runfiles_with_build_data( ctx, semantics.get_central_uncachable_version_file(ctx), semantics.get_extra_write_build_data_env(ctx), - )) + ) + build_data_file = build_data_runfiles.symlinks.to_list()[0].target_file + 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, ) @@ -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, ), ] diff --git a/python/private/py_executable_info.bzl b/python/private/py_executable_info.bzl index 7fa2f18308..7c2dc1be5e 100644 --- a/python/private/py_executable_info.bzl +++ b/python/private/py_executable_info.bzl @@ -30,6 +30,11 @@ file if precompiling is enabled. The runfiles the program needs, but without the original executable, files only added to support the original executable, or files specific to the original program. +""", + "build_data_file": """ +:type: File + +A symlink to build_data.txt if stamping is enabled, otherwise None. """, }, ) From 41bbe0689a8529e873ded93ba103805849abefe4 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Wed, 4 Sep 2024 22:15:38 +0200 Subject: [PATCH 2/3] Fix lint issue --- python/private/py_executable_info.bzl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/private/py_executable_info.bzl b/python/private/py_executable_info.bzl index 7c2dc1be5e..7653a5e72a 100644 --- a/python/private/py_executable_info.bzl +++ b/python/private/py_executable_info.bzl @@ -10,6 +10,11 @@ This provider is for executable-specific information (e.g. tests and binaries). ::: """, fields = { + "build_data_file": """ +:type: File + +A symlink to build_data.txt if stamping is enabled, otherwise None. +""", "interpreter_path": """ :type: None | str @@ -30,11 +35,6 @@ file if precompiling is enabled. The runfiles the program needs, but without the original executable, files only added to support the original executable, or files specific to the original program. -""", - "build_data_file": """ -:type: File - -A symlink to build_data.txt if stamping is enabled, otherwise None. """, }, ) From 700a0de3f52cd1828b178b7d7256e6440668bac1 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Thu, 5 Sep 2024 20:03:56 +0200 Subject: [PATCH 3/3] Fix review comments --- python/private/common/py_executable.bzl | 22 +++++++++++----------- python/private/py_executable_info.bzl | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python/private/common/py_executable.bzl b/python/private/common/py_executable.bzl index 4fe82fde32..80418acfcc 100644 --- a/python/private/common/py_executable.bzl +++ b/python/private/common/py_executable.bzl @@ -426,7 +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. + * build_data_file: A file with build stamp information if stamping is enabled, otherwise + None. """ common_runfiles_depsets = [main_py_files] @@ -466,12 +467,11 @@ def _get_base_runfiles_for_binary( data_runfiles = runfiles_with_exe if is_stamping_enabled(ctx, semantics) and semantics.should_include_build_data(ctx): - build_data_runfiles = _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), ) - build_data_file = build_data_runfiles.symlinks.to_list()[0].target_file default_runfiles = runfiles_with_exe.merge(build_data_runfiles) else: build_data_file = None @@ -488,15 +488,15 @@ 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 diff --git a/python/private/py_executable_info.bzl b/python/private/py_executable_info.bzl index 7653a5e72a..deb119428d 100644 --- a/python/private/py_executable_info.bzl +++ b/python/private/py_executable_info.bzl @@ -11,7 +11,7 @@ This provider is for executable-specific information (e.g. tests and binaries). """, fields = { "build_data_file": """ -:type: File +:type: None | File A symlink to build_data.txt if stamping is enabled, otherwise None. """,