From bcbcdf6f990d98fad2d4530a8c1ae042ac4aeaad Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 12 Apr 2018 14:15:41 +0800 Subject: [PATCH] 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. --- make/component_wrapper.mk | 15 +++++++++------ tools/ci/test_build_system.sh | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/make/component_wrapper.mk b/make/component_wrapper.mk index b23872c798..f2b2364202 100644 --- a/make/component_wrapper.mk +++ b/make/component_wrapper.mk @@ -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))) diff --git a/tools/ci/test_build_system.sh b/tools/ci/test_build_system.sh index d2e75ddf91..d83198bf46 100755 --- a/tools/ci/test_build_system.sh +++ b/tools/ci/test_build_system.sh @@ -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:"