@@ -267,6 +267,7 @@ def _filter_inputs(
267
267
unaccounted_for_libs = []
268
268
exports = {}
269
269
owners_seen = {}
270
+ linked_statically_but_not_exported = {}
270
271
for linker_input in dependency_linker_inputs :
271
272
owner = str (linker_input .owner )
272
273
if owner in owners_seen :
@@ -277,8 +278,7 @@ def _filter_inputs(
277
278
linker_inputs .append (dynamic_linker_input )
278
279
elif owner in link_statically_labels :
279
280
if owner in link_once_static_libs_map :
280
- fail (owner + " is already linked statically in " +
281
- link_once_static_libs_map [owner ] + " but not exported" )
281
+ linked_statically_but_not_exported .setdefault (link_once_static_libs_map [owner ], []).append (owner )
282
282
283
283
is_direct_export = owner in direct_exports
284
284
@@ -337,9 +337,27 @@ def _filter_inputs(
337
337
else :
338
338
unaccounted_for_libs .append (linker_input .owner )
339
339
340
+ _throw_linked_but_not_exported_errors (linked_statically_but_not_exported )
340
341
_throw_error_if_unaccounted_libs (unaccounted_for_libs )
341
342
return (exports , linker_inputs , link_once_static_libs , precompiled_only_dynamic_libraries )
342
343
344
+ def _throw_linked_but_not_exported_errors (error_libs_dict ):
345
+ if not error_libs_dict :
346
+ return
347
+
348
+ error_builder = ["The following libraries were linked statically by different cc_shared_libraries but not exported:\n " ]
349
+ for cc_shared_library_target , error_libs in error_libs_dict .items ():
350
+ error_builder .append ("cc_shared_library %s:\n " % str (cc_shared_library_target ))
351
+ for error_lib in error_libs :
352
+ error_builder .append (" \" %s\" ,\n " % str (error_lib ))
353
+
354
+ error_builder .append ("If you are sure that the previous libraries are exported by the cc_shared_libraries because:\n " )
355
+ error_builder .append (" 1. You have visibility declarations in the source code\n " )
356
+ error_builder .append (" 2. Or you are passing a visibility script to the linker to export symbols from them\n " )
357
+ error_builder .append ("then add those libraries to roots or exports_filter for each cc_shared_library.\n " )
358
+
359
+ fail ("" .join (error_builder ))
360
+
343
361
def _throw_error_if_unaccounted_libs (unaccounted_for_libs ):
344
362
if not unaccounted_for_libs :
345
363
return
0 commit comments