Skip to content

Commit

Permalink
cleanup: shorter names for CMake targets (#10431)
Browse files Browse the repository at this point in the history
The CMake targets need to be unique across the whole project. That is
trivial for libraries, but tests often have conflicting names. A
`foo_test.cc` will typically result in a target name of `foo` regardless
of what directory it is in. Note that only the target name needs to be
globally unique, the output file (`foo_test`) is already in the same
directory as `foo_test.cc` and not likely to conflict.

In some places we used something inspired by the path (relative to the
project root or to `google/cloud`) to prefix the target name. In other
places we used something inspired by the associated library. I think it
is simpler to always use the path. And it also yields shorter target.
  • Loading branch information
coryan committed Dec 13, 2022
1 parent a65f43f commit acb4355
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/external-account-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: build
run: |
cmake --build "${{runner.temp}}/build" -j 2 \
--target rest_internal_internal_external_account_integration_test
--target common_internal_external_account_integration_test
# Configure Workload Identity Federation and generate an access token.
- id: 'auth'
Expand Down
3 changes: 1 addition & 2 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ function (google_cloud_cpp_generator_define_tests)

# Generate a target for each unit test.
foreach (fname ${google_cloud_cpp_generator_unit_tests})
google_cloud_cpp_add_executable(target "google_cloud_cpp_generator"
"${fname}")
google_cloud_cpp_add_executable(target "generator" "${fname}")
target_link_libraries(
${target}
PRIVATE google_cloud_cpp_generator
Expand Down
3 changes: 1 addition & 2 deletions generator/integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export_list_to_bazel("google_cloud_cpp_generator_golden_tests.bzl"
"google_cloud_cpp_generator_golden_tests" YEAR "2020")

foreach (fname ${google_cloud_cpp_generator_golden_tests})
google_cloud_cpp_add_executable(target "google_cloud_cpp_generator_golden"
"${fname}")
google_cloud_cpp_add_executable(target "generator_golden" "${fname}")
target_link_libraries(
${target}
PRIVATE google_cloud_cpp_generator_golden_testing
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigtable/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (BUILD_TESTING)
"bigtable_benchmarks_unit_tests" YEAR "2020")

foreach (fname ${bigtable_benchmarks_unit_tests})
google_cloud_cpp_add_executable(target "bigtable_benchmarks" "${fname}")
google_cloud_cpp_add_executable(target "bigtable" "${fname}")
target_link_libraries(
${target}
PRIVATE bigtable_benchmark_common
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/google_cloud_cpp_grpc_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ install(
COMPONENT google_cloud_cpp_development)

function (google_cloud_cpp_grpc_utils_add_test fname labels)
google_cloud_cpp_add_executable(target "common_grpc_utils" "${fname}")
google_cloud_cpp_add_executable(target "common" "${fname}")
target_link_libraries(
${target}
PRIVATE google-cloud-cpp::grpc_utils
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/google_cloud_cpp_rest_internal.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ create_bazel_config(google_cloud_cpp_rest_internal YEAR 2021)

# Define the unit tests in a function so we have a new scope for variable names.
function (google_cloud_cpp_rest_internal_add_test fname labels)
google_cloud_cpp_add_executable(target "rest_internal" "${fname}")
google_cloud_cpp_add_executable(target "common" "${fname}")
target_link_libraries(
${target}
PRIVATE google-cloud-cpp::rest_internal
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/google_cloud_cpp_rest_protobuf_internal.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ install(
COMPONENT google_cloud_cpp_development)

function (google_cloud_cpp_rest_protobuf_internal_add_test fname labels)
google_cloud_cpp_add_executable(target "common_rest_protobuf" "${fname}")
google_cloud_cpp_add_executable(target "common" "${fname}")
target_link_libraries(
${target}
PRIVATE google-cloud-cpp::rest_protobuf_internal
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/testing_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export_list_to_bazel("google_cloud_cpp_testing_unit_tests.bzl"
"google_cloud_cpp_testing_unit_tests" YEAR "2018")

foreach (fname ${google_cloud_cpp_testing_unit_tests})
google_cloud_cpp_add_executable(target "common_testing" "${fname}")
google_cloud_cpp_add_executable(target "testing_util" "${fname}")
target_link_libraries(
${target} PRIVATE google_cloud_cpp_testing google-cloud-cpp::common
GTest::gmock_main GTest::gmock GTest::gtest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export_list_to_bazel("google_cloud_cpp_testing_grpc_unit_tests.bzl"
"google_cloud_cpp_testing_grpc_unit_tests" YEAR "2020")

foreach (fname ${google_cloud_cpp_testing_grpc_unit_tests})
google_cloud_cpp_add_executable(target "common_testing_grpc" "${fname}")
google_cloud_cpp_add_executable(target "testing_util" "${fname}")
target_link_libraries(
${target}
PRIVATE google_cloud_cpp_testing_grpc
Expand Down

0 comments on commit acb4355

Please sign in to comment.