build: fix excluding source files outside of component root

Since !2190, source files located outside of the component root
produce object files inside build directory. This change fixes
handling of COMPONENT_OBJEXCLUDE variable for such files. Tests are
added.
This commit is contained in:
Ivan Grokhotkov 2018-04-12 14:15:41 +08:00
parent 234723c061
commit bcbcdf6f99
2 changed files with 31 additions and 6 deletions

View File

@ -123,18 +123,21 @@ else
# Add in components defined by conditional compiling macros
COMPONENT_OBJS += $(COMPONENT_OBJINCLUDE)
endif
# Remove items disabled by optional compilation
COMPONENT_OBJS := $(foreach obj,$(COMPONENT_OBJS),$(if $(filter $(realpath $(obj)),$(realpath $(COMPONENT_OBJEXCLUDE))), ,$(obj)))
# Remove duplicates
COMPONENT_OBJS := $(call uniq,$(COMPONENT_OBJS))
# Remove any leading ../ from paths, so everything builds inside build dir
COMPONENT_OBJS := $(call stripLeadingParentDirs,$(COMPONENT_OBJS))
# Do the same for COMPONENT_OBJEXCLUDE (used below)
COMPONENT_OBJEXCLUDE := $(call stripLeadingParentDirs,$(COMPONENT_OBJEXCLUDE))
# COMPONENT_OBJDIRS is COMPONENT_SRCDIRS with the same transform applied
COMPONENT_OBJDIRS := $(call stripLeadingParentDirs,$(COMPONENT_SRCDIRS))
# Remove items disabled by optional compilation
COMPONENT_OBJS := $(foreach obj,$(COMPONENT_OBJS),$(if $(filter $(abspath $(obj)),$(abspath $(COMPONENT_OBJEXCLUDE))), ,$(obj)))
# Remove duplicates
COMPONENT_OBJS := $(call uniq,$(COMPONENT_OBJS))
# Object files with embedded binaries to add to the component library
# Correspond to the files named in COMPONENT_EMBED_FILES & COMPONENT_EMBED_TXTFILES
COMPONENT_EMBED_OBJS ?= $(addsuffix .bin.o,$(notdir $(COMPONENT_EMBED_FILES))) $(addsuffix .txt.o,$(notdir $(COMPONENT_EMBED_TXTFILES)))

View File

@ -183,6 +183,28 @@ function run_tests()
assert_rebuilt nvs_flash/src/nvs_api.o
assert_rebuilt freertos/xtensa_vectors.o
print_status "Can include/exclude object files"
echo "#error This file should not compile" > main/excluded_file.c
echo "int required_global;" > main/included_file.c
echo "COMPONENT_OBJEXCLUDE := excluded_file.o" >> main/component.mk
echo "COMPONENT_OBJINCLUDE := included_file.o" >> main/component.mk
echo "COMPONENT_ADD_LDFLAGS := -l\$(COMPONENT_NAME) -u required_global" >> main/component.mk
make
git checkout main/component.mk
rm main/{included,excluded}_file.c
print_status "Can include/exclude object files outside of component tree"
mkdir -p extra_source_dir
echo "#error This file should not compile" > extra_source_dir/excluded_file.c
echo "int required_global;" > extra_source_dir/included_file.c
echo "COMPONENT_SRCDIRS := . ../extra_source_dir" >> main/component.mk
echo "COMPONENT_OBJEXCLUDE := ../extra_source_dir/excluded_file.o" >> main/component.mk
echo "COMPONENT_OBJINCLUDE := ../extra_source_dir/included_file.o" >> main/component.mk
echo "COMPONENT_ADD_LDFLAGS := -l\$(COMPONENT_NAME) -u required_global" >> main/component.mk
make
git checkout main/component.mk
rm -rf extra_source_dir
print_status "All tests completed"
if [ -n "${FAILURES}" ]; then
echo "Some failures were detected:"