@@ -129,13 +129,12 @@ def _test_action_graph_impl(env, target):
129129 link_action = link_action_subject .from_target (env , target )
130130
131131 # link.inputs = { hello.o }
132- hello_obj_files = [
133- f
134- for f in link_action .actual .inputs .to_list ()
135- if f .basename .startswith ("hello." ) and f .extension in ["o" , "obj" ]
136- ]
137- env .expect .that_collection (hello_obj_files ).has_size (1 )
138- obj_file = hello_obj_files [0 ]
132+ hello_obj_files = link_action .inputs ().transform (
133+ desc = "hello object files" ,
134+ filter = lambda f : f .basename .startswith ("hello." ) and f .extension in ["o" , "obj" ],
135+ )
136+ hello_obj_files .has_size (1 )
137+ obj_file = hello_obj_files .offset (0 , subjects .file ).actual
139138
140139 # link.outputs = { hello }
141140 link_action .outputs ().contains_exactly ([executable ])
@@ -279,13 +278,10 @@ def _test_pic(name, **kwargs):
279278
280279def _test_pic_impl (env , target ):
281280 link_action = link_action_subject .from_target (env , target )
282- hello_obj_files = [
283- f
284- for f in link_action .actual .inputs .to_list ()
285- if f .basename .startswith ("hello.pic." ) and f .extension in ["o" , "obj" ]
286- ]
287-
288- env .expect .that_collection (hello_obj_files ).has_size (1 )
281+ link_action .inputs ().transform (
282+ desc = "hello pic object files" ,
283+ filter = lambda f : f .basename .startswith ("hello.pic." ) and f .extension in ["o" , "obj" ],
284+ ).has_size (1 )
289285
290286def _generated_def_file_test (name , impl , with_action_configs = None , ** kwargs ):
291287 if with_action_configs == None :
@@ -747,6 +743,12 @@ def _test_linkopts_fake_diamond_impl(env, target):
747743 "core" ,
748744 ]).in_order ()
749745
746+ def _input_basenames (link_action ):
747+ return link_action .inputs ().transform (
748+ desc = "input basenames" ,
749+ map_each = lambda f : f .basename ,
750+ )
751+
750752def _is_shared_library (f ):
751753 return f .extension in ["so" , "dylib" , "dll" , "ifso" ] or ".so" in f .basename or ".dylib" in f .basename
752754
@@ -890,9 +892,7 @@ def _test_cc_runtimes_added_to_libraries(name, **kwargs):
890892
891893def _test_cc_runtimes_added_to_libraries_impl (env , target ):
892894 link_action = link_action_subject .from_target (env , target )
893- inputs = [f .basename for f in link_action .actual .inputs .to_list ()]
894-
895- env .expect .that_collection (inputs ).contains_at_least ([
895+ _input_basenames (link_action ).contains_at_least ([
896896 "app.pic.o" ,
897897 "libmiddleware1.a" ,
898898 "libinfrastructure1.a" ,
@@ -916,9 +916,9 @@ def _test_ignore_custom_malloc(name, **kwargs):
916916
917917def _test_ignore_custom_malloc_impl (env , target ):
918918 link_action = link_action_subject .from_target (env , target )
919- inputs = [ f . basename for f in link_action . actual . inputs . to_list ()]
920- env . expect . that_collection ( inputs ) .contains ("libsystem_malloc.a" )
921- env . expect . that_collection ( inputs ) .not_contains ("libmock_malloc.a" )
919+ basenames = _input_basenames ( link_action )
920+ basenames .contains ("libsystem_malloc.a" )
921+ basenames .not_contains ("libmock_malloc.a" )
922922
923923def _test_custom_malloc (name , ** kwargs ):
924924 _create_dep_tree (name , use_actual_cc_binary = True )
@@ -936,9 +936,9 @@ def _test_custom_malloc(name, **kwargs):
936936
937937def _test_custom_malloc_impl (env , target ):
938938 link_action = link_action_subject .from_target (env , target )
939- inputs = [ f . basename for f in link_action . actual . inputs . to_list ()]
940- env . expect . that_collection ( inputs ) .contains ("libmymalloc.a" )
941- env . expect . that_collection ( inputs ) .not_contains ("libmock_malloc.a" )
939+ basenames = _input_basenames ( link_action )
940+ basenames .contains ("libmymalloc.a" )
941+ basenames .not_contains ("libmock_malloc.a" )
942942
943943def _test_app_linking_static (name , ** kwargs ):
944944 _create_dep_tree (name )
@@ -956,18 +956,18 @@ def _test_app_linking_static(name, **kwargs):
956956
957957def _test_app_linking_static_impl (env , target ):
958958 link_action = link_action_subject .from_target (env , target )
959- inputs = [ f . basename for f in link_action . actual . inputs . to_list ()]
959+ basenames = _input_basenames ( link_action )
960960
961961 # Assert inputs
962- env . expect . that_collection ( inputs ) .contains ("app.pic.o" )
963- env . expect . that_collection ( inputs ) .contains ("libmiddleware1.a" )
964- env . expect . that_collection ( inputs ) .contains ("libinfrastructure1.a" )
965- env . expect . that_collection ( inputs ) .contains ("linkstamp.o" )
962+ basenames .contains ("app.pic.o" )
963+ basenames .contains ("libmiddleware1.a" )
964+ basenames .contains ("libinfrastructure1.a" )
965+ basenames .contains ("linkstamp.o" )
966966
967967 # Assert NOT inputs
968- env . expect . that_collection ( inputs ) .not_contains ("libinfrastructure2.a" )
969- env . expect . that_collection ( inputs ) .not_contains ("libmiddleware2.so" )
970- env . expect . that_collection ( inputs ) .not_contains ("libmiddleware3.so.1" )
968+ basenames .not_contains ("libinfrastructure2.a" )
969+ basenames .not_contains ("libmiddleware2.so" )
970+ basenames .not_contains ("libmiddleware3.so.1" )
971971
972972 # Assert linkopts
973973 link_action .argv ().contains_at_least ([
@@ -996,21 +996,21 @@ def _test_app_linking_dynamic(name, **kwargs):
996996
997997def _test_app_linking_dynamic_impl (env , target ):
998998 link_action = link_action_subject .from_target (env , target )
999- inputs = [ f . basename for f in link_action . actual . inputs . to_list ()]
999+ basenames = _input_basenames ( link_action )
10001000
10011001 # Assert inputs
1002- env . expect . that_collection ( inputs ) .contains ("app.pic.o" )
1003- env . expect . that_collection ( inputs ) .contains ("libinfrastructure1.a" )
1004- env . expect . that_collection ( inputs ) .contains ("linkstamp.o" )
1002+ basenames .contains ("app.pic.o" )
1003+ basenames .contains ("libinfrastructure1.a" )
1004+ basenames .contains ("linkstamp.o" )
10051005
10061006 # Assert dynamic library symlink (mangled)
1007- env . expect . that_collection ( inputs ) .contains_predicate (
1007+ basenames .contains_predicate (
10081008 matching .str_endswith ("_Slibmiddleware1.ifso" ),
10091009 )
10101010
10111011 # Assert NOT inputs
1012- env . expect . that_collection ( inputs ) .not_contains ("libmiddleware1.a" )
1013- env . expect . that_collection ( inputs ) .not_contains ("libinfrastructure2.a" )
1012+ basenames .not_contains ("libmiddleware1.a" )
1013+ basenames .not_contains ("libinfrastructure2.a" )
10141014
10151015 # Assert linkopts
10161016 link_action .argv ().contains_at_least ([
@@ -1082,10 +1082,7 @@ def _test_transitive_libs_are_collected(name, **kwargs):
10821082
10831083def _test_transitive_libs_are_collected_impl (env , target ):
10841084 link_action = link_action_subject .from_target (env , target )
1085- input_basenames = link_action .inputs ().transform (
1086- desc = "input basenames" ,
1087- map_each = lambda f : f .basename ,
1088- )
1085+ input_basenames = _input_basenames (link_action )
10891086
10901087 input_basenames .contains_at_least ([
10911088 "foo.pic.o" ,
@@ -1105,10 +1102,7 @@ def _test_transitive_linkstamps_are_collected(name, **kwargs):
11051102
11061103def _test_transitive_linkstamps_are_collected_impl (env , target ):
11071104 link_action = link_action_subject .from_target (env , target )
1108- input_basenames = link_action .inputs ().transform (
1109- desc = "input basenames" ,
1110- map_each = lambda f : f .basename ,
1111- )
1105+ input_basenames = _input_basenames (link_action )
11121106
11131107 input_basenames .contains ("linkstamp.o" )
11141108 input_basenames .not_contains ("linkstamp.cc" )
@@ -1191,10 +1185,7 @@ def _test_additional_linker_inputs_impl(env, target):
11911185 lambda arg : arg .startswith ("--option=" ) and arg .endswith ("main.extra_file" ),
11921186 ),
11931187 )
1194- input_basenames = link_action .inputs ().transform (
1195- desc = "input basenames" ,
1196- map_each = lambda f : f .basename ,
1197- )
1188+ input_basenames = _input_basenames (link_action )
11981189 input_basenames .contains ("main.extra_file" )
11991190
12001191# Regression test for b/193125967
@@ -1312,9 +1303,9 @@ def _test_pic_mode_prefers_pic_libs_force_pic_disabled(name, **kwargs):
13121303
13131304def _test_pic_mode_prefers_pic_libs_force_pic_disabled_impl (env , target ):
13141305 link_action = link_action_subject .from_target (env , target )
1315- inputs = [ f . basename for f in link_action . actual . inputs . to_list ()]
1316- env . expect . that_collection ( inputs ) .contains ("dep.nopic.a" )
1317- env . expect . that_collection ( inputs ) .not_contains ("dep.pic.a" )
1306+ basenames = _input_basenames ( link_action )
1307+ basenames .contains ("dep.nopic.a" )
1308+ basenames .not_contains ("dep.pic.a" )
13181309
13191310def _test_pic_mode_prefers_pic_libs_force_pic_enabled (name , ** kwargs ):
13201311 _create_prefers_pic_libs_dep_tree (name )
@@ -1331,9 +1322,9 @@ def _test_pic_mode_prefers_pic_libs_force_pic_enabled(name, **kwargs):
13311322
13321323def _test_pic_mode_prefers_pic_libs_force_pic_enabled_impl (env , target ):
13331324 link_action = link_action_subject .from_target (env , target )
1334- inputs = [ f . basename for f in link_action . actual . inputs . to_list ()]
1335- env . expect . that_collection ( inputs ) .contains ("dep.pic.a" )
1336- env . expect . that_collection ( inputs ) .not_contains ("dep.nopic.a" )
1325+ basenames = _input_basenames ( link_action )
1326+ basenames .contains ("dep.pic.a" )
1327+ basenames .not_contains ("dep.nopic.a" )
13371328
13381329def _test_pic_mode_uses_pic_libs (name , ** kwargs ):
13391330 util .helper_target (
@@ -1363,8 +1354,7 @@ def _test_pic_mode_uses_pic_libs(name, **kwargs):
13631354
13641355def _test_pic_mode_uses_pic_libs_impl (env , target ):
13651356 link_action = link_action_subject .from_target (env , target )
1366- inputs = [f .basename for f in link_action .actual .inputs .to_list ()]
1367- env .expect .that_collection (inputs ).contains ("dep.pic.o" )
1357+ _input_basenames (link_action ).contains ("dep.pic.o" )
13681358
13691359def _create_does_not_use_nopic_library_dep_tree (name ):
13701360 util .helper_target (
@@ -1394,9 +1384,9 @@ def _test_pic_mode_does_not_use_nopic_library_force_pic_disabled(name, **kwargs)
13941384
13951385def _test_pic_mode_does_not_use_nopic_library_force_pic_disabled_impl (env , target ):
13961386 link_action = link_action_subject .from_target (env , target )
1397- inputs = [ f . basename for f in link_action . actual . inputs . to_list ()]
1398- env . expect . that_collection ( inputs ) .contains ("mybinary.pic.o" )
1399- env . expect . that_collection ( inputs ) .not_contains ("dep.nopic.o" )
1387+ basenames = _input_basenames ( link_action )
1388+ basenames .contains ("mybinary.pic.o" )
1389+ basenames .not_contains ("dep.nopic.o" )
14001390
14011391def _test_pic_mode_does_not_use_nopic_library_force_pic_enabled (name , ** kwargs ):
14021392 _create_does_not_use_nopic_library_dep_tree (name )
@@ -1413,8 +1403,7 @@ def _test_pic_mode_does_not_use_nopic_library_force_pic_enabled(name, **kwargs):
14131403
14141404def _test_pic_mode_does_not_use_nopic_library_force_pic_enabled_impl (env , target ):
14151405 link_action = link_action_subject .from_target (env , target )
1416- inputs = [f .basename for f in link_action .actual .inputs .to_list ()]
1417- env .expect .that_collection (inputs ).not_contains ("dep.nopic.o" )
1406+ _input_basenames (link_action ).not_contains ("dep.nopic.o" )
14181407
14191408def _test_pic_mode_does_not_use_nopic_binary (name , ** kwargs ):
14201409 util .helper_target (
@@ -1432,8 +1421,7 @@ def _test_pic_mode_does_not_use_nopic_binary(name, **kwargs):
14321421
14331422def _test_pic_mode_does_not_use_nopic_binary_impl (env , target ):
14341423 link_action = link_action_subject .from_target (env , target )
1435- inputs = [f .basename for f in link_action .actual .inputs .to_list ()]
1436- env .expect .that_collection (inputs ).not_contains ("xyz.nopic.o" )
1424+ _input_basenames (link_action ).not_contains ("xyz.nopic.o" )
14371425
14381426def _setup_cc_runtimes_mock ():
14391427 util .helper_target (
0 commit comments