1- load ("@rules_cc//cc:defs.bzl" , "cc_binary" )
1+ load ("@rules_cc//cc:defs.bzl" , "cc_binary" , "cc_library" )
22load ("@rules_java//java:defs.bzl" , "JavaInfo" )
33load ("@rules_testing//lib:analysis_test.bzl" , "analysis_test" )
44load ("@rules_testing//lib:test_suite.bzl" , "test_suite" )
@@ -28,6 +28,16 @@ def _native_library_basenames(java_info):
2828 return basenames
2929
3030def _native_library_target (name , suffix ):
31+ # Analysis tests only need CcInfo propagation, and cc_library matches the
32+ # rules_java fixture shape more reliably across platforms than linkshared binaries.
33+ util .helper_target (
34+ cc_library ,
35+ name = name + "/" + suffix ,
36+ srcs = [util .empty_file (name + "_" + suffix + ".cc" )],
37+ )
38+ return name + "/" + suffix
39+
40+ def _native_shared_library_target (name , suffix ):
3141 util .helper_target (
3242 cc_binary ,
3343 name = name + "/" + suffix ,
@@ -106,6 +116,24 @@ def _with_native_libraries_test(name):
106116def _with_native_libraries_test_impl (env , target ):
107117 _assert_native_library_basenames (env , target , ["*native_direct*" ])
108118
119+ def _with_native_libraries_in_deps_test (name ):
120+ native_target = _native_library_target (name , "native_direct" )
121+ util .helper_target (
122+ kt_jvm_library ,
123+ name = name + "/subject" ,
124+ srcs = [util .empty_file (name + "_Direct.kt" )],
125+ deps = [native_target ],
126+ )
127+
128+ analysis_test (
129+ name = name ,
130+ impl = _with_native_libraries_in_deps_test_impl ,
131+ target = name + "/subject" ,
132+ )
133+
134+ def _with_native_libraries_in_deps_test_impl (env , target ):
135+ _assert_native_library_basenames (env , target , ["*native_direct*" ])
136+
109137def _transitive_native_libraries_test (name ):
110138 native_c = _native_library_target (name , "native_c" )
111139 util .helper_target (
@@ -196,7 +224,7 @@ def _native_libraries_propagation_test_impl(env, target):
196224 ])
197225
198226def _kt_jvm_binary_propagates_direct_native_libraries_test (name ):
199- native_target = _native_library_target (name , "native" )
227+ native_target = _native_shared_library_target (name , "native" )
200228 util .helper_target (
201229 kt_jvm_binary ,
202230 name = name + "/binary" ,
@@ -216,7 +244,7 @@ def _kt_jvm_binary_propagates_direct_native_libraries_test_impl(env, target):
216244 _assert_has_native_library_path_flag (env , target )
217245
218246def _kt_jvm_test_propagates_direct_native_libraries_test (name ):
219- native_target = _native_library_target (name , "native" )
247+ native_target = _native_shared_library_target (name , "native" )
220248 util .helper_target (
221249 kt_jvm_test ,
222250 name = name + "/binary" ,
@@ -240,6 +268,7 @@ def native_libraries_test_suite(name):
240268 name = name ,
241269 tests = [
242270 _with_native_libraries_test ,
271+ _with_native_libraries_in_deps_test ,
243272 _transitive_native_libraries_test ,
244273 _native_libraries_propagation_test ,
245274 _kt_jvm_binary_propagates_direct_native_libraries_test ,
0 commit comments