|
| 1 | +# Protocol Buffers - Google's data interchange format |
| 2 | +# Copyright 2025 Google Inc. All rights reserved. |
| 3 | +# |
| 4 | +# Use of this source code is governed by a BSD-style |
| 5 | +# license that can be found in the LICENSE file or at |
| 6 | +# https://developers.google.com/open-source/licenses/bsd |
| 7 | +"""Tests for `cc_proto_library`.""" |
| 8 | + |
| 9 | +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") |
| 10 | +load("@rules_cc//cc:defs.bzl", "cc_library") |
| 11 | +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") |
| 12 | +load("@rules_testing//lib:truth.bzl", "matching") |
| 13 | +load("@rules_testing//lib:util.bzl", "util") |
| 14 | +load("//bazel:cc_proto_library.bzl", "cc_proto_library") |
| 15 | +load("//bazel:proto_library.bzl", "proto_library") |
| 16 | + |
| 17 | +def cc_proto_library_test_suite(name): |
| 18 | + test_suite( |
| 19 | + name = name, |
| 20 | + tests = [ |
| 21 | + _test_link_order_with_mixed_deps, |
| 22 | + _test_link_order_with_mixed_deps_and_intermediate_library, |
| 23 | + ], |
| 24 | + ) |
| 25 | + |
| 26 | +def _test_link_order_with_mixed_deps(name): |
| 27 | + util.helper_target(cc_library, name = name + "_a", srcs = ["a.cc"]) |
| 28 | + util.helper_target(proto_library, name = name + "_b", srcs = ["b.proto"]) |
| 29 | + util.helper_target(cc_proto_library, name = name + "_bc", deps = [":" + name + "_b"]) |
| 30 | + util.helper_target(cc_library, name = name + "_c", srcs = ["c.cc"]) |
| 31 | + util.helper_target( |
| 32 | + cc_binary, |
| 33 | + name = name + "_foo", |
| 34 | + srcs = ["foo.cc"], |
| 35 | + deps = [ |
| 36 | + ":" + name + "_a", |
| 37 | + ":" + name + "_bc", |
| 38 | + ":" + name + "_c", |
| 39 | + ], |
| 40 | + ) |
| 41 | + |
| 42 | + analysis_test( |
| 43 | + name = name, |
| 44 | + target = ":" + name + "_foo", |
| 45 | + impl = _test_link_order_with_mixed_deps_impl, |
| 46 | + ) |
| 47 | + |
| 48 | +def _test_link_order_with_mixed_deps_impl(env, target): |
| 49 | + action = env.expect.that_target(target).action_named("CppLink") |
| 50 | + action.inputs().contains_at_least_predicates([ |
| 51 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_a"), |
| 52 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_b"), |
| 53 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_c"), |
| 54 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_foo"), |
| 55 | + ]) |
| 56 | + |
| 57 | +def _test_link_order_with_mixed_deps_and_intermediate_library(name): |
| 58 | + util.helper_target(cc_library, name = name + "_a", srcs = ["a.cc"]) |
| 59 | + util.helper_target(proto_library, name = name + "_b", srcs = ["b.proto"]) |
| 60 | + util.helper_target(cc_proto_library, name = name + "_bc", deps = [":" + name + "_b"]) |
| 61 | + util.helper_target(cc_library, name = name + "_c", srcs = ["c.cc"]) |
| 62 | + util.helper_target( |
| 63 | + cc_library, |
| 64 | + name = name + "_lib", |
| 65 | + srcs = ["lib.cc"], |
| 66 | + deps = [ |
| 67 | + ":" + name + "_a", |
| 68 | + ":" + name + "_bc", |
| 69 | + ":" + name + "_c", |
| 70 | + ], |
| 71 | + ) |
| 72 | + util.helper_target( |
| 73 | + cc_binary, |
| 74 | + name = name + "_foo", |
| 75 | + srcs = ["foo.cc"], |
| 76 | + deps = [":" + name + "_lib"], |
| 77 | + ) |
| 78 | + |
| 79 | + analysis_test( |
| 80 | + name = name, |
| 81 | + target = ":" + name + "_foo", |
| 82 | + impl = _test_link_order_with_mixed_deps_and_intermediate_library_impl, |
| 83 | + ) |
| 84 | + |
| 85 | +def _test_link_order_with_mixed_deps_and_intermediate_library_impl(env, target): |
| 86 | + action = env.expect.that_target(target).action_named("CppLink") |
| 87 | + action.inputs().contains_at_least_predicates([ |
| 88 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_a"), |
| 89 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_b"), |
| 90 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_c"), |
| 91 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_foo"), |
| 92 | + matching.file_basename_contains("libtest_link_order_with_mixed_deps_lib"), |
| 93 | + ]) |
0 commit comments