1#!/usr/bin/env bash 2 3set -u 4set -e 5 6echo "Checking if IDF version in esp_idf_version.h matches 'git describe' output" 7 8function get_ver_from_header() { 9 # Get the 3rd word from '#define ESP_IDF_VERSION_X <number>' line. 10 grep -E "^#define ${1}" components/esp_common/include/esp_idf_version.h | awk '{print $3;}' 11} 12 13function get_ver_from_make() { 14 grep -E "^${1} :=" make/version.mk | awk '{print $3;}' 15} 16 17function get_ver_from_cmake() { 18 grep -E "^set\(${1}" tools/cmake/version.cmake | sed -En "s/set\(${1} ([0-9])\)/\1/p" 19} 20 21header_ver_major=$(get_ver_from_header ESP_IDF_VERSION_MAJOR) 22header_ver_minor=$(get_ver_from_header ESP_IDF_VERSION_MINOR) 23header_ver_patch=$(get_ver_from_header ESP_IDF_VERSION_PATCH) 24version_from_header="${header_ver_major}.${header_ver_minor}.${header_ver_patch}" 25 26make_ver_major=$(get_ver_from_make IDF_VERSION_MAJOR) 27make_ver_minor=$(get_ver_from_make IDF_VERSION_MINOR) 28make_ver_patch=$(get_ver_from_make IDF_VERSION_PATCH) 29version_from_make="${make_ver_major}.${make_ver_minor}.${make_ver_patch}" 30 31cmake_ver_major=$(get_ver_from_cmake IDF_VERSION_MAJOR) 32cmake_ver_minor=$(get_ver_from_cmake IDF_VERSION_MINOR) 33cmake_ver_patch=$(get_ver_from_cmake IDF_VERSION_PATCH) 34version_from_cmake="${cmake_ver_major}.${cmake_ver_minor}.${cmake_ver_patch}" 35 36git_desc=$(git describe) 37git_desc_regex="^v([0-9]+)\.([0-9]+)(\.([0-9]+))?.*$" 38if [[ ! ${git_desc} =~ ${git_desc_regex} ]]; then 39 echo "Could not determine the version from 'git describe' output: ${git_desc}" 40 exit 1 41fi 42version_from_git="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[4]:-0}" 43 44echo "From esp_idf_version.h: ${version_from_header}" 45echo "From version.mk: ${version_from_make}" 46echo "From version.cmake: ${version_from_cmake}" 47echo "From git describe: ${version_from_git}" 48 49if [[ "${version_from_header}" != "${version_from_git}" ]]; then 50 echo "esp_idf_version.h does not match 'git describe' output" 51 exit 1 52fi 53 54if [[ "${version_from_make}" != "${version_from_git}" ]]; then 55 echo "version.mk does not match 'git describe' output" 56 exit 1 57fi 58 59if [[ "${version_from_cmake}" != "${version_from_git}" ]]; then 60 echo "version.cmake does not match 'git describe' output" 61 exit 1 62fi 63