diff --git a/.github/workflows/cmake_install.yml b/.github/workflows/cmake_install.yml index 7bc345707f..f770d0dd8c 100644 --- a/.github/workflows/cmake_install.yml +++ b/.github/workflows/cmake_install.yml @@ -29,6 +29,8 @@ jobs: - name: Build dependencies with vcpkg submodule run: | ./ci/setup_windows_ci_environment.ps1 + - name: Run Install Functions Tests + run: ./ci/do_ci.ps1 cmake.install_functions.test - name: Run Tests run: ./ci/do_ci.ps1 cmake.install.test - name: Run DLL Tests @@ -51,6 +53,8 @@ jobs: - name: Build dependencies with vcpkg submodule run: | ./ci/setup_windows_ci_environment.ps1 + - name: Run Install Functions Tests + run: ./ci/do_ci.ps1 cmake.install_functions.test - name: Run Tests run: ./ci/do_ci.ps1 cmake.install.test @@ -78,6 +82,8 @@ jobs: sudo -E apt-get update sudo -E apt-get install -y libabsl-dev libcurl4-openssl-dev zlib1g-dev nlohmann-json3-dev libprotobuf-dev libgrpc++-dev protobuf-compiler protobuf-compiler-grpc sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file third_party_release --packages "googletest;benchmark" + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -108,6 +114,8 @@ jobs: - name: Install Dependencies run: | sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_latest + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -138,6 +146,8 @@ jobs: - name: Install Dependencies run: | sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_stable + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -172,6 +182,8 @@ jobs: - name: Install Dependencies run: | sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_minimum + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -209,6 +221,8 @@ jobs: run: | conan install install/conan/conanfile_stable.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD} conan cache clean --source --build + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -248,6 +262,8 @@ jobs: run: | conan install install/conan/conanfile_latest.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD} conan cache clean --source --build + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -288,6 +304,8 @@ jobs: run: | conan install install/conan/conanfile_stable.txt --build=missing -of /Users/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD} conan cache clean --source --build + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -320,6 +338,8 @@ jobs: brew install grpc brew install nlohmann-json brew install prometheus-cpp + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index eb71804511..3df3f4b3b0 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -472,6 +472,33 @@ switch ($action) { exit 0 } + "cmake.install_functions.test" { + Remove-Item -Recurse -Force "$BUILD_DIR\*" + Remove-Item -Recurse -Force "$INSTALL_TEST_DIR\*" + cd "$BUILD_DIR" + mkdir "$BUILD_DIR\install_functions_test" + cd "$BUILD_DIR\install_functions_test" + $INSTALL_FUNCTIONS_CMAKE_OPTIONS = @( + "-DVCPKG_TARGET_TRIPLET=x64-windows", + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" + ) + $CMAKE_OPTIONS_STRING = $INSTALL_FUNCTIONS_CMAKE_OPTIONS -join " " + cmake "-DCMAKE_PREFIX_PATH=$INSTALL_TEST_DIR" ` + "-DINSTALL_TEST_CMAKE_OPTIONS=$CMAKE_OPTIONS_STRING" ` + "-DINSTALL_TEST_DIR=$INSTALL_TEST_DIR" ` + "-DOPENTELEMETRY_SOURCE_DIR=$SRC_DIR" ` + -S "$SRC_DIR\install\test\cmake\install_functions_test" + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + ctest -C Debug --output-on-failure + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + exit 0 + } "cmake.dll.install.test" { cd "$BUILD_DIR" Remove-Item -Recurse -Force "$BUILD_DIR\*" diff --git a/ci/do_ci.sh b/ci/do_ci.sh index cc825c37f1..5951d92a20 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -457,6 +457,19 @@ elif [[ "$1" == "cmake.do_not_install.test" ]]; then cmake --build . "${CMAKE_BUILD_ARGS[@]}" ctest --output-on-failure exit 0 +elif [[ "$1" == "cmake.install_functions.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + rm -rf ${INSTALL_TEST_DIR}/* + export LD_LIBRARY_PATH="${INSTALL_TEST_DIR}/lib:$LD_LIBRARY_PATH" + mkdir -p "${BUILD_DIR}/install_functions_test" + cd "${BUILD_DIR}/install_functions_test" + cmake "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}" \ + "-DINSTALL_TEST_DIR=${INSTALL_TEST_DIR}" \ + "-DOPENTELEMETRY_SOURCE_DIR=${SRC_DIR}" \ + -S "${SRC_DIR}/install/test/cmake/install_functions_test" + ctest --output-on-failure + exit 0 elif [[ "$1" == "cmake.install.test" ]]; then if [[ -n "${BUILD_SHARED_LIBS}" && "${BUILD_SHARED_LIBS}" == "ON" ]]; then CMAKE_OPTIONS+=("-DBUILD_SHARED_LIBS=ON") diff --git a/cmake/find-package-support-functions.cmake b/cmake/find-package-support-functions.cmake index f74d029d27..5ce6e0f94d 100644 --- a/cmake/find-package-support-functions.cmake +++ b/cmake/find-package-support-functions.cmake @@ -4,6 +4,46 @@ include("${CMAKE_CURRENT_LIST_DIR}/component-definitions.cmake") include("${CMAKE_CURRENT_LIST_DIR}/thirdparty-dependency-definitions.cmake") +#------------------------------------------------------------------------- +# Function to resolve deprecated component names to their aliases. +# Components without an alias are removed from the list +#------------------------------------------------------------------------- +function(resolve_deprecated_components requested_components_inout) + set(_result ${${requested_components_inout}}) + foreach(_COMPONENT IN LISTS ${requested_components_inout}) + if(_COMPONENT IN_LIST OTEL_DEPRECATED_COMPONENTS_LIST) + set(_replacement_var "COMPONENT_${_COMPONENT}_REPLACEMENT") + if(DEFINED ${_replacement_var}) + message(DEPRECATION "opentelemetry-cpp: component `${_COMPONENT}` is deprecated, use `${${_replacement_var}}` instead.") + list(REMOVE_ITEM _result ${_COMPONENT}) + list(APPEND _result ${${_replacement_var}}) + else() + message(DEPRECATION "opentelemetry-cpp: component `${_COMPONENT}` is deprecated with no replacement.") + list(REMOVE_ITEM _result ${_COMPONENT}) + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES _result) + set(${requested_components_inout} "${_result}" PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------- +# Function to set the __FOUND variable for requested +# deprecated component names that have a replacement component. +#------------------------------------------------------------------------- +function(set_deprecated_components_found requested_components_in) + foreach(_COMPONENT IN LISTS ${requested_components_in}) + if(_COMPONENT IN_LIST OTEL_DEPRECATED_COMPONENTS_LIST) + set(_replacement_var "COMPONENT_${_COMPONENT}_REPLACEMENT") + if(DEFINED ${_replacement_var} + AND ${CMAKE_FIND_PACKAGE_NAME}_${${_replacement_var}}_FOUND) + set(${CMAKE_FIND_PACKAGE_NAME}_${_COMPONENT}_FOUND TRUE + CACHE BOOL "whether ${CMAKE_FIND_PACKAGE_NAME} deprecated component ${_COMPONENT} is found (via replacement ${${_replacement_var}})" FORCE) + endif() + endif() + endforeach() +endfunction() + #------------------------------------------------------------------------- # Function to get installed components. #------------------------------------------------------------------------- @@ -33,7 +73,6 @@ function(get_dependent_components component_in dependent_components_out) set(${dependent_components_out} ${result} PARENT_SCOPE) endfunction() - #------------------------------------------------------------------------- # Function to get requested components. #------------------------------------------------------------------------- @@ -44,13 +83,15 @@ function(get_requested_components installed_components_in requested_components_o message(DEBUG "get_requested_components: No components explicitly requested. Importing all installed components including: ${result}") set(${requested_components_out} ${result} PARENT_SCOPE) else() - message(DEBUG "get_requested_components: Components requested: ${opentelemetry-cpp_FIND_COMPONENTS}") - foreach(_COMPONENT IN LISTS opentelemetry-cpp_FIND_COMPONENTS) - if(NOT ${_COMPONENT} IN_LIST OTEL_BUILT_COMPONENTS_LIST) + set(REQUESTED_COMPONENTS ${opentelemetry-cpp_FIND_COMPONENTS}) + message(DEBUG "get_requested_components: Components requested: ${REQUESTED_COMPONENTS}") + resolve_deprecated_components(REQUESTED_COMPONENTS) + foreach(_COMPONENT IN LISTS REQUESTED_COMPONENTS) + if(NOT _COMPONENT IN_LIST OTEL_BUILT_COMPONENTS_LIST) message(ERROR " get_requested_components: Component `${_COMPONENT}` is not a built component of the opentelemetry-cpp package. Built components include: ${OTEL_BUILT_COMPONENTS_LIST}") return() endif() - if(NOT ${_COMPONENT} IN_LIST ${installed_components_in}) + if(NOT _COMPONENT IN_LIST ${installed_components_in}) message(ERROR " get_requested_components: Component `${_COMPONENT}` is supported by opentelemetry-cpp but not installed. Installed components include: ${${installed_components_in}}") return() endif() @@ -69,7 +110,7 @@ endfunction() #------------------------------------------------------------------------- function(get_component_targets component_in targets_out) set(result "") - if(NOT ${component_in} IN_LIST OTEL_BUILT_COMPONENTS_LIST) + if(NOT component_in IN_LIST OTEL_BUILT_COMPONENTS_LIST) message(ERROR " get_component_targets: Component `${component_in}` component is not a built component of the opentelemetry-cpp package.") else() set(targets_var "COMPONENT_${component_in}_TARGETS") @@ -116,7 +157,7 @@ endfunction() #------------------------------------------------------------------------- function (is_dependency_required dependency_in components_in is_required_out) foreach(_component IN LISTS ${components_in}) - if(${dependency_in} IN_LIST COMPONENT_${_component}_THIRDPARTY_DEPENDS) + if(dependency_in IN_LIST COMPONENT_${_component}_THIRDPARTY_DEPENDS) set(${is_required_out} TRUE PARENT_SCOPE) return() endif() diff --git a/cmake/otel-install-functions.cmake b/cmake/otel-install-functions.cmake index 109a0ed548..468d6db653 100644 --- a/cmake/otel-install-functions.cmake +++ b/cmake/otel-install-functions.cmake @@ -6,6 +6,38 @@ include("${PROJECT_SOURCE_DIR}/cmake/thirdparty-dependency-config.cmake") # INTERNAL FUNCTIONS - do not call directly. Use the otel_* "Main" functions ######################################################################## +#----------------------------------------------------------------------- +# _otel_check_component_name: +# 1. Checks if the component name is valid and not already registered or deprecated. +# 2. Checks if any of the deprecated names conflict with existing components or deprecated names. +# +#----------------------------------------------------------------------- +function(_otel_check_component_name _COMPONENT_NAME _DEPRECATED_NAMES) + get_property(_COMPONENTS DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_COMPONENTS_LIST) + get_property(_DEPRECATED_COMPONENTS DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) + + # Check if the component name is already registered or deprecated + if(_COMPONENT_NAME IN_LIST _COMPONENTS) + message(FATAL_ERROR + "_otel_check_component_name: COMPONENT ${_COMPONENT_NAME} has already been created") + elseif(_COMPONENT_NAME IN_LIST _DEPRECATED_COMPONENTS) + message(FATAL_ERROR + "_otel_check_component_name: COMPONENT ${_COMPONENT_NAME} is already registered as a deprecated name") + endif() + + # Check if any of the deprecated names conflict with existing components or deprecated names + foreach(_DEPRECATED_NAME IN LISTS _DEPRECATED_NAMES) + if(_DEPRECATED_NAME STREQUAL _COMPONENT_NAME OR _DEPRECATED_NAME IN_LIST _COMPONENTS) + message(FATAL_ERROR + "_otel_check_component_name: DEPRECATED_NAME ${_DEPRECATED_NAME} conflicts with a component name") + endif() + if(_DEPRECATED_NAME IN_LIST _DEPRECATED_COMPONENTS) + message(FATAL_ERROR + "_otel_check_component_name: DEPRECATED_NAME ${_DEPRECATED_NAME} is already registered") + endif() + endforeach() +endfunction() + #----------------------------------------------------------------------- # _otel_set_component_properties: # Sets the component properties used for install. @@ -27,9 +59,6 @@ function(_otel_set_component_properties) # Add the component to the current components list get_property(existing_components DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_COMPONENTS_LIST) - if(_PROPERTIES_COMPONENT IN_LIST existing_components) - message(FATAL_ERROR " component ${_PROPERTIES_COMPONENT} has already been created.") - endif() list(APPEND existing_components "${_PROPERTIES_COMPONENT}") set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_COMPONENTS_LIST "${existing_components}") @@ -80,7 +109,7 @@ function(_otel_set_target_component_property _TARGET _COMPONENT) if(_TARGET_COMPONENT) message(FATAL_ERROR " Target ${_TARGET} is already assigned to an opentelemetry-cpp COMPONENT ${_TARGET_COMPONENT}.") endif() - set_target_properties(${_TARGET} PROPERTIES INTERFACE_OTEL_COMPONENT_NAME ${_OTEL_ADD_COMP_COMPONENT}) + set_target_properties(${_TARGET} PROPERTIES INTERFACE_OTEL_COMPONENT_NAME ${_COMPONENT}) endfunction() #----------------------------------------------------------------------- @@ -181,14 +210,14 @@ function(_otel_collect_component_dependencies _TARGET _COMPONENT OUT_COMPONENT_D endif() # Skip BUILD_INTERFACE targets - string(FIND "${_linked_target}" "$ +# [DEPRECATED_NAMES ...] # TARGETS ... -# FILES_DIRECTORY -# FILES_DESTINATION -# FILES_MATCHING ) +# [FILES_DIRECTORY +# FILES_DESTINATION +# FILES_MATCHING ]) #----------------------------------------------------------------------- function(otel_add_component) - set(optionArgs ) + set(optionArgs DEPRECATED) set(oneValueArgs COMPONENT FILES_DIRECTORY FILES_DESTINATION) - set(multiValueArgs TARGETS FILES_MATCHING) + set(multiValueArgs TARGETS FILES_MATCHING DEPRECATED_NAMES) cmake_parse_arguments(_OTEL_ADD_COMP "${optionArgs}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") if(NOT _OTEL_ADD_COMP_COMPONENT) @@ -343,6 +377,8 @@ function(otel_add_component) message(FATAL_ERROR "otel_add_component: TARGETS is required") endif() + _otel_check_component_name(${_OTEL_ADD_COMP_COMPONENT} "${_OTEL_ADD_COMP_DEPRECATED_NAMES}") + message(DEBUG "Add COMPONENT: ${_OTEL_ADD_COMP_COMPONENT}") set(_COMPONENT_DEPENDS "") set(_THIRDPARTY_DEPENDS "") @@ -378,6 +414,16 @@ function(otel_add_component) FILES_MATCHING ${_OTEL_ADD_COMP_FILES_MATCHING} COMPONENT_DEPENDS ${_COMPONENT_DEPENDS} THIRDPARTY_DEPENDS ${_THIRDPARTY_DEPENDS}) + + foreach(_DEP_NAME IN LISTS _OTEL_ADD_COMP_DEPRECATED_NAMES) + get_property(_deprecated_components DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) + list(APPEND _deprecated_components "${_DEP_NAME}") + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST "${_deprecated_components}") + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} + PROPERTY OTEL_COMPONENT_REPLACEMENT_${_DEP_NAME} + "${_OTEL_ADD_COMP_COMPONENT}") + message(DEBUG " DEPRECATED_NAME: ${_DEP_NAME} -> ${_OTEL_ADD_COMP_COMPONENT}") + endforeach() endfunction() #----------------------------------------------------------------------- @@ -420,6 +466,26 @@ function(otel_install_components) _otel_populate_component_thirdparty_depends_block(${_COMPONENT} OTEL_COMPONENTS_THIRDPARTY_DEPENDENCIES_BLOCK) endforeach() + get_property(OTEL_DEPRECATED_COMPONENTS_LIST DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) + + if(OTEL_DEPRECATED_COMPONENTS_LIST) + message(STATUS "Install DEPRECATED COMPONENT definitions:") + endif() + + set(OTEL_COMPONENTS_REPLACEMENTS_BLOCK "") + foreach(_DEPRECATED_COMPONENT IN LISTS OTEL_DEPRECATED_COMPONENTS_LIST) + get_property(_REPLACEMENT_COMPONENT DIRECTORY ${PROJECT_SOURCE_DIR} + PROPERTY OTEL_COMPONENT_REPLACEMENT_${_DEPRECATED_COMPONENT}) + message(STATUS " Deprecated COMPONENT ${_DEPRECATED_COMPONENT}") + if(_REPLACEMENT_COMPONENT) + message(STATUS " Replacement: ${_REPLACEMENT_COMPONENT}") + string(APPEND OTEL_COMPONENTS_REPLACEMENTS_BLOCK + "set(COMPONENT_${_DEPRECATED_COMPONENT}_REPLACEMENT ${_REPLACEMENT_COMPONENT})\n") + else() + message(FATAL_ERROR " no DEPRECATED_NAME on an installed component was found for ${_DEPRECATED_COMPONENT} -- deprecating components with no replacement is not currently supported.") + endif() + endforeach() + configure_file( "${PROJECT_SOURCE_DIR}/cmake/templates/component-definitions.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake/component-definitions.cmake" diff --git a/cmake/templates/component-definitions.cmake.in b/cmake/templates/component-definitions.cmake.in index 8430cc90fe..46263053ea 100644 --- a/cmake/templates/component-definitions.cmake.in +++ b/cmake/templates/component-definitions.cmake.in @@ -3,6 +3,17 @@ # Configured from opentelemetry-cpp/cmake/component-definitions.cmake.in +# ---------------------------------------------------------------------- +# Deprecated components +# ---------------------------------------------------------------------- +set(OTEL_DEPRECATED_COMPONENTS_LIST @OTEL_DEPRECATED_COMPONENTS_LIST@) + +# ---------------------------------------------------------------------- +# Deprecated component replacements (deprecated_name -> replacement_name) +# ---------------------------------------------------------------------- + +@OTEL_COMPONENTS_REPLACEMENTS_BLOCK@ + # ---------------------------------------------------------------------- # opentelmetry-cpp Built COMPONENT list # ---------------------------------------------------------------------- diff --git a/cmake/templates/opentelemetry-cpp-config.cmake.in b/cmake/templates/opentelemetry-cpp-config.cmake.in index 69f77feac9..db43a99216 100644 --- a/cmake/templates/opentelemetry-cpp-config.cmake.in +++ b/cmake/templates/opentelemetry-cpp-config.cmake.in @@ -72,6 +72,7 @@ # COMPONENTS # api # sdk +# configuration # ext_common # ext_http_curl # ext_dll @@ -88,6 +89,14 @@ # resource_detectors # shims_opentracing # +# DEPRECATED COMPONENTS +# exporters_otlp_builder_utils - targets moved to COMPONENT exporters_otlp_common +# exporters_otlp_file_builder - targets moved to COMPONENT exporters_otlp_file +# exporters_otlp_http_builder - targets moved to COMPONENT exporters_otlp_http +# exporters_otlp_grpc_builder - targets moved to COMPONENT exporters_otlp_grpc +# exporters_ostream_builder - targets moved to COMPONENT exporters_ostream +# exporters_prometheus_builder - targets moved to COMPONENT exporters_prometheus +# -------------------- # :: # # TARGETS @@ -99,6 +108,8 @@ # opentelemetry-cpp::trace - Imported target of COMPONENT sdk # opentelemetry-cpp::metrics - Imported target of COMPONENT sdk # opentelemetry-cpp::logs - Imported target of COMPONENT sdk +# opentelemetry-cpp::configuration_core - Imported target of COMPONENT sdk +# opentelemetry-cpp::configuration - Imported target of COMPONENT configuration # opentelemetry-cpp::ext - Imported target of COMPONENT ext_common # opentelemetry-cpp::http_client_curl - Imported target of COMPONENT ext_http_curl # opentelemetry-cpp::opentelemetry_cpp - Imported target of COMPONENT ext_dll @@ -143,6 +154,7 @@ # - **Protobuf** # - **gRPC** # - **prometheus-cpp** +# - **ryml** # - **OpenTracing** # # **Found using the CMake MODULE search mode:** @@ -194,6 +206,10 @@ foreach(_COMPONENT IN LISTS _REQUESTED_COMPONENTS) CACHE BOOL "whether ${CMAKE_FIND_PACKAGE_NAME} component ${_COMPONENT} is found" FORCE) endforeach() +# set the component found flag for requested deprecated component names +# resolved to an imported replacement component +set_deprecated_components_found(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) + # get installed and requested targets set(_OPENTELEMETRY_CPP_TARGETS "") get_targets(_REQUESTED_COMPONENTS _OPENTELEMETRY_CPP_TARGETS) diff --git a/docs/deprecation-process.md b/docs/deprecation-process.md index 81d3e845ce..ce8105671e 100644 --- a/docs/deprecation-process.md +++ b/docs/deprecation-process.md @@ -298,6 +298,137 @@ and will not be impacted by the removal to come. When implementing such logic, document it in the mitigation section, in file `DEPRECATED`. +### CMake package component deprecation + +The installed opentelemetry-cpp CMake package supports the `COMPONENTS` +argument to `find_package(opentelemetry-cpp CONFIG ...)`. +CMake components may need to be deprecated over time. + +There are three cases to distinguish: + +* a component name is changed, +* a component is merged (with all its targets) into another component, +* a component and its targets are deprecated and set for future removal from the + package. + +#### Component name change + +For a component name change, keep the CMake target set unchanged and add the +deprecated name under the `DEPRECATED_NAMES` list. + +Example: + +```cmake +otel_add_component( + COMPONENT component_old_name + TARGETS opentelemetry_some_target) +``` + +The new component receives the new name but must retain the targets unchanged. + +```cmake +otel_add_component( + COMPONENT component_new_name + DEPRECATED_NAMES component_old_name + TARGETS opentelemetry_some_target) +``` + +When a user requests `component_old_name`, the installed package config emits a CMake +deprecation warning and resolves the request to `component_new_name`. + +```cmake +# the following will now resolve `component_old_name` to `component_new_name` +find_package(opentelemetry-cpp CONFIG COMPONENTS component_old_name) +``` + +#### Component merge + +For a component merge, add `component_B` to `component_A`'s +`DEPRECATED_NAMES` list and add `component_B`'s targets to `component_A`'s +`TARGETS` list: + +Example: + +Before the merge, two components are defined. + +```cmake +otel_add_component( + COMPONENT component_A + TARGETS component_A_target) + +otel_add_component( + COMPONENT component_B + TARGETS component_B_target) +``` + +After the merge, `component_B`'s definition is removed. +Its name and targets are added to the deprecated names and targets +for `component_A` respectively. + +```cmake +otel_add_component( + COMPONENT component_A + DEPRECATED_NAMES component_B + TARGETS + component_A_target + component_B_target) +``` + +When a user requests `component_B`, the installed package config emits a CMake +deprecation warning and resolves the request to `component_A` importing +the merged set of targets. + +```cmake +# the following will now resolve deprecated `component_B` to `component_A` +# all targets from the merged component are imported and remain unchanged +find_package(opentelemetry-cpp CONFIG COMPONENTS component_B) + +target_link_libraries(my_library PRIVATE + opentelemetry-cpp::component_A_target + opentelemetry-cpp::component_B_target) +``` + +Note: The set of targets provided by the independent components before merge +and from the merged component must not change. Changing target names risks +breaking the user's CMake configuration. Deprecating and renaming targets +remains a TODO and is currently not supported. + +#### Deprecating a component for removal + +[TODO] This use case is not fully implemented in `otel_add_component` + +When a component and its targets are set for removal from the package, the +component must be marked deprecated with the `DEPRECATED` tag and remain in the +package for a deprecation period. During this time the component and its targets +must be installed with the package and be imported by `find_package`. + +Example: + +```cmake +otel_add_component( + COMPONENT component_to_remove + DEPRECATED + TARGETS component_target + ) +``` + +```cmake +# the following will import the deprecated component's targets and emit a +# CMake deprecation warning +find_package(opentelemetry-cpp CONFIG COMPONENTS component_to_remove) +``` + +#### Validate the deprecated component + +Add the deprecated component name to the `./ci/do_ci.sh` script's +`cmake.install.test` target's `DEPRECATED_COMPONENTS` variable. + +The install test +`./install/test/cmake/usage_tests/deprecated_components` verifies that +requesting deprecated +component names with `find_package` configures successfully and that +CMake emits a deprecation warning. + ### C++ deprecation #### C++ header deprecation diff --git a/install/test/cmake/CMakeLists.txt b/install/test/cmake/CMakeLists.txt index dfe569bf8f..2e2024b3b0 100644 --- a/install/test/cmake/CMakeLists.txt +++ b/install/test/cmake/CMakeLists.txt @@ -50,48 +50,6 @@ set(INSTALL_TEST_SRC_DIR "${CMAKE_SOURCE_DIR}/../src") enable_testing() -# ----------------------------------------------------------- -# CMake Usage tests for find_package(opentelemetry-cpp ...) -# -# 1. Test find_package with no components specified -# 2. Test find_package with components specified but not sorted in dependency -# order -# 3. Test find_package with components specified but missing dependent components -# 4. Test find_package with components specified but including -# unsupported/unknown components - -add_test( - NAME cmake-usage-no-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/no_components -B - build-cmake-usage-no-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - -add_test( - NAME cmake-usage-unsorted-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/unsorted_components -B - build-cmake-usage-unsorted-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - -add_test( - NAME cmake-usage-missing-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/missing_components -B - build-cmake-usage-missing-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - -add_test( - NAME cmake-usage-unsupported-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/unsupported_components -B - build-cmake-usage-unsupported-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - # ----------------------------------------------------------- # Test the full package install using legacy cmake build instructions # find_package(opentelemetry-cpp CONFIG REQUIRED) diff --git a/install/test/cmake/install_functions_test/CMakeLists.txt b/install/test/cmake/install_functions_test/CMakeLists.txt new file mode 100644 index 0000000000..fd508cfb78 --- /dev/null +++ b/install/test/cmake/install_functions_test/CMakeLists.txt @@ -0,0 +1,157 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# opentelemetry-cpp CMake Install Functions Tests +# +# These tests cover the opentelemetry-cpp CMake install functions defined in +# cmake/otel-install-functions.cmake. +# +# Usage: ./ci/do_ci.sh cmake.install_functions.test + +cmake_minimum_required(VERSION 3.16) +project(opentelemetry-cpp-install-functions-tests LANGUAGES NONE) + +list( + APPEND + INSTALL_TEST_CMAKE_OPTIONS + "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_BUILD_TYPE=Release" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + "-DENABLE_EXAMPLES=OFF" + "-DENABLE_TESTS=OFF" + "-DENABLE_PREVIEW=OFF" + "-DENABLE_COMPONENTS=OFF" + "-DOPENTELEMETRY_INSTALL=ON" + "-DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR}" + "-C" + "${OPENTELEMETRY_SOURCE_DIR}/test_common/cmake/all-options-abiv1.cmake" + "-S" + "${OPENTELEMETRY_SOURCE_DIR}") + +set(POST_INSTALL_TEST_CMAKE_OPTIONS "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}") + +enable_testing() + +# --------------------------------------------------------------- +# Test to verify that a currently defined component cannot be marked deprecated +# by another component. Must fail the CMake configure step. +# --------------------------------------------------------------- +add_test( + NAME install-functions-configure-duplicate-component-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -B + build-configure-duplicate-component-test + "-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${CMAKE_SOURCE_DIR}/configure_tests/duplicate_component" + ${INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-configure-duplicate-component-test + PROPERTIES WILL_FAIL TRUE) + +# --------------------------------------------------------------- +# Test to verify that duplicate component names cannot be defined. Must fail the +# CMake configure step. +# --------------------------------------------------------------- +add_test( + NAME install-functions-configure-component-name-collision-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -B + build-configure-component-name-collision-test + "-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${CMAKE_SOURCE_DIR}/configure_tests/component_name_collision" + ${INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-configure-component-name-collision-test + PROPERTIES WILL_FAIL TRUE) + +# --------------------------------------------------------------- +# Test to verify that a deprecated component cannot have multiple replacement +# components. Must fail the CMake configure step. +# --------------------------------------------------------------- +add_test( + NAME install-functions-configure-duplicate-deprecated-name-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -B + build-configure-duplicate-deprecated-name-test + "-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${CMAKE_SOURCE_DIR}/configure_tests/duplicate_deprecated_name" + ${INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-configure-duplicate-deprecated-name-test + PROPERTIES WILL_FAIL TRUE) + +# --------------------------------------------------------------- +# Test to correctly define CMake components including component to component +# dependencies and deprecated components. Must pass the CMake configure step and +# installation must succeed for the tests to follow. +# --------------------------------------------------------------- +add_test( + NAME install-functions-configure-valid-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -B build-configure-valid-test + "-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${CMAKE_SOURCE_DIR}/configure_tests/valid_components" + ${INSTALL_TEST_CMAKE_OPTIONS}) + +add_test(NAME install-functions-install-valid-test + COMMAND ${CMAKE_COMMAND} --build build-configure-valid-test --parallel + --target install) +set_tests_properties(install-functions-install-valid-test + PROPERTIES DEPENDS install-functions-configure-valid-test) + +# --------------------------------------------------------------- +# Test find_package with no components specified. All installed components and +# targets must be imported. +# ---------------------------------------------------------------- +add_test( + NAME install-functions-usage-no-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/no_components -B + build-cmake-usage-no-components-test ${POST_INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-usage-no-components-test + PROPERTIES DEPENDS install-functions-install-valid-test) + +# --------------------------------------------------------------- +# Test find_package with a deprecated component name. A deprecation warning must +# be emitted and the replacement component must be imported. +# --------------------------------------------------------------- +add_test( + NAME install-functions-deprecated-name-test + COMMAND + ${CMAKE_COMMAND} -Wdeprecated --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/deprecated_name -B + build-deprecated-name-test ${POST_INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-deprecated-name-test + PROPERTIES DEPENDS install-functions-install-valid-test) + +# --------------------------------------------------------------- +# Test find_package component dependency resolution. Unsorted components must be +# imported in the correct order. +# --------------------------------------------------------------- +add_test( + NAME install-functions-unsorted-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/unsorted_components -B + build-unsorted-components-test ${POST_INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-unsorted-components-test + PROPERTIES DEPENDS install-functions-install-valid-test) + +# --------------------------------------------------------------- +# Test find_package component dependency resolution. Missing dependent +# components must be imported automatically. +# --------------------------------------------------------------- +add_test( + NAME install-functions-missing-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/missing_components -B + build-missing-components-test ${POST_INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-missing-components-test + PROPERTIES DEPENDS install-functions-install-valid-test) + +# --------------------------------------------------------------- +# Test find_package on an unsupported/unknown component +# --------------------------------------------------------------- +add_test( + NAME install-functions-unsupported-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/unsupported_components -B + build-unsupported-components-test ${POST_INSTALL_TEST_CMAKE_OPTIONS}) +set_tests_properties(install-functions-unsupported-components-test + PROPERTIES DEPENDS install-functions-install-valid-test) diff --git a/install/test/cmake/install_functions_test/configure_tests/component_name_collision/CMakeLists.txt b/install/test/cmake/install_functions_test/configure_tests/component_name_collision/CMakeLists.txt new file mode 100644 index 0000000000..02c37d1ad9 --- /dev/null +++ b/install/test/cmake/install_functions_test/configure_tests/component_name_collision/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Tests to verify that a previously defined component cannot be marked as +# deprecated. To deprecate a component its definition must be removed and its +# name added to the DEPRECATED_NAMES of the replacement. This test must fail +# CMake the configure step. + +add_library(target_a INTERFACE) +set_target_properties(target_a PROPERTIES EXPORT_NAME target_a) +otel_add_component(COMPONENT component_a TARGETS target_a) + +add_library(target_b INTERFACE) +set_target_properties(target_b PROPERTIES EXPORT_NAME target_b) +otel_add_component(COMPONENT component_b TARGETS target_b DEPRECATED_NAMES + component_a) diff --git a/install/test/cmake/install_functions_test/configure_tests/duplicate_component/CMakeLists.txt b/install/test/cmake/install_functions_test/configure_tests/duplicate_component/CMakeLists.txt new file mode 100644 index 0000000000..339cbe6337 --- /dev/null +++ b/install/test/cmake/install_functions_test/configure_tests/duplicate_component/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Test to verify that duplicate component names are not allowed. This test must +# fail the CMake configure step. + +add_library(target_a INTERFACE) +set_target_properties(target_a PROPERTIES EXPORT_NAME target_a) +otel_add_component(COMPONENT component_a TARGETS target_a) + +add_library(target_b INTERFACE) +set_target_properties(target_b PROPERTIES EXPORT_NAME target_b) +otel_add_component(COMPONENT component_a TARGETS target_b) diff --git a/install/test/cmake/install_functions_test/configure_tests/duplicate_deprecated_name/CMakeLists.txt b/install/test/cmake/install_functions_test/configure_tests/duplicate_deprecated_name/CMakeLists.txt new file mode 100644 index 0000000000..bb8f3b9f12 --- /dev/null +++ b/install/test/cmake/install_functions_test/configure_tests/duplicate_deprecated_name/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Test to verify that duplicate deprecated component names are not allowed. This +# test must fail the CMake configure step. + +add_library(target_a INTERFACE) +set_target_properties(target_a PROPERTIES EXPORT_NAME target_a) +otel_add_component(COMPONENT component_a TARGETS target_a DEPRECATED_NAMES + old_name) + +add_library(target_b INTERFACE) +set_target_properties(target_b PROPERTIES EXPORT_NAME target_b) +otel_add_component(COMPONENT component_b TARGETS target_b DEPRECATED_NAMES + old_name) diff --git a/install/test/cmake/install_functions_test/configure_tests/valid_components/CMakeLists.txt b/install/test/cmake/install_functions_test/configure_tests/valid_components/CMakeLists.txt new file mode 100644 index 0000000000..e9481b3da4 --- /dev/null +++ b/install/test/cmake/install_functions_test/configure_tests/valid_components/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Test for valid usage of the otel_add_component() CMake function. This test +# must pass the CMake configure step. + +# Add a component with a deprecated name. +add_library(opentelemetry_deprecation_test_target INTERFACE) +set_target_properties(opentelemetry_deprecation_test_target + PROPERTIES EXPORT_NAME deprecation_test_target) +otel_add_component( + COMPONENT deprecation_test_component_new DEPRECATED_NAMES + deprecation_test_component_old TARGETS opentelemetry_deprecation_test_target) + +# Add two components where the second depends on the first through a target +# dependency. +add_library(opentelemetry_component_dependency_test_base_target INTERFACE) +set_target_properties(opentelemetry_component_dependency_test_base_target + PROPERTIES EXPORT_NAME test_component_base_target) +otel_add_component(COMPONENT test_component_base TARGETS + opentelemetry_component_dependency_test_base_target) + +add_library(opentelemetry_test_component_depends INTERFACE) +set_target_properties(opentelemetry_test_component_depends + PROPERTIES EXPORT_NAME test_component_depends_target) +target_link_libraries( + opentelemetry_test_component_depends + INTERFACE opentelemetry_component_dependency_test_base_target) +otel_add_component(COMPONENT test_component_depends TARGETS + opentelemetry_test_component_depends) diff --git a/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt new file mode 100644 index 0000000000..5cfee589c0 --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: find_package with a deprecated component name. +# +# Requesting the deprecated name must resolve to the replacement component and +# emit a deprecation warning. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-deprecated-name-test LANGUAGES NONE) + +find_package(opentelemetry-cpp CONFIG REQUIRED + COMPONENTS deprecation_test_component_old) + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with a deprecated component name must set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_deprecation_test_component_old_FOUND) + message( + FATAL_ERROR + "the requested deprecated component name must set opentelemetry-cpp_deprecation_test_component_old_FOUND when its replacement is imported" + ) +endif() + +if(NOT opentelemetry-cpp_deprecation_test_component_new_FOUND) + message( + FATAL_ERROR + "the requested deprecated component name must set opentelemetry-cpp_deprecation_test_component_new_FOUND when its replacement is imported" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::deprecation_test_target) + message( + FATAL_ERROR "opentelemetry-cpp::deprecation_test_target target not imported" + ) +endif() diff --git a/install/test/cmake/install_functions_test/post_install_tests/missing_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/missing_components/CMakeLists.txt new file mode 100644 index 0000000000..e0df503ff0 --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/missing_components/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: missing dependent components are implicitly resolved. +# +# Only test_component_depends is requested. Its dependency test_component_base +# must be imported automatically. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-missing-components-test LANGUAGES NONE) + +find_package(opentelemetry-cpp CONFIG REQUIRED + COMPONENTS test_component_depends) + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with a missing dependent component must set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_test_component_depends_FOUND) + message( + FATAL_ERROR + "find_package must set opentelemetry-cpp_test_component_depends_FOUND") +endif() + +if(NOT opentelemetry-cpp_test_component_base_FOUND) + message( + FATAL_ERROR + "the implicitly imported dependency component must set opentelemetry-cpp_test_component_base_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_depends_target) + message( + FATAL_ERROR + "opentelemetry-cpp::test_component_depends_target target not imported") +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_base_target) + message( + FATAL_ERROR + "the dependency component target opentelemetry-cpp::test_component_base_target must be imported implicitly" + ) +endif() diff --git a/install/test/cmake/usage_tests/no_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/no_components/CMakeLists.txt similarity index 68% rename from install/test/cmake/usage_tests/no_components/CMakeLists.txt rename to install/test/cmake/install_functions_test/post_install_tests/no_components/CMakeLists.txt index 7e4f092b9f..dd58a7ff6e 100644 --- a/install/test/cmake/usage_tests/no_components/CMakeLists.txt +++ b/install/test/cmake/install_functions_test/post_install_tests/no_components/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16) -project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) +project(opentelemetry-cpp-no-components-install-test LANGUAGES CXX) # specifying no components must import all installed components find_package(opentelemetry-cpp CONFIG REQUIRED) @@ -22,6 +22,18 @@ if(NOT opentelemetry-cpp_FOUND) ) endif() +# Test components added: +set(TEST_COMPONENT_TARGETS + opentelemetry-cpp::deprecation_test_target + opentelemetry-cpp::test_component_base_target + opentelemetry-cpp::test_component_depends_target) + +foreach(_COMPONENT_TARGET IN LISTS TEST_COMPONENT_TARGETS) + if(NOT TARGET ${_COMPONENT_TARGET}) + message(FATAL_ERROR "component target ${_COMPONENT_TARGET} not found") + endif() +endforeach() + if(NOT TARGET opentelemetry-cpp::api) message(FATAL_ERROR "opentelemetry-cpp::api target not found") endif() diff --git a/install/test/cmake/install_functions_test/post_install_tests/unsorted_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/unsorted_components/CMakeLists.txt new file mode 100644 index 0000000000..cb00da88a5 --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/unsorted_components/CMakeLists.txt @@ -0,0 +1,70 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: components requested out of dependency order. Depends on +# configuration and installation of opentelemetry-cpp configured from +# install_functions_test/configure_tests/valid_components/CMakeLists.txt. +# +# test_component_depends depends on test_component_base but is listed first. The +# package config must import the components in the correct order without error. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-unsorted-components-test LANGUAGES NONE) + +find_package( + opentelemetry-cpp CONFIG REQUIRED + COMPONENTS test_component_depends deprecation_test_component_old + test_component_base deprecation_test_component_new) + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_test_component_depends_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_test_component_depends_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_test_component_base_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_test_component_base_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_base_target) + message( + FATAL_ERROR + "opentelemetry-cpp::test_component_base_target target not imported") +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_depends_target) + message( + FATAL_ERROR + "opentelemetry-cpp::test_component_depends_target target not imported") +endif() + +if(NOT opentelemetry-cpp_deprecation_test_component_old_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_deprecation_test_component_old_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_deprecation_test_component_new_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_deprecation_test_component_new_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::deprecation_test_target) + message( + FATAL_ERROR "opentelemetry-cpp::deprecation_test_target target not imported" + ) +endif() diff --git a/install/test/cmake/install_functions_test/post_install_tests/unsupported_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/unsupported_components/CMakeLists.txt new file mode 100644 index 0000000000..d0d3d523b3 --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/unsupported_components/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: an unsupported/unknown component must not be found. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-unsupported-components-test LANGUAGES NONE) + +# request an unsupported/unknown component (without the REQUIRED arg) +find_package(opentelemetry-cpp CONFIG COMPONENTS test_component_base + an_unknown_component) + +if(OPENTELEMETRY_CPP_FOUND) + message( + FATAL_ERROR + "find_package with an unsupported component must not set OPENTELEMETRY_CPP_FOUND" + ) +endif() + +if(opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with an unsupported component must not set opentelemetry-cpp_FOUND" + ) +endif() + +if(opentelemetry-cpp_an_unknown_component_FOUND) + message( + FATAL_ERROR + "an unsupported component must not set opentelemetry-cpp_an_unknown_component_FOUND" + ) +endif() diff --git a/install/test/cmake/usage_tests/missing_components/CMakeLists.txt b/install/test/cmake/usage_tests/missing_components/CMakeLists.txt deleted file mode 100644 index 0f123511ad..0000000000 --- a/install/test/cmake/usage_tests/missing_components/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.16) - -project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) - -# Any missing component dependencies must be implicitly resolved. This tests -# implicitly resolves the sdk component dependency -find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api - exporters_in_memory) - -if(NOT OPENTELEMETRY_CPP_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set OPENTELEMETRY_CPP_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_exporters_in_memory_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_exporters_in_memory_FOUND" - ) -endif() - -if(NOT TARGET opentelemetry-cpp::api) - message(FATAL_ERROR "opentelemetry-cpp::api target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::sdk) - message(FATAL_ERROR "opentelemetry-cpp::sdk target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::in_memory_span_exporter) - message( - FATAL_ERROR "opentelemetry-cpp::in_memory_span_exporter target not found") -endif() diff --git a/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt deleted file mode 100644 index 7eb7465043..0000000000 --- a/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.16) - -project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) - -# components not provided in order of dependency must be imported in the correct -# order without error -find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_ostream api - sdk) - -if(NOT OPENTELEMETRY_CPP_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set OPENTELEMETRY_CPP_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_exporters_ostream_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_exporters_ostream_FOUND" - ) -endif() - -if(NOT TARGET opentelemetry-cpp::api) - message(FATAL_ERROR "opentelemetry-cpp::api target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::sdk) - message(FATAL_ERROR "opentelemetry-cpp::sdk target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::ostream_log_record_exporter) - message( - FATAL_ERROR - "opentelemetry-cpp::ostream_log_record_exporter target not found") -endif() diff --git a/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt deleted file mode 100644 index f799f4850b..0000000000 --- a/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.16) - -project(opentelemetry-cpp-unsupported-components-install-test LANGUAGES CXX) - -# request an unsupported/unknown component (without the REQUIRED arg) -find_package(opentelemetry-cpp CONFIG COMPONENTS api an_unknown_component) - -if(OPENTELEMETRY_CPP_FOUND) - message( - FATAL_ERROR - "calling find_package with an unsuported component should not set OPENTELEMETRY_CPP_FOUND" - ) -endif() - -if(opentelemetry-cpp_FOUND) - message( - FATAL_ERROR - "calling find_package with an unsupported component should not set opentelemetry-cpp_FOUND" - ) -endif()