• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2022 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
16load("//build/bazel/rules/cc:cc_library_shared.bzl", "cc_library_shared")
17load("//build/bazel/rules/cc:cc_library_static.bzl", "cc_library_static")
18load("//build/bazel/rules/cc:cc_stub_library.bzl", "cc_stub_suite")
19load(
20    "//build/bazel/rules/cc/testing:transitions.bzl",
21    "ActionArgsInfo",
22    "compile_action_argv_aspect_generator",
23)
24load("//build/bazel/rules/test_common:flags.bzl", "action_flags_present_only_for_mnemonic_test")
25load("//build/bazel/rules/test_common:paths.bzl", "get_package_dir_based_path")
26load(":cc_library_common_test.bzl", "target_provides_androidmk_info_test")
27
28def _cc_library_shared_suffix_test_impl(ctx):
29    env = analysistest.begin(ctx)
30    target = analysistest.target_under_test(env)
31    info = target[DefaultInfo]
32    suffix = ctx.attr.suffix
33
34    # NB: There may be more than 1 output file (if e.g. including a TOC)
35    outputs = [so.path for so in info.files.to_list() if so.path.endswith(".so")]
36    asserts.true(
37        env,
38        len(outputs) == 1,
39        "Expected only 1 output file; got %s" % outputs,
40    )
41    out = outputs[0]
42    suffix_ = suffix + ".so"
43    asserts.true(
44        env,
45        out.endswith(suffix_),
46        "Expected output filename to end in `%s`; it was instead %s" % (suffix_, out),
47    )
48
49    return analysistest.end(env)
50
51cc_library_shared_suffix_test = analysistest.make(
52    _cc_library_shared_suffix_test_impl,
53    attrs = {"suffix": attr.string()},
54)
55
56def _cc_library_shared_suffix():
57    name = "cc_library_shared_suffix"
58    test_name = name + "_test"
59    suffix = "-suf"
60
61    cc_library_shared(
62        name,
63        srcs = ["foo.cc"],
64        tags = ["manual"],
65        suffix = suffix,
66    )
67    cc_library_shared_suffix_test(
68        name = test_name,
69        target_under_test = name,
70        suffix = suffix,
71    )
72    return test_name
73
74def _cc_library_shared_empty_suffix():
75    name = "cc_library_shared_empty_suffix"
76    test_name = name + "_test"
77
78    cc_library_shared(
79        name,
80        srcs = ["foo.cc"],
81        tags = ["manual"],
82    )
83    cc_library_shared_suffix_test(
84        name = test_name,
85        target_under_test = name,
86    )
87    return test_name
88
89def _cc_library_shared_propagating_compilation_context_test_impl(ctx):
90    env = analysistest.begin(ctx)
91    target = analysistest.target_under_test(env)
92    cc_info = target[CcInfo]
93    compilation_context = cc_info.compilation_context
94
95    header_paths = [f.path for f in compilation_context.headers.to_list()]
96    for hdr in ctx.files.expected_hdrs:
97        asserts.true(
98            env,
99            hdr.path in header_paths,
100            "Did not find {hdr} in includes: {hdrs}.".format(hdr = hdr, hdrs = compilation_context.headers),
101        )
102
103    for hdr in ctx.files.expected_absent_hdrs:
104        asserts.true(
105            env,
106            hdr not in header_paths,
107            "Found {hdr} in includes: {hdrs}, should not be present.".format(hdr = hdr, hdrs = compilation_context.headers),
108        )
109
110    for include in ctx.attr.expected_includes:
111        absolute_include = get_package_dir_based_path(env, include)
112        asserts.true(
113            env,
114            absolute_include in compilation_context.includes.to_list(),
115            "Did not find {include} in includes: {includes}.".format(include = include, includes = compilation_context.includes),
116        )
117
118    for include in ctx.attr.expected_absent_includes:
119        absolute_include = get_package_dir_based_path(env, include)
120        asserts.true(
121            env,
122            absolute_include not in compilation_context.includes.to_list(),
123            "Found {include} in includes: {includes}, was expected to be absent".format(include = include, includes = compilation_context.includes),
124        )
125
126    for include in ctx.attr.expected_system_includes:
127        absolute_include = get_package_dir_based_path(env, include)
128        asserts.true(
129            env,
130            absolute_include in compilation_context.system_includes.to_list(),
131            "Did not find {include} in system includes: {includes}.".format(include = include, includes = compilation_context.system_includes),
132        )
133
134    for include in ctx.attr.expected_absent_system_includes:
135        absolute_include = get_package_dir_based_path(env, include)
136        asserts.true(
137            env,
138            absolute_include not in compilation_context.system_includes.to_list(),
139            "Found {include} in system includes: {includes}, was expected to be absent".format(include = include, includes = compilation_context.system_includes),
140        )
141
142    return analysistest.end(env)
143
144_cc_library_shared_propagating_compilation_context_test = analysistest.make(
145    _cc_library_shared_propagating_compilation_context_test_impl,
146    attrs = {
147        "expected_hdrs": attr.label_list(),
148        "expected_absent_hdrs": attr.label_list(),
149        "expected_includes": attr.string_list(),
150        "expected_absent_includes": attr.string_list(),
151        "expected_system_includes": attr.string_list(),
152        "expected_absent_system_includes": attr.string_list(),
153    },
154)
155
156def _cc_library_shared_propagates_deps():
157    name = "_cc_library_shared_propagates_deps"
158    dep_name = name + "_dep"
159    test_name = name + "_test"
160
161    cc_library_static(
162        name = dep_name,
163        hdrs = [":cc_library_shared_hdr"],
164        export_includes = ["a/b/c"],
165        export_system_includes = ["d/e/f"],
166        tags = ["manual"],
167    )
168
169    cc_library_shared(
170        name = name,
171        deps = [dep_name],
172        tags = ["manual"],
173    )
174
175    _cc_library_shared_propagating_compilation_context_test(
176        name = test_name,
177        target_under_test = name,
178        expected_hdrs = [":cc_library_shared_hdr"],
179        expected_includes = ["a/b/c"],
180        expected_system_includes = ["d/e/f"],
181    )
182
183    return test_name
184
185def _cc_library_shared_propagates_whole_archive_deps():
186    name = "_cc_library_shared_propagates_whole_archive_deps"
187    dep_name = name + "_dep"
188    test_name = name + "_test"
189
190    cc_library_static(
191        name = dep_name,
192        hdrs = [":cc_library_shared_hdr"],
193        export_includes = ["a/b/c"],
194        export_system_includes = ["d/e/f"],
195        tags = ["manual"],
196    )
197
198    cc_library_shared(
199        name = name,
200        whole_archive_deps = [dep_name],
201        tags = ["manual"],
202    )
203
204    _cc_library_shared_propagating_compilation_context_test(
205        name = test_name,
206        target_under_test = name,
207        expected_hdrs = [":cc_library_shared_hdr"],
208        expected_includes = ["a/b/c"],
209        expected_system_includes = ["d/e/f"],
210    )
211
212    return test_name
213
214def _cc_library_shared_propagates_dynamic_deps():
215    name = "_cc_library_shared_propagates_dynamic_deps"
216    dep_name = name + "_dep"
217    test_name = name + "_test"
218
219    cc_library_shared(
220        name = dep_name,
221        hdrs = [":cc_library_shared_hdr"],
222        export_includes = ["a/b/c"],
223        export_system_includes = ["d/e/f"],
224        tags = ["manual"],
225    )
226
227    cc_library_shared(
228        name = name,
229        dynamic_deps = [dep_name],
230        tags = ["manual"],
231    )
232
233    _cc_library_shared_propagating_compilation_context_test(
234        name = test_name,
235        target_under_test = name,
236        expected_hdrs = [":cc_library_shared_hdr"],
237        expected_includes = ["a/b/c"],
238        expected_system_includes = ["d/e/f"],
239    )
240
241    return test_name
242
243def _cc_library_shared_does_not_propagate_implementation_deps():
244    name = "_cc_library_shared_does_not_propagate_implementation_deps"
245    dep_name = name + "_dep"
246    test_name = name + "_test"
247
248    cc_library_static(
249        name = dep_name,
250        hdrs = [":cc_library_shared_hdr"],
251        export_includes = ["a/b/c"],
252        export_system_includes = ["d/e/f"],
253        tags = ["manual"],
254    )
255
256    cc_library_shared(
257        name = name,
258        implementation_deps = [dep_name],
259        tags = ["manual"],
260    )
261
262    _cc_library_shared_propagating_compilation_context_test(
263        name = test_name,
264        target_under_test = name,
265        expected_absent_hdrs = [":cc_library_shared_hdr"],
266        expected_absent_includes = ["a/b/c"],
267        expected_absent_system_includes = ["d/e/f"],
268    )
269
270    return test_name
271
272def _cc_library_shared_does_not_propagate_implementation_whole_archive_deps():
273    name = "_cc_library_shared_does_not_propagate_implementation_whole_archive_deps"
274    dep_name = name + "_dep"
275    test_name = name + "_test"
276
277    cc_library_static(
278        name = dep_name,
279        hdrs = [":cc_library_shared_hdr"],
280        export_includes = ["a/b/c"],
281        export_system_includes = ["d/e/f"],
282        tags = ["manual"],
283    )
284
285    cc_library_shared(
286        name = name,
287        implementation_whole_archive_deps = [dep_name],
288        tags = ["manual"],
289    )
290
291    _cc_library_shared_propagating_compilation_context_test(
292        name = test_name,
293        target_under_test = name,
294        expected_absent_hdrs = [":cc_library_shared_hdr"],
295        expected_absent_includes = ["a/b/c"],
296        expected_absent_system_includes = ["d/e/f"],
297    )
298
299    return test_name
300
301def _cc_library_shared_does_not_propagate_implementation_dynamic_deps():
302    name = "_cc_library_shared_does_not_propagate_implementation_dynamic_deps"
303    dep_name = name + "_dep"
304    test_name = name + "_test"
305
306    cc_library_shared(
307        name = dep_name,
308        hdrs = [":cc_library_shared_hdr"],
309        export_includes = ["a/b/c"],
310        export_system_includes = ["d/e/f"],
311        tags = ["manual"],
312    )
313
314    cc_library_shared(
315        name = name,
316        implementation_dynamic_deps = [dep_name],
317        tags = ["manual"],
318    )
319
320    _cc_library_shared_propagating_compilation_context_test(
321        name = test_name,
322        target_under_test = name,
323        expected_absent_hdrs = [":cc_library_shared_hdr"],
324        expected_absent_includes = ["a/b/c"],
325        expected_absent_system_includes = ["d/e/f"],
326    )
327
328    return test_name
329
330def _cc_library_shared_propagating_fdo_profile_test_impl(ctx):
331    env = analysistest.begin(ctx)
332    target_under_test = analysistest.target_under_test(env)
333    argv_map = target_under_test[ActionArgsInfo].argv_map
334    for label in ctx.attr.deps_labels_to_check_fdo_profile:
335        asserts.true(
336            env,
337            label in argv_map,
338            "can't find {} in argv map".format(label),
339        )
340        argv = argv_map[label]
341        asserts.true(
342            env,
343            _has_fdo_profile(argv, ctx.attr.fdo_profile_path_basename),
344            "can't find {} in compile action of {}".format(
345                ctx.attr.fdo_profile_path_basename,
346                label,
347            ),
348        )
349    for label in ctx.attr.deps_labels_to_check_no_fdo_profile:
350        asserts.true(
351            env,
352            label in argv_map,
353            "can't find {} in argv_map".format(label),
354        )
355        argv = argv_map[label]
356        asserts.true(
357            env,
358            not _has_fdo_profile(argv, ctx.attr.fdo_profile_path_basename),
359            "{} should not have {} in compile action".format(
360                ctx.attr.fdo_profile_path_basename,
361                label,
362            ),
363        )
364
365    return analysistest.end(env)
366
367_compile_action_argv_aspect = compile_action_argv_aspect_generator({
368    "_cc_library_combiner": ["deps", "roots", "includes"],
369    "_cc_includes": ["deps"],
370    "_cc_library_shared_proxy": ["deps"],
371})
372
373cc_library_shared_propagating_fdo_profile_test = analysistest.make(
374    _cc_library_shared_propagating_fdo_profile_test_impl,
375    attrs = {
376        # FdoProfileInfo isn't exposed to Starlark so we need to test against
377        # the path basename directly
378        "fdo_profile_path_basename": attr.string(),
379        # This has to be a string_list() instead of label_list(). If the deps
380        # are given as labels, the deps are analyzed because transition is attached
381        "deps_labels_to_check_fdo_profile": attr.string_list(),
382        "deps_labels_to_check_no_fdo_profile": attr.string_list(),
383    },
384    # We need to use aspect to examine the dependencies' actions of the apex
385    # target as the result of the transition, checking the dependencies directly
386    # using names will give you the info before the transition takes effect.
387    extra_target_under_test_aspects = [_compile_action_argv_aspect],
388)
389
390# _has_fdo_profile checks whether afdo-specific flag is present in actions.argv
391def _has_fdo_profile(argv, fdo_profile_path_basename):
392    for arg in argv:
393        if fdo_profile_path_basename in arg and "-fprofile-sample-use" in arg:
394            return True
395
396    return False
397
398def _cc_libary_shared_propagate_fdo_profile_to_whole_archive_deps():
399    name = "_cc_libary_shared_propagate_fdo_profile_to_whole_archive_deps"
400    fdo_profile_name = name + "_fdo_profile"
401    dep_name = name + "_dep"
402    transitive_dep_name = name + "_transitive_dep"
403    unexported_dep_name = name + "_exported_dep"
404    transitive_unexported_dep_name = name + "_transitive_unexported_dep"
405    test_name = name + "_test"
406
407    native.fdo_profile(
408        name = fdo_profile_name,
409        profile = fdo_profile_name + ".afdo",
410    )
411
412    cc_library_static(
413        name = transitive_dep_name,
414        srcs = ["foo.cpp"],
415        tags = ["manual"],
416    )
417    cc_library_static(
418        name = transitive_unexported_dep_name,
419        srcs = ["foo.cpp"],
420        tags = ["manual"],
421    )
422    cc_library_static(
423        name = dep_name,
424        whole_archive_deps = [transitive_dep_name],
425        implementation_whole_archive_deps = [transitive_unexported_dep_name],
426        srcs = ["foo.cpp", "bar.cpp"],
427        tags = ["manual"],
428    )
429    cc_library_static(
430        name = unexported_dep_name,
431        srcs = ["foo.cpp"],
432        tags = ["manual"],
433    )
434
435    cc_library_shared(
436        name = name,
437        whole_archive_deps = [dep_name],
438        implementation_whole_archive_deps = [unexported_dep_name],
439        fdo_profile = ":" + fdo_profile_name,
440        tags = ["manual"],
441    )
442
443    cc_library_shared_propagating_fdo_profile_test(
444        name = test_name,
445        target_under_test = name,
446        deps_labels_to_check_fdo_profile = [
447            dep_name + "_cpp",
448            transitive_dep_name + "_cpp",
449            unexported_dep_name + "_cpp",
450            transitive_unexported_dep_name + "_cpp",
451        ],
452        fdo_profile_path_basename = fdo_profile_name + ".afdo",
453    )
454
455    return test_name
456
457def _cc_library_shared_does_not_propagate_fdo_profile_to_dynamic_deps():
458    name = "_cc_library_shared_does_not_propagate_fdo_profile_to_dynamic_deps"
459    fdo_profile_name = name + "_fdo_profile"
460    dep_name = name + "_dep"
461    transitive_shared_dep_name = name + "_transitive_shared_dep"
462    unexported_transitive_shared_dep_name = name + "_unexported_transitive_shared_dep"
463    test_name = name + "_test"
464
465    cc_library_shared(
466        name = transitive_shared_dep_name,
467        srcs = ["foo.cpp"],
468        tags = ["manual"],
469    )
470    cc_library_shared(
471        name = unexported_transitive_shared_dep_name,
472        srcs = ["foo.cpp"],
473        tags = ["manual"],
474    )
475    cc_library_static(
476        name = dep_name,
477        srcs = ["foo.cpp"],
478        dynamic_deps = [transitive_shared_dep_name],
479        implementation_dynamic_deps = [unexported_transitive_shared_dep_name],
480        tags = ["manual"],
481    )
482    native.fdo_profile(
483        name = fdo_profile_name,
484        profile = fdo_profile_name + ".afdo",
485    )
486    cc_library_shared(
487        name = name,
488        whole_archive_deps = [dep_name],
489        fdo_profile = fdo_profile_name,
490        stl = "",
491        tags = ["manual"],
492    )
493
494    cc_library_shared_propagating_fdo_profile_test(
495        name = test_name,
496        target_under_test = name,
497        deps_labels_to_check_fdo_profile = [
498            dep_name + "_cpp",
499        ],
500        # make sure dynamic deps don't build with afdo profiles from rdeps
501        deps_labels_to_check_no_fdo_profile = [
502            transitive_shared_dep_name + "__internal_root_cpp",
503            unexported_transitive_shared_dep_name + "__internal_root_cpp",
504        ],
505        fdo_profile_path_basename = fdo_profile_name + ".afdo",
506    )
507
508    return test_name
509
510def _fdo_profile_transition_correctly_set_and_unset_fdo_profile():
511    name = "_fdo_profile_transition_set_and_unset_fdo_profile_correctly"
512    fdo_profile_name = name + "_fdo_profile"
513    dep_with_fdo_profile = name + "_dep_with_fdo_profile"
514    transitive_dep_without_fdo_profile = name + "_transitive_dep_without_fdo_profile"
515    test_name = name + "_test"
516
517    native.fdo_profile(
518        name = fdo_profile_name,
519        profile = fdo_profile_name + ".afdo",
520    )
521
522    cc_library_shared(
523        name = name,
524        srcs = ["foo.cpp"],
525        tags = ["manual"],
526        dynamic_deps = [dep_with_fdo_profile],
527    )
528
529    cc_library_shared(
530        name = dep_with_fdo_profile,
531        fdo_profile = fdo_profile_name,
532        srcs = ["foo.cpp"],
533        tags = ["manual"],
534        dynamic_deps = [transitive_dep_without_fdo_profile],
535    )
536
537    cc_library_shared(
538        name = transitive_dep_without_fdo_profile,
539        srcs = ["foo.cpp"],
540        tags = ["manual"],
541    )
542
543    cc_library_shared_propagating_fdo_profile_test(
544        name = test_name,
545        target_under_test = name,
546        deps_labels_to_check_fdo_profile = [
547            dep_with_fdo_profile + "__internal_root_cpp",
548        ],
549        # make sure dynamic deps don't build with afdo profiles from rdeps
550        deps_labels_to_check_no_fdo_profile = [
551            name + "__internal_root_cpp",
552            transitive_dep_without_fdo_profile + "__internal_root_cpp",
553        ],
554        fdo_profile_path_basename = fdo_profile_name + ".afdo",
555    )
556
557    return test_name
558
559def _cc_library_link_flags_test_impl(ctx):
560    env = analysistest.begin(ctx)
561    target = analysistest.target_under_test(env)
562
563    for action in target.actions:
564        if action.mnemonic == "CppLink":
565            for flag in ctx.attr.expected_link_flags:
566                if flag not in action.argv:
567                    fail("{} is not in list of flags for linking {}".format(flag, action.argv))
568
569    return analysistest.end(env)
570
571cc_library_link_flags_test = analysistest.make(
572    _cc_library_link_flags_test_impl,
573    attrs = {
574        "expected_link_flags": attr.string_list(),
575    },
576)
577
578def _cc_library_with_fdo_profile_link_flags():
579    name = "_cc_library_with_fdo_profile_link_flags"
580    test_name = name + "_test"
581    cc_library_shared(
582        name = name,
583        fdo_profile = name + "_fdo_profile",
584        tags = ["manual"],
585    )
586    cc_library_link_flags_test(
587        name = test_name,
588        target_under_test = name + "_unstripped",
589        expected_link_flags = [
590            "-funique-internal-linkage-names",
591            "-fprofile-sample-accurate",
592            "-fprofile-sample-use=build/bazel/rules/cc/_cc_library_with_fdo_profile_link_flags_fdo_profile.afdo",
593            "-Wl,-mllvm,-no-warn-sample-unused=true",
594        ],
595    )
596    return test_name
597
598def _cc_library_disable_fdo_optimization_if_coverage_is_enabled_impl(ctx):
599    env = analysistest.begin(ctx)
600    target = analysistest.target_under_test(env)
601
602    for action in target.actions:
603        if action.mnemonic == "CppCompile":
604            for arg in action.argv:
605                if "-fprofile-sample-use" in arg:
606                    fail("fdo optimization can not be enabled when coverage is enabled")
607
608    return analysistest.end(env)
609
610cc_library_disable_fdo_optimization_if_coverage_is_enabled_test = analysistest.make(
611    _cc_library_disable_fdo_optimization_if_coverage_is_enabled_impl,
612    config_settings = {
613        "//command_line_option:collect_code_coverage": True,
614    },
615)
616
617def _cc_library_disable_fdo_optimization_if_coverage_is_enabled_test():
618    name = "_cc_library_disable_fdo_optimization_if_coverage_is_enabled_test"
619    test_name = name + "_test"
620    cc_library_shared(
621        name = name,
622        fdo_profile = name + "_fdo_profile",
623        srcs = ["foo.cpp"],
624        # Coverage will add an extra lib to all the shared libs, we try to avoid
625        # that by clearing the system_dynamic_deps and stl.
626        system_dynamic_deps = [],
627        stl = "none",
628        tags = ["manual"],
629    )
630    cc_library_disable_fdo_optimization_if_coverage_is_enabled_test(
631        name = test_name,
632        target_under_test = name + "__internal_root_cpp",
633    )
634    return test_name
635
636def _cc_library_set_defines_for_stubs():
637    name = "cc_library_set_defines_for_stubs"
638    test_name = name + "_test"
639
640    cc_library_shared(
641        name = name + "_libfoo",
642        system_dynamic_deps = [],
643        stl = "none",
644        tags = ["manual"],
645        stubs_symbol_file = name + "_libfoo.map.txt",
646    )
647
648    cc_stub_suite(
649        name = name + "_libfoo_stub_libs",
650        soname = name + "_libfoo.so",
651        source_library_label = ":" + name + "_libfoo",
652        symbol_file = name + "_libfoo.map.txt",
653        versions = ["30", "40"],
654    )
655
656    cc_library_shared(
657        name = name + "_libbar",
658        system_dynamic_deps = [],
659        stl = "none",
660        tags = ["manual"],
661        stubs_symbol_file = name + "_libbar.map.txt",
662    )
663
664    cc_stub_suite(
665        name = name + "_libbar_stub_libs",
666        soname = name + "_libbar.so",
667        source_library_label = ":" + name + "_libbar",
668        symbol_file = name + "_libbar.map.txt",
669        versions = ["current"],
670    )
671
672    cc_library_shared(
673        name = name + "_libbaz",
674        system_dynamic_deps = [],
675        stl = "none",
676        tags = ["manual"],
677        stubs_symbol_file = name + "_libbaz.map.txt",
678    )
679
680    cc_stub_suite(
681        name = name + "_libbaz_stub_libs",
682        soname = name + "_libbaz.so",
683        source_library_label = ":" + name + "_libbaz",
684        symbol_file = name + "_libbaz.map.txt",
685        versions = ["30"],
686    )
687
688    cc_library_shared(
689        name = name + "_lib_with_stub_deps",
690        srcs = ["foo.cpp"],
691        implementation_dynamic_deps = [
692            name + "_libfoo_stub_libs_current",
693            name + "_libbar_stub_libs_current",
694            name + "_libbaz_stub_libs-30",  # depend on an old version explicitly
695        ],
696        tags = ["manual"],
697    )
698
699    action_flags_present_only_for_mnemonic_test(
700        name = test_name,
701        target_under_test = name + "_lib_with_stub_deps__internal_root_cpp",
702        mnemonics = ["CppCompile"],
703        expected_flags = [
704            "-D__CC_LIBRARY_SET_DEFINES_FOR_STUBS_LIBFOO_API__=10000",
705            "-D__CC_LIBRARY_SET_DEFINES_FOR_STUBS_LIBBAR_API__=10000",
706            "-D__CC_LIBRARY_SET_DEFINES_FOR_STUBS_LIBBAZ_API__=30",
707        ],
708    )
709    return test_name
710
711def _cc_library_shared_provides_androidmk_info():
712    name = "cc_library_shared_provides_androidmk_info"
713    dep_name = name + "_static_dep"
714    whole_archive_dep_name = name + "_whole_archive_dep"
715    dynamic_dep_name = name + "_dynamic_dep"
716    test_name = name + "_test"
717
718    cc_library_static(
719        name = dep_name,
720        srcs = ["foo.c"],
721        tags = ["manual"],
722    )
723    cc_library_static(
724        name = whole_archive_dep_name,
725        srcs = ["foo.c"],
726        tags = ["manual"],
727    )
728    cc_library_shared(
729        name = dynamic_dep_name,
730        srcs = ["foo.c"],
731        tags = ["manual"],
732    )
733    cc_library_shared(
734        name = name,
735        srcs = ["foo.cc"],
736        deps = [dep_name],
737        whole_archive_deps = [whole_archive_dep_name],
738        dynamic_deps = [dynamic_dep_name],
739        tags = ["manual"],
740    )
741    android_test_name = test_name + "_android"
742    linux_test_name = test_name + "_linux"
743    target_provides_androidmk_info_test(
744        name = android_test_name,
745        target_under_test = name,
746        expected_static_libs = [dep_name, "libc++demangle"],
747        expected_whole_static_libs = [whole_archive_dep_name],
748        expected_shared_libs = [dynamic_dep_name, "libc++", "libc", "libdl", "libm"],
749        target_compatible_with = ["//build/bazel/platforms/os:android"],
750    )
751    target_provides_androidmk_info_test(
752        name = linux_test_name,
753        target_under_test = name,
754        expected_static_libs = [dep_name],
755        expected_whole_static_libs = [whole_archive_dep_name],
756        expected_shared_libs = [dynamic_dep_name, "libc++"],
757        target_compatible_with = ["//build/bazel/platforms/os:linux"],
758    )
759    return [
760        android_test_name,
761        linux_test_name,
762    ]
763
764def cc_library_shared_test_suite(name):
765    native.genrule(name = "cc_library_shared_hdr", cmd = "null", outs = ["cc_shared_f.h"], tags = ["manual"])
766
767    native.test_suite(
768        name = name,
769        tests = [
770            _cc_library_shared_suffix(),
771            _cc_library_shared_empty_suffix(),
772            _cc_library_shared_propagates_deps(),
773            _cc_library_shared_propagates_whole_archive_deps(),
774            _cc_library_shared_propagates_dynamic_deps(),
775            _cc_library_shared_does_not_propagate_implementation_deps(),
776            _cc_library_shared_does_not_propagate_implementation_whole_archive_deps(),
777            _cc_library_shared_does_not_propagate_implementation_dynamic_deps(),
778            _cc_libary_shared_propagate_fdo_profile_to_whole_archive_deps(),
779            _cc_library_shared_does_not_propagate_fdo_profile_to_dynamic_deps(),
780            _fdo_profile_transition_correctly_set_and_unset_fdo_profile(),
781            _cc_library_with_fdo_profile_link_flags(),
782            _cc_library_disable_fdo_optimization_if_coverage_is_enabled_test(),
783            _cc_library_set_defines_for_stubs(),
784        ] + _cc_library_shared_provides_androidmk_info(),
785    )
786