@@ -17,17 +17,37 @@ load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
1717load ("@rules_testing//lib:truth.bzl" , "matching" )
1818load ("@rules_testing//lib:util.bzl" , "PREVENT_IMPLICIT_BUILDING_TAGS" , rt_util = "util" )
1919load ("//python:defs.bzl" , "PyInfo" )
20+ load ("//python/private:reexports.bzl" , "BuiltinPyInfo" ) # buildifier: disable=bzl-visibility
2021load ("//tests/base_rules:py_info_subject.bzl" , "py_info_subject" )
2122load ("//tests/base_rules:util.bzl" , pt_util = "util" )
2223
2324_tests = []
2425
26+ _PRODUCES_PY_INFO_ATTRS = {
27+ "imports" : attr .string_list (),
28+ "srcs" : attr .label_list (allow_files = True ),
29+ }
30+
31+ def _create_py_info (ctx , provider_type ):
32+ return [provider_type (
33+ transitive_sources = depset (ctx .files .srcs ),
34+ imports = depset (ctx .attr .imports ),
35+ )]
36+
37+ def _produces_builtin_py_info_impl (ctx ):
38+ return _create_py_info (ctx , BuiltinPyInfo )
39+
40+ _produces_builtin_py_info = rule (
41+ implementation = _produces_builtin_py_info_impl ,
42+ attrs = _PRODUCES_PY_INFO_ATTRS ,
43+ )
44+
2545def _produces_py_info_impl (ctx ):
26- return [ PyInfo ( transitive_sources = depset ( ctx . files . srcs ))]
46+ return _create_py_info ( ctx , BuiltinPyInfo )
2747
2848_produces_py_info = rule (
2949 implementation = _produces_py_info_impl ,
30- attrs = { "srcs" : attr . label_list ( allow_files = True )} ,
50+ attrs = _PRODUCES_PY_INFO_ATTRS ,
3151)
3252
3353def _not_produces_py_info_impl (ctx ):
@@ -38,30 +58,58 @@ _not_produces_py_info = rule(
3858 implementation = _not_produces_py_info_impl ,
3959)
4060
41- def _test_consumes_provider (name , config ):
61+ def _py_info_propagation_setup (name , config , produce_py_info_rule , test_impl ):
4262 rt_util .helper_target (
4363 config .base_test_rule ,
4464 name = name + "_subject" ,
45- deps = [name + "_produces_py_info " ],
65+ deps = [name + "_produces_builtin_py_info " ],
4666 )
4767 rt_util .helper_target (
48- _produces_py_info ,
49- name = name + "_produces_py_info " ,
68+ produce_py_info_rule ,
69+ name = name + "_produces_builtin_py_info " ,
5070 srcs = [rt_util .empty_file (name + "_produce.py" )],
71+ imports = ["custom-import" ],
5172 )
5273 analysis_test (
5374 name = name ,
5475 target = name + "_subject" ,
55- impl = _test_consumes_provider_impl ,
76+ impl = test_impl ,
5677 )
5778
58- def _test_consumes_provider_impl (env , target ):
59- env .expect .that_target (target ).provider (
60- PyInfo ,
79+ def _py_info_propagation_test_impl (env , target , provider_type ):
80+ info = env .expect .that_target (target ).provider (
81+ provider_type ,
6182 factory = py_info_subject ,
62- ).transitive_sources ().contains ("{package}/{test_name}_produce.py" )
83+ )
84+
85+ info .transitive_sources ().contains ("{package}/{test_name}_produce.py" )
86+ info .imports ().contains ("custom-import" )
87+
88+ def _test_py_info_propagation_builtin (name , config ):
89+ _py_info_propagation_setup (
90+ name ,
91+ config ,
92+ _produces_builtin_py_info ,
93+ _test_py_info_propagation_builtin_impl ,
94+ )
95+
96+ def _test_py_info_propagation_builtin_impl (env , target ):
97+ _py_info_propagation_test_impl (env , target , BuiltinPyInfo )
98+
99+ _tests .append (_test_py_info_propagation_builtin )
100+
101+ def _test_py_info_propagation (name , config ):
102+ _py_info_propagation_setup (
103+ name ,
104+ config ,
105+ _produces_py_info ,
106+ _test_py_info_propagation_impl ,
107+ )
108+
109+ def _test_py_info_propagation_impl (env , target ):
110+ _py_info_propagation_test_impl (env , target , PyInfo )
63111
64- _tests .append (_test_consumes_provider )
112+ _tests .append (_test_py_info_propagation )
65113
66114def _test_requires_provider (name , config ):
67115 rt_util .helper_target (
0 commit comments