tool_version_check.cmake 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function(check_expected_tool_version tool_name tool_path)
  2. # Function to check the tool used the expected version and warn otherwise
  3. set(tool_version_warning "Check Getting Started documentation or proceed at own risk.\n")
  4. set(tool_version_error "Check Getting Started documentation if the error continues.\n"
  5. "You can override this error and proceed with build by defining the IDF_MAINTAINER environment variable.\n")
  6. set(fixing_hint "Please try to run 'idf.py fullclean' to solve it.\n")
  7. idf_build_get_property(python PYTHON)
  8. idf_build_get_property(idf_path IDF_PATH)
  9. set(ENV{IDF_TOOLS_VERSION_HELPER} "1")
  10. # Use idf_tools.py to check if tool version is supported
  11. execute_process(
  12. COMMAND ${python} "${idf_path}/tools/idf_tools.py"
  13. "check-tool-supported" "--tool-name" "${tool_name}"
  14. "--exec-path" "${tool_path}"
  15. OUTPUT_VARIABLE is_version_supported
  16. OUTPUT_STRIP_TRAILING_WHITESPACE
  17. ERROR_QUIET)
  18. if(is_version_supported STREQUAL "False")
  19. # Version is not supported. Need to get supported versions list to print them to user
  20. execute_process(
  21. COMMAND ${python} "${idf_path}/tools/idf_tools.py"
  22. "get-tool-supported-versions" "--tool-name" "${tool_name}"
  23. OUTPUT_VARIABLE tool_supported_versions
  24. OUTPUT_STRIP_TRAILING_WHITESPACE
  25. ERROR_QUIET)
  26. # IDF maintainers can build projects with not supported versions with just a warning
  27. if($ENV{IDF_MAINTAINER})
  28. set(message_mode "WARNING")
  29. else()
  30. set(message_mode "FATAL_ERROR")
  31. endif()
  32. message(${message_mode} "\n"
  33. "Tool doesn't match supported version from list "
  34. "${tool_supported_versions}: ${tool_path}\n"
  35. ${fixing_hint})
  36. elseif(NOT is_version_supported STREQUAL "True")
  37. message(WARNING "Can not get version for tool: ${tool_path}\n" ${tool_version_warning})
  38. endif()
  39. unset(ENV{IDF_TOOLS_VERSION_HELPER})
  40. endfunction()