Merge branch 'feature/cut_len_for_header_struct' into 'master'

build: Add trimming PROJECT_VER and PROJECT_NAME vars

See merge request idf/esp-idf!3927
This commit is contained in:
Angus Gratton 2018-12-21 07:45:22 +08:00
commit 78487123bf
11 changed files with 67 additions and 19 deletions

View file

@ -75,7 +75,9 @@ idf_get_git_revision()
idf_check_config_target() idf_check_config_target()
## get PROJECT_VER ## get PROJECT_VER
app_get_revision("${CMAKE_SOURCE_DIR}") if(NOT BOOTLOADER_BUILD)
app_get_revision("${CMAKE_SOURCE_DIR}")
endif()
# Add some idf-wide definitions # Add some idf-wide definitions
idf_set_global_compile_options() idf_set_global_compile_options()

View file

@ -10,10 +10,14 @@ register_component()
# linker will ignore this structure as it has no other files depending on it. # linker will ignore this structure as it has no other files depending on it.
target_link_libraries(${COMPONENT_TARGET} "-u esp_app_desc") target_link_libraries(${COMPONENT_TARGET} "-u esp_app_desc")
# cut PROJECT_VER and PROJECT_NAME to required 32 characters.
string(SUBSTRING "${PROJECT_VER}" 0 31 PROJECT_VER_CUT)
string(SUBSTRING "${PROJECT_NAME}" 0 31 PROJECT_NAME_CUT)
set_source_files_properties( set_source_files_properties(
SOURCE "esp_app_desc.c" SOURCE "esp_app_desc.c"
PROPERTIES COMPILE_DEFINITIONS PROPERTIES COMPILE_DEFINITIONS
PROJECT_VER=\"${PROJECT_VER}\") "PROJECT_VER=\"${PROJECT_VER_CUT}\"; PROJECT_NAME=\"${PROJECT_NAME_CUT}\"")
# Add custom target for generating empty otadata partition for flashing # Add custom target for generating empty otadata partition for flashing
if(OTADATA_PARTITION_OFFSET AND OTADATA_PARTITION_SIZE) if(OTADATA_PARTITION_OFFSET AND OTADATA_PARTITION_SIZE)

View file

@ -9,4 +9,18 @@ config APP_COMPILE_TIME_DATE
This can be useful for getting the same binary image files made from the same source, This can be useful for getting the same binary image files made from the same source,
but at different times. but at different times.
config APP_EXCLUDE_PROJECT_VER_VAR
bool "Exclude PROJECT_VER from firmware image"
default n
help
The PROJECT_VER variable from the build system will not affect the firmware image.
This value will not be contained in the esp_app_desc structure.
config APP_EXCLUDE_PROJECT_NAME_VAR
bool "Exclude PROJECT_NAME from firmware image"
default n
help
The PROJECT_NAME variable from the build system will not affect the firmware image.
This value will not be contained in the esp_app_desc structure.
endmenu # "Application manager" endmenu # "Application manager"

View file

@ -11,11 +11,13 @@ ifndef IS_BOOTLOADER_BUILD
GET_PROJECT_VER ?= GET_PROJECT_VER ?=
ifeq ("${PROJECT_VER}", "") ifeq ("${PROJECT_VER}", "")
ifeq ("$(wildcard ${PROJECT_PATH}/version.txt)","") ifeq ("$(wildcard ${PROJECT_PATH}/version.txt)","")
GET_PROJECT_VER := $(shell cd ${PROJECT_PATH} && git describe --always --tags --dirty || echo "Not found git repo")
ifeq ("${GET_PROJECT_VER}", "Not found git repo") GET_PROJECT_VER := $(shell cd ${PROJECT_PATH} && git describe --always --tags --dirty 2> /dev/null)
$(info Project do not have git repo, it needs to get PROJECT_VER from `git describe` command.) ifeq ("${GET_PROJECT_VER}", "")
GET_PROJECT_VER := "" GET_PROJECT_VER := "1"
$(info Project is not inside a git repository, will not use 'git describe' to determine PROJECT_VER.)
endif endif
else else
# read from version.txt # read from version.txt
GET_PROJECT_VER := $(shell cat ${PROJECT_PATH}/version.txt) GET_PROJECT_VER := $(shell cat ${PROJECT_PATH}/version.txt)
@ -24,16 +26,21 @@ endif
# If ``PROJECT_VER`` variable set in project Makefile file, its value will be used. # If ``PROJECT_VER`` variable set in project Makefile file, its value will be used.
# Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``. # Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``.
# Else, if the project is located inside a Git repository, the output of git describe will be used. # Else, if the project is located inside a Git repository, the output of git describe will be used.
# Otherwise, ``PROJECT_VER`` will be empty. # Otherwise, ``PROJECT_VER`` will be "1".
ifeq ("${PROJECT_VER}", "") ifeq ("${PROJECT_VER}", "")
PROJECT_VER:= $(GET_PROJECT_VER) PROJECT_VER:= $(GET_PROJECT_VER)
else else
PROJECT_VER:= $(PROJECT_VER) PROJECT_VER:= $(PROJECT_VER)
endif endif
$(info App "$(PROJECT_NAME)" version: $(PROJECT_VER))
NEW_DEFINES:= $(PROJECT_VER) $(PROJECT_NAME) $(IDF_VER) # cut PROJECT_VER and PROJECT_NAME to required 32 characters.
PROJECT_VER_CUT := $(shell echo $(PROJECT_VER) | cut -c 1-31)
PROJECT_NAME_CUT := $(shell echo $(PROJECT_NAME) | cut -c 1-31)
$(info App "$(PROJECT_NAME_CUT)" version: $(PROJECT_VER_CUT))
NEW_DEFINES:= $(PROJECT_VER_CUT) $(PROJECT_NAME_CUT) $(IDF_VER)
ifeq ("$(wildcard ${TMP_DEFINES})","") ifeq ("$(wildcard ${TMP_DEFINES})","")
OLD_DEFINES:= OLD_DEFINES:=
else else
@ -45,5 +52,5 @@ ifneq ("${NEW_DEFINES}", "${OLD_DEFINES}")
$(shell echo $(NEW_DEFINES) > $(TMP_DEFINES); rm -f esp_app_desc.o;) $(shell echo $(NEW_DEFINES) > $(TMP_DEFINES); rm -f esp_app_desc.o;)
endif endif
esp_app_desc.o: CPPFLAGS += -D PROJECT_VER=\"$(PROJECT_VER)\" -D PROJECT_NAME=\"$(PROJECT_NAME)\" esp_app_desc.o: CPPFLAGS += -D PROJECT_VER=\"$(PROJECT_VER_CUT)\" -D PROJECT_NAME=\"$(PROJECT_NAME_CUT)\"
endif endif

View file

@ -19,8 +19,17 @@
// Application version info // Application version info
const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = { const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
.magic_word = ESP_APP_DESC_MAGIC_WORD, .magic_word = ESP_APP_DESC_MAGIC_WORD,
#ifdef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
.version = "",
#else
.version = PROJECT_VER, .version = PROJECT_VER,
#endif
#ifdef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
.project_name = "",
#else
.project_name = PROJECT_NAME, .project_name = PROJECT_NAME,
#endif
.idf_ver = IDF_VER, .idf_ver = IDF_VER,
#ifdef CONFIG_APP_SECURE_VERSION #ifdef CONFIG_APP_SECURE_VERSION
@ -39,9 +48,13 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
}; };
#ifndef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
_Static_assert(sizeof(PROJECT_VER) <= sizeof(esp_app_desc.version), "PROJECT_VER is longer than version field in structure"); _Static_assert(sizeof(PROJECT_VER) <= sizeof(esp_app_desc.version), "PROJECT_VER is longer than version field in structure");
#endif
_Static_assert(sizeof(IDF_VER) <= sizeof(esp_app_desc.idf_ver), "IDF_VER is longer than idf_ver field in structure"); _Static_assert(sizeof(IDF_VER) <= sizeof(esp_app_desc.idf_ver), "IDF_VER is longer than idf_ver field in structure");
#ifndef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
_Static_assert(sizeof(PROJECT_NAME) <= sizeof(esp_app_desc.project_name), "PROJECT_NAME is longer than project_name field in structure"); _Static_assert(sizeof(PROJECT_NAME) <= sizeof(esp_app_desc.project_name), "PROJECT_NAME is longer than project_name field in structure");
#endif
const esp_app_desc_t *esp_ota_get_app_description(void) const esp_app_desc_t *esp_ota_get_app_description(void)
{ {

View file

@ -179,8 +179,12 @@ void IRAM_ATTR call_start_cpu0()
if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {
const esp_app_desc_t *app_desc = esp_ota_get_app_description(); const esp_app_desc_t *app_desc = esp_ota_get_app_description();
ESP_EARLY_LOGI(TAG, "Application information:"); ESP_EARLY_LOGI(TAG, "Application information:");
#ifndef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
ESP_EARLY_LOGI(TAG, "Project name: %s", app_desc->project_name); ESP_EARLY_LOGI(TAG, "Project name: %s", app_desc->project_name);
#endif
#ifndef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
ESP_EARLY_LOGI(TAG, "App version: %s", app_desc->version); ESP_EARLY_LOGI(TAG, "App version: %s", app_desc->version);
#endif
#ifdef CONFIG_APP_SECURE_VERSION #ifdef CONFIG_APP_SECURE_VERSION
ESP_EARLY_LOGI(TAG, "Secure version: %x", app_desc->secure_version); ESP_EARLY_LOGI(TAG, "Secure version: %x", app_desc->secure_version);
#endif #endif

View file

@ -347,7 +347,7 @@ The following variables are set at the project level, but available for use in c
* If ``PROJECT_VER`` variable set in project CMakeLists.txt file, its value will be used. * If ``PROJECT_VER`` variable set in project CMakeLists.txt file, its value will be used.
* Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``. * Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``.
* Else, if the project is located inside a Git repository, the output of git describe will be used. * Else, if the project is located inside a Git repository, the output of git describe will be used.
* Otherwise, ``PROJECT_VER`` will be empty. * Otherwise, ``PROJECT_VER`` will be "1".
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

@ -192,7 +192,7 @@ The following variables are set at the project level, but exported for use in th
* If ``PROJECT_VER`` variable set in project Makefile file, its value will be used. * If ``PROJECT_VER`` variable set in project Makefile file, its value will be used.
* Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``. * Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``.
* Else, if the project is located inside a Git repository, the output of git describe will be used. * Else, if the project is located inside a Git repository, the output of git describe will be used.
* Otherwise, ``PROJECT_VER`` will be empty. * Otherwise, ``PROJECT_VER`` will be "1".
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

@ -247,7 +247,7 @@ function run_tests()
assert_rebuilt ${APP_BINS} assert_rebuilt ${APP_BINS}
print_status "Change app version" print_status "Change app version"
take_build_snapshot take_build_snapshot
echo "project-version-2.0" > ${TESTDIR}/template/version.txt echo "project-version-2.0(012345678901234567890123456789)" > ${TESTDIR}/template/version.txt
make make
assert_rebuilt ${APP_BINS} assert_rebuilt ${APP_BINS}
assert_not_rebuilt ${BOOTLOADER_BINS} esp32/libesp32.a assert_not_rebuilt ${BOOTLOADER_BINS} esp32/libesp32.a

View file

@ -103,7 +103,7 @@ function run_tests()
idf.py build || failure "Failed to build with app version" idf.py build || failure "Failed to build with app version"
print_status "Change app version" print_status "Change app version"
take_build_snapshot take_build_snapshot
echo "project-version-2.0" > ${TESTDIR}/template/version.txt echo "project-version-2.0(012345678901234567890123456789)" > ${TESTDIR}/template/version.txt
idf.py build || failure "Failed to rebuild with changed app version" idf.py build || failure "Failed to rebuild with changed app version"
assert_rebuilt ${APP_BINS} assert_rebuilt ${APP_BINS}
assert_not_rebuilt ${BOOTLOADER_BINS} esp-idf/esp32/libesp32.a assert_not_rebuilt ${BOOTLOADER_BINS} esp-idf/esp32/libesp32.a

View file

@ -87,7 +87,6 @@ function(idf_set_global_compile_options)
list(APPEND compile_options "${CMAKE_C_FLAGS}") list(APPEND compile_options "${CMAKE_C_FLAGS}")
list(APPEND c_compile_options "${CMAKE_C_FLAGS}") list(APPEND c_compile_options "${CMAKE_C_FLAGS}")
list(APPEND cxx_compile_options "${CMAKE_CXX_FLAGS}") list(APPEND cxx_compile_options "${CMAKE_CXX_FLAGS}")
add_definitions(-DPROJECT_NAME=\"${PROJECT_NAME}\")
if(CONFIG_OPTIMIZATION_LEVEL_RELEASE) if(CONFIG_OPTIMIZATION_LEVEL_RELEASE)
list(APPEND compile_options "-Os") list(APPEND compile_options "-Os")
@ -240,19 +239,24 @@ endfunction()
# If PROJECT_VER variable set in project CMakeLists.txt file, its value will be used. # If PROJECT_VER variable set in project CMakeLists.txt file, its value will be used.
# Else, if the _project_path/version.txt exists, its contents will be used as PROJECT_VER. # Else, if the _project_path/version.txt exists, its contents will be used as PROJECT_VER.
# Else, if the project is located inside a Git repository, the output of git describe will be used. # Else, if the project is located inside a Git repository, the output of git describe will be used.
# Otherwise, PROJECT_VER will be empty. # Otherwise, PROJECT_VER will be "1".
function(app_get_revision _project_path) function(app_get_revision _project_path)
git_describe(PROJECT_VER_GIT "${_project_path}")
if(NOT DEFINED PROJECT_VER) if(NOT DEFINED PROJECT_VER)
if(EXISTS "${_project_path}/version.txt") if(EXISTS "${_project_path}/version.txt")
file(STRINGS "${_project_path}/version.txt" PROJECT_VER) file(STRINGS "${_project_path}/version.txt" PROJECT_VER)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_project_path}/version.txt") set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_project_path}/version.txt")
else() else()
set(PROJECT_VER ${PROJECT_VER_GIT}) git_describe(PROJECT_VER_GIT "${_project_path}")
if(PROJECT_VER_GIT)
set(PROJECT_VER ${PROJECT_VER_GIT})
else()
message(STATUS "Project is not inside a git repository, \
will not use 'git describe' to determine PROJECT_VER.")
set(PROJECT_VER "1")
endif()
endif() endif()
endif() endif()
message(STATUS "Project version: ${PROJECT_VER}") message(STATUS "Project version: ${PROJECT_VER}")
git_submodule_check("${_project_path}")
set(PROJECT_VER ${PROJECT_VER} PARENT_SCOPE) set(PROJECT_VER ${PROJECT_VER} PARENT_SCOPE)
endfunction() endfunction()