Merge branch 'feature/remove_make_dependency_on_git' into 'master'

make: remove build system dependency on `git` using some hooks

See merge request idf/esp-idf!2211
This commit is contained in:
Ivan Grokhotkov 2018-04-19 13:01:12 +08:00
commit 96b4a45cde
3 changed files with 27 additions and 2 deletions

View File

@ -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
-----------------------

View File

@ -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

View File

@ -209,6 +209,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:"