@@ -140,7 +140,7 @@ Valid values are:
140
140
allow_none = True ,
141
141
)
142
142
143
- def py_executable_base_impl (ctx , * , semantics , is_test , inherited_environment = []):
143
+ def py_executable_base_impl (ctx , * , semantics , is_test , inherited_environment = [], coverage_rc ):
144
144
"""Base rule implementation for a Python executable.
145
145
146
146
Google and Bazel call this common base and apply customizations using the
@@ -246,6 +246,7 @@ def py_executable_base_impl(ctx, *, semantics, is_test, inherited_environment =
246
246
inherited_environment = inherited_environment ,
247
247
semantics = semantics ,
248
248
output_groups = exec_result .output_groups ,
249
+ coverage_rc = coverage_rc ,
249
250
)
250
251
251
252
def _get_build_info (ctx , cc_toolchain ):
@@ -789,6 +790,7 @@ def _create_providers(
789
790
inherited_environment ,
790
791
runtime_details ,
791
792
output_groups ,
793
+ coverage_rc ,
792
794
semantics ):
793
795
"""Creates the providers an executable should return.
794
796
@@ -816,29 +818,26 @@ def _create_providers(
816
818
Returns:
817
819
A list of modern providers.
818
820
"""
819
- default_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
820
- ctx ,
821
- runfiles_details .default_runfiles ,
822
- )
823
- data_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
824
- ctx ,
825
- runfiles_details .data_runfiles ,
826
- )
827
- binary_info = struct (
828
- files = default_outputs ,
829
- default_runfiles = default_runfiles ,
830
- data_runfiles = data_runfiles ,
831
- executable = executable ,
832
- )
821
+ if coverage_rc :
822
+ extra_test_env = {"COVERAGE_RC" : coverage_rc .files .to_list ()[0 ].path }
823
+ default_runfiles = default_runfiles .merge (ctx .runfiles (files = coverage_rc .files .to_list ()))
824
+ else :
825
+ extra_test_env = {}
833
826
providers = [
834
827
DefaultInfo (
835
828
executable = executable ,
836
829
files = default_outputs ,
837
- default_runfiles = default_runfiles ,
838
- data_runfiles = data_runfiles ,
830
+ default_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
831
+ ctx ,
832
+ runfiles_details .default_runfiles ,
833
+ ),
834
+ data_runfiles = _py_builtins .make_runfiles_respect_legacy_external_runfiles (
835
+ ctx ,
836
+ runfiles_details .data_runfiles ,
837
+ ),
839
838
),
840
839
create_instrumented_files_info (ctx ),
841
- _create_run_environment_info (ctx , inherited_environment ),
840
+ _create_run_environment_info (ctx , inherited_environment , extra_test_env ),
842
841
PyExecutableInfo (
843
842
main = main_py ,
844
843
runfiles_without_exe = runfiles_details .runfiles_without_exe ,
@@ -905,9 +904,9 @@ def _create_providers(
905
904
runtime_details = runtime_details ,
906
905
)
907
906
providers .extend (extra_providers )
908
- return binary_info , providers
907
+ return providers
909
908
910
- def _create_run_environment_info (ctx , inherited_environment ):
909
+ def _create_run_environment_info (ctx , inherited_environment , extra_test_env ):
911
910
expanded_env = {}
912
911
for key , value in ctx .attr .env .items ():
913
912
expanded_env [key ] = _py_builtins .expand_location_and_make_variables (
@@ -916,6 +915,7 @@ def _create_run_environment_info(ctx, inherited_environment):
916
915
expression = value ,
917
916
targets = ctx .attr .data ,
918
917
)
918
+ expanded_env .update (extra_test_env )
919
919
return RunEnvironmentInfo (
920
920
environment = expanded_env ,
921
921
inherited_environment = inherited_environment ,
0 commit comments