From 344e757a6a1faaadae863a3b52c84c8b6091a70d Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Tue, 10 Apr 2018 08:50:59 +0530 Subject: [PATCH 1/3] make: remove build system dependency on `git` using some hooks Currently for checking IDF version and submodules existence, build system uses `git` commands. But, it could be possible use-case where `git` is not installed (assuming IDF is flattened in source format) on system and build happens without any warnings. Signed-off-by: Mahavir Jain --- make/project.mk | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/make/project.mk b/make/project.mk index 36cfce7205..ff7aa6ed44 100644 --- a/make/project.mk +++ b/make/project.mk @@ -227,7 +227,12 @@ endif @echo $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS) +# If we have `version.txt` then prefer that for extracting IDF version +ifeq ("$(wildcard ${IDF_PATH}/version.txt)","") IDF_VER := $(shell cd ${IDF_PATH} && git describe --always --tags --dirty) +else +IDF_VER := `cat ${IDF_PATH}/version.txt` +endif # Set default LDFLAGS EXTRA_LDFLAGS ?= @@ -485,6 +490,8 @@ clean: app-clean bootloader-clean config-clean # # This only works for components inside IDF_PATH check-submodules: +# Check if .gitmodules exists, otherwise skip submodule check, assuming flattened structure +ifneq ("$(wildcard ${IDF_PATH}/.gitmodules)","") # Dump the git status for the whole working copy once, then grep it for each submodule. This saves a lot of time on Windows. GIT_STATUS := $(shell cd ${IDF_PATH} && git status --porcelain --ignore-submodules=dirty) @@ -509,6 +516,7 @@ endef # filter/subst in expression ensures all submodule paths begin with $(IDF_PATH), and then strips that prefix # so the argument is suitable for use with 'git submodule' commands $(foreach submodule,$(subst $(IDF_PATH)/,,$(filter $(IDF_PATH)/%,$(COMPONENT_SUBMODULES))),$(eval $(call GenerateSubmoduleCheckTarget,$(submodule)))) +endif # End check for .gitmodules existence # PHONY target to list components in the build and their paths From 4a7ca68596db73c4fcdb645d47156321c3a71f47 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Thu, 12 Apr 2018 18:26:43 +0530 Subject: [PATCH 2/3] tools/ci: add test case for build without dependency on `git` Signed-off-by: Mahavir Jain --- tools/ci/test_build_system.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/ci/test_build_system.sh b/tools/ci/test_build_system.sh index d83198bf46..a6640b4ed2 100755 --- a/tools/ci/test_build_system.sh +++ b/tools/ci/test_build_system.sh @@ -205,6 +205,23 @@ function run_tests() git checkout main/component.mk rm -rf extra_source_dir + print_status "Can build without git installed on system" + clean_build_dir + # Make provision for getting IDF version + echo "custom-version-x.y" > ${IDF_PATH}/version.txt + # Hide .gitmodules so that submodule check is avoided + [ -f ${IDF_PATH}/.gitmodules ] && mv ${IDF_PATH}/.gitmodules ${IDF_PATH}/.gitmodules_backup + # Overload `git` command + echo -e '#!/bin/bash\ntouch ${IDF_PATH}/git_invoked' > git + chmod +x git + OLD_PATH=$PATH + export PATH="$PWD:$PATH" + make + [ -f ${IDF_PATH}/git_invoked ] && rm ${IDF_PATH}/git_invoked && failure "git should not have been invoked in this case" + rm -f ${IDF_PATH}/version.txt git + [ -f ${IDF_PATH}/.gitmodules_backup ] && mv ${IDF_PATH}/.gitmodules_backup ${IDF_PATH}/.gitmodules + export PATH=$OLD_PATH + print_status "All tests completed" if [ -n "${FAILURES}" ]; then echo "Some failures were detected:" From 8fd4ee1b1ffc98eab63e0ad1b232edc9ba1c6000 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Wed, 18 Apr 2018 18:30:58 +0530 Subject: [PATCH 3/3] docs: add note regarding ESP-IDF version Signed-off-by: Mahavir Jain --- docs/en/api-guides/build-system.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index ca967f071b..e638a36d07 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -185,7 +185,7 @@ The following variables are set at the project level, but exported for use in th - ``CONFIG_*``: Each value in the project configuration has a corresponding variable available in make. All names begin with ``CONFIG_``. - ``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. -- ``IDF_VER``: Git version of ESP-IDF (produced by ``git describe``) +- ``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`. 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. @@ -298,7 +298,7 @@ Preprocessor Definitions ESP-IDF build systems adds the following C preprocessor definitions on the command line: - ``ESP_PLATFORM`` — Can be used to detect that build happens within ESP-IDF. -- ``IDF_VER`` — Defined to a git version string. E.g. ``v2.0`` for a tagged release or ``v1.0-275-g0efaa4f`` for an arbitrary commit. +- ``IDF_VER`` — ESP-IDF version, see `Preset Component Variables`_ for more details. Build Process Internals -----------------------