-
Notifications
You must be signed in to change notification settings - Fork 591
[CMAKE] Add support for CMake component deprecation and update the policy #4272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d89c800
a30f9fb
8832698
e585b0d
84199e2
47a21c1
634abea
72cdd88
1b861d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}) | ||
|
dbarker marked this conversation as resolved.
|
||
| list(APPEND _result ${${_replacement_var}}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it OK to change the order? |
||
| 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 <package>_<component>_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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to use a map-based approach here to avoid the |
||
| 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,8 +83,10 @@ 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) | ||
| 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() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,28 +317,43 @@ endfunction() | |
|
|
||
| #----------------------------------------------------------------------- | ||
| # otel_add_component: | ||
| # Adds a component to the list of components to be installed. A component name and list of targest are required. | ||
| # Adds a component to the list of components to be installed. A component name and list of targets are required. | ||
| # Optional files can be added to the component by specifying a directory, destination and matching pattern. | ||
| # Each target is assigned to the component and its dependencies are identified based on the LINK_LIBRARIES property. | ||
| # An alias target is also created for each target in the form of PROJECT_NAME::TARGET_EXPORT_NAME. | ||
| # DEPRECATED_NAMES lists old component names that are redirected to this component with a deprecation warning. | ||
| # | ||
| # TODO: add a DEPRECATED tag to support deprecated components that are still installed but will be removed in the future. | ||
| # | ||
| # Usage: | ||
| # otel_add_component( | ||
| # COMPONENT <component_name> | ||
| # [DEPRECATED_NAMES <old_name1> <old_name2> ...] | ||
| # TARGETS <target1> <target2> ... | ||
| # FILES_DIRECTORY <directory> | ||
| # FILES_DESTINATION <destination> | ||
| # FILES_MATCHING <matching>) | ||
| # [FILES_DIRECTORY <directory> | ||
| # FILES_DESTINATION <destination> | ||
| # FILES_MATCHING <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) | ||
| message(FATAL_ERROR "otel_add_component: COMPONENT is required") | ||
| endif() | ||
|
|
||
| # TODO: Support deprecated components that still install their targets, and mark those targets deprecated during the deprecation window. | ||
| # | ||
| # if(_OTEL_ADD_COMP_DEPRECATED) | ||
| # get_property(_deprecated_components DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) | ||
| # list(APPEND _deprecated_components "${_OTEL_ADD_COMP_COMPONENT}") | ||
| # set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST "${_deprecated_components}") | ||
| # message(DEBUG " DEPRECATED: ${_OTEL_ADD_COMP_COMPONENT} (no replacement)") | ||
| # return() | ||
| # endif() | ||
|
|
||
| if(NOT _OTEL_ADD_COMP_TARGETS) | ||
| message(FATAL_ERROR "otel_add_component: TARGETS is required") | ||
| endif() | ||
|
|
@@ -378,6 +393,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 +445,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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alias resolver is single-pass over the original request list: |
||
| 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" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if()re-dereferences an unquoted left operand that names a defined variable, soif(${_COMPONENT} IN_LIST ...)can take the wrong branch.