esp_common: add version definitions in code and build system

This commit is contained in:
Ivan Grokhotkov 2019-03-22 12:40:12 +08:00
parent caacfd87fa
commit 5f9003aa0a
15 changed files with 166 additions and 9 deletions

View file

@ -704,6 +704,18 @@ check_permissions:
script: script:
- tools/ci/check-executable.sh - tools/ci/check-executable.sh
check_version:
<<: *check_job_template
# Don't run this for feature/bugfix branches, so that it is possible to modify
# esp_idf_version.h in a branch before tagging the next version.
only:
- master
- /^release\/v/
- /^v\d+\.\d+(\.\d+)?($|-)/
script:
- export IDF_PATH=$PWD
- tools/ci/check_idf_version.sh
check_examples_cmake_make: check_examples_cmake_make:
<<: *check_job_template <<: *check_job_template
except: except:

View file

@ -0,0 +1,58 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/** Major version number (X.x.x) */
#define ESP_IDF_VERSION_MAJOR 3
/** Minor version number (x.X.x) */
#define ESP_IDF_VERSION_MINOR 2
/** Patch version number (x.x.X) */
#define ESP_IDF_VERSION_PATCH 3
/**
* Macro to convert IDF version number into an integer
*
* To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
*/
#define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
/**
* Current IDF version, as an integer
*
* To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
*/
#define ESP_IDF_VERSION ESP_IDF_VERSION_VAL(ESP_IDF_VERSION_MAJOR, \
ESP_IDF_VERSION_MINOR, \
ESP_IDF_VERSION_PATCH)
/**
* Return full IDF version string, same as 'git describe' output.
*
* @note If you are printing the ESP-IDF version in a log file or other information,
* this function provides more information than using the numerical version macros.
* For example, numerical version macros don't differentiate between development,
* pre-release and release versions, but the output of this function does.
*
* @return constant string from IDF_VER
*/
const char* esp_get_idf_version(void);
#ifdef __cplusplus
}
#endif

View file

@ -19,6 +19,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "esp_err.h" #include "esp_err.h"
#include "esp_sleep.h" #include "esp_sleep.h"
#include "esp_idf_version.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -292,14 +293,6 @@ esp_err_t esp_derive_local_mac(uint8_t* local_mac, const uint8_t* universal_mac)
const char* system_get_sdk_version(void) __attribute__ ((deprecated)); const char* system_get_sdk_version(void) __attribute__ ((deprecated));
/** @endcond */ /** @endcond */
/**
* Get IDF version
*
* @return constant string from IDF_VER
*/
const char* esp_get_idf_version(void);
/** /**
* @brief Chip models * @brief Chip models
*/ */

View file

@ -173,6 +173,8 @@ INPUT = \
## Base MAC address ## Base MAC address
## NOTE: for line below header_file.inc is not used ## NOTE: for line below header_file.inc is not used
../../components/esp32/include/esp_system.h \ ../../components/esp32/include/esp_system.h \
## IDF version
../../components/esp32/include/esp_idf_version.h \
## ##
## ULP Coprocessor - API Guides ## ULP Coprocessor - API Guides
## ##

View file

@ -319,6 +319,7 @@ The following variables are set at the project level, but available for use in c
- ``COMPONENTS``: Names of all components that are included in this build, formatted as a semicolon-delimited CMake list. - ``COMPONENTS``: Names of all components that are included in this build, formatted as a semicolon-delimited CMake list.
- ``CONFIG_*``: Each value in the project configuration has a corresponding variable available in make. All names begin with ``CONFIG_``. :doc:`More information here </api-reference/kconfig>`. - ``CONFIG_*``: Each value in the project configuration has a corresponding variable available in make. All names begin with ``CONFIG_``. :doc:`More information here </api-reference/kconfig>`.
- ``IDF_VER``: Git version of ESP-IDF (produced by ``git describe``) - ``IDF_VER``: Git version of ESP-IDF (produced by ``git describe``)
- ``IDF_VERSION_MAJOR``, ``IDF_VERSION_MINOR``, ``IDF_VERSION_PATCH``: Components of ESP-IDF version, to be used in conditional expressions. Note that this information is less precise than that provided by ``IDF_VER`` variable. ``v4.0-dev-*``, ``v4.0-beta1``, ``v4.0-rc1`` and ``v4.0`` will all have the same values of ``IDF_VERSION_*`` variables, but different ``IDF_VER`` values.
If you modify any of these variables inside ``CMakeLists.txt`` then this will not prevent other components from building but it may make your component hard to build and/or debug. If you modify any of these variables inside ``CMakeLists.txt`` then this will not prevent other components from building but it may make your component hard to build and/or debug.

View file

@ -187,6 +187,7 @@ The following variables are set at the project level, but exported for use in th
- ``CC``, ``LD``, ``AR``, ``OBJCOPY``: Full paths to each tool from the gcc xtensa cross-toolchain. - ``CC``, ``LD``, ``AR``, ``OBJCOPY``: Full paths to each tool from the gcc xtensa cross-toolchain.
- ``HOSTCC``, ``HOSTLD``, ``HOSTAR``: Full names of each tool from the host native toolchain. - ``HOSTCC``, ``HOSTLD``, ``HOSTAR``: Full names of each tool from the host native toolchain.
- ``IDF_VER``: ESP-IDF version, retrieved from either ``$(IDF_PATH)/version.txt`` file (if present) else using git command ``git describe``. Recommended format here is single liner that specifies major IDF release version, e.g. ``v2.0`` for a tagged release or ``v2.0-275-g0efaa4f`` for an arbitrary commit. Application can make use of this by calling :cpp:func:`esp_get_idf_version`. - ``IDF_VER``: ESP-IDF version, retrieved from either ``$(IDF_PATH)/version.txt`` file (if present) else using git command ``git describe``. Recommended format here is single liner that specifies major IDF release version, e.g. ``v2.0`` for a tagged release or ``v2.0-275-g0efaa4f`` for an arbitrary commit. Application can make use of this by calling :cpp:func:`esp_get_idf_version`.
- ``IDF_VERSION_MAJOR``, ``IDF_VERSION_MINOR``, ``IDF_VERSION_PATCH``: Components of ESP-IDF version, to be used in conditional expressions. Note that this information is less precise than that provided by ``IDF_VER`` variable. ``v4.0-dev-*``, ``v4.0-beta1``, ``v4.0-rc1`` and ``v4.0`` will all have the same values of ``ESP_IDF_VERSION_*`` variables, but different ``IDF_VER`` values.
If you modify any of these variables inside ``component.mk`` then this will not prevent other components from building but it may make your component hard to build and/or debug. If you modify any of these variables inside ``component.mk`` then this will not prevent other components from building but it may make your component hard to build and/or debug.

View file

@ -109,10 +109,26 @@ SDK version
:cpp:func:`esp_get_idf_version` returns a string describing the IDF version which was used to compile the application. This is the same value as the one available through ``IDF_VER`` variable of the build system. The version string generally has the format of ``git describe`` output. :cpp:func:`esp_get_idf_version` returns a string describing the IDF version which was used to compile the application. This is the same value as the one available through ``IDF_VER`` variable of the build system. The version string generally has the format of ``git describe`` output.
To get the version at build time, additional version macros are provided. They can be used to enable or disable parts of the program depending on IDF version.
* :c:macro:`ESP_IDF_VERSION_MAJOR`, :c:macro:`ESP_IDF_VERSION_MINOR`, :c:macro:`ESP_IDF_VERSION_PATCH` are defined to integers representing major, minor, and patch version.
* :c:macro:`ESP_IDF_VERSION_VAL` and :c:macro:`ESP_IDF_VERSION` can be used when implementing version checks:
.. code-block:: c
#include "esp_idf_version.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
// enable functionality present in IDF v4.0
#endif
API Reference API Reference
------------- -------------
.. include:: /_build/inc/esp_system.inc .. include:: /_build/inc/esp_system.inc
.. include:: /_build/inc/esp_idf_version.inc

View file

@ -176,6 +176,7 @@ ESP-IDF 搜索组件时,会按照 ``COMPONENT_DIRS`` 指定的顺序依次进
- ``CC````LD````AR````OBJCOPY`` gcc xtensa 交叉编译工具链中每个工具的完整路径。 - ``CC````LD````AR````OBJCOPY`` gcc xtensa 交叉编译工具链中每个工具的完整路径。
- ``HOSTCC````HOSTLD````HOSTAR`` 主机本地工具链中每个工具的全名。 - ``HOSTCC````HOSTLD````HOSTAR`` 主机本地工具链中每个工具的全名。
- ``IDF_VER`` ESP-IDF 的版本号,可以通过检索 ``$(IDF_PATH)/version.txt`` 文件(假如存在的话)或者使用 git 命令 ``git describe`` 来获取。这里推荐的格式是在一行中指定主 IDF 的发布版本号,例如标记为 ``v2.0`` 的发布版本或者是标记任意一次提交记录的 ``v2.0-275-g0efaa4f``。应用程序可以通过调用 :cpp:func:`esp_get_idf_version` 函数来使用该变量。 - ``IDF_VER`` ESP-IDF 的版本号,可以通过检索 ``$(IDF_PATH)/version.txt`` 文件(假如存在的话)或者使用 git 命令 ``git describe`` 来获取。这里推荐的格式是在一行中指定主 IDF 的发布版本号,例如标记为 ``v2.0`` 的发布版本或者是标记任意一次提交记录的 ``v2.0-275-g0efaa4f``。应用程序可以通过调用 :cpp:func:`esp_get_idf_version` 函数来使用该变量。
- ``IDF_VERSION_MAJOR``, ``IDF_VERSION_MINOR``, ``IDF_VERSION_PATCH``: ESP-IDF 的组件版本,可用于条件表达式。请注意这些信息的精确度不如 ``IDF_VER`` 变量,版本号 ``v4.0-dev-*`` ``v4.0-beta1`` ``v4.0-rc1````v4.0`` 对应的 ``IDF_VERSION_*`` 变量值是相同的,但是 ``IDF_VER`` 的值是不同的。
如果您在 ``component.mk`` 文件中修改这些变量,这并不会影响其它组件的编译,但可能会使您的组件变得难以编译或调试。 如果您在 ``component.mk`` 文件中修改这些变量,这并不会影响其它组件的编译,但可能会使您的组件变得难以编译或调试。

View file

@ -36,6 +36,9 @@ ifdef CONFIG_MAKE_WARN_UNDEFINED_VARIABLES
MAKEFLAGS += --warn-undefined-variables MAKEFLAGS += --warn-undefined-variables
endif endif
# Get version variables
include $(IDF_PATH)/make/version.mk
# General make utilities # General make utilities
# convenience variable for printing an 80 asterisk wide separator line # convenience variable for printing an 80 asterisk wide separator line

View file

@ -116,7 +116,7 @@ export PROJECT_PATH
endif endif
# A list of the "common" makefiles, to use as a target dependency # A list of the "common" makefiles, to use as a target dependency
COMMON_MAKEFILES := $(abspath $(IDF_PATH)/make/project.mk $(IDF_PATH)/make/common.mk $(IDF_PATH)/make/component_wrapper.mk $(firstword $(MAKEFILE_LIST))) COMMON_MAKEFILES := $(abspath $(IDF_PATH)/make/project.mk $(IDF_PATH)/make/common.mk $(IDF_PATH)/make/version.mk $(IDF_PATH)/make/component_wrapper.mk $(firstword $(MAKEFILE_LIST)))
export COMMON_MAKEFILES export COMMON_MAKEFILES
# The directory where we put all objects/libraries/binaries. The project Makefile can # The directory where we put all objects/libraries/binaries. The project Makefile can

3
make/version.mk Normal file
View file

@ -0,0 +1,3 @@
IDF_VERSION_MAJOR := 3
IDF_VERSION_MINOR := 2
IDF_VERSION_PATCH := 3

62
tools/ci/check_idf_version.sh Executable file
View file

@ -0,0 +1,62 @@
#!/bin/bash
set -u
set -e
echo "Checking if IDF version in esp_idf_version.h matches 'git describe' output"
function get_ver_from_header() {
# Get the 3rd word from '#define ESP_IDF_VERSION_X <number>' line.
grep -E "^#define ${1}" components/esp32/include/esp_idf_version.h | awk '{print $3;}'
}
function get_ver_from_make() {
grep -E "^${1} :=" make/version.mk | awk '{print $3;}'
}
function get_ver_from_cmake() {
grep -E "^set\(${1}" tools/cmake/version.cmake | sed -En "s/set\(${1} ([0-9])\)/\1/p"
}
header_ver_major=$(get_ver_from_header ESP_IDF_VERSION_MAJOR)
header_ver_minor=$(get_ver_from_header ESP_IDF_VERSION_MINOR)
header_ver_patch=$(get_ver_from_header ESP_IDF_VERSION_PATCH)
version_from_header="${header_ver_major}.${header_ver_minor}.${header_ver_patch}"
make_ver_major=$(get_ver_from_make IDF_VERSION_MAJOR)
make_ver_minor=$(get_ver_from_make IDF_VERSION_MINOR)
make_ver_patch=$(get_ver_from_make IDF_VERSION_PATCH)
version_from_make="${make_ver_major}.${make_ver_minor}.${make_ver_patch}"
cmake_ver_major=$(get_ver_from_cmake IDF_VERSION_MAJOR)
cmake_ver_minor=$(get_ver_from_cmake IDF_VERSION_MINOR)
cmake_ver_patch=$(get_ver_from_cmake IDF_VERSION_PATCH)
version_from_cmake="${cmake_ver_major}.${cmake_ver_minor}.${cmake_ver_patch}"
git_desc=$(git describe --tags)
git_desc_regex="^v([0-9]+)\.([0-9]+)(\.([0-9]+))?.*$"
if [[ ! ${git_desc} =~ ${git_desc_regex} ]]; then
echo "Could not determine the version from 'git describe' output: ${git_desc}"
exit 1
fi
version_from_git="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[4]:-0}"
echo "From esp_idf_version.h: ${version_from_header}"
echo "From version.mk: ${version_from_make}"
echo "From version.cmake: ${version_from_cmake}"
echo "From git describe: ${version_from_git}"
if [[ "${version_from_header}" != "${version_from_git}" ]]; then
echo "esp_idf_version.h does not match 'git describe' output"
exit 1
fi
if [[ "${version_from_make}" != "${version_from_git}" ]]; then
echo "version.mk does not match 'git describe' output"
exit 1
fi
if [[ "${version_from_cmake}" != "${version_from_git}" ]]; then
echo "version.cmake does not match 'git describe' output"
exit 1
fi

View file

@ -18,6 +18,7 @@ docs/gen-version-specific-includes.py
tools/ci/apply_bot_filter.py tools/ci/apply_bot_filter.py
tools/ci/build_examples.sh tools/ci/build_examples.sh
tools/ci/build_examples_cmake.sh tools/ci/build_examples_cmake.sh
tools/ci/check_idf_version.sh
tools/ci/check-executable.sh tools/ci/check-executable.sh
tools/ci/check-line-endings.sh tools/ci/check-line-endings.sh
tools/ci/checkout_project_ref.py tools/ci/checkout_project_ref.py

View file

@ -26,6 +26,7 @@ include(components)
include(kconfig) include(kconfig)
include(git_submodules) include(git_submodules)
include(idf_functions) include(idf_functions)
include(version)
set_default(PYTHON "python") set_default(PYTHON "python")

View file

@ -0,0 +1,3 @@
set(IDF_VERSION_MAJOR 3)
set(IDF_VERSION_MINOR 2)
set(IDF_VERSION_PATCH 3)