]> granicus.if.org Git - esp-idf/commitdiff
build: fix excluding source files outside of component root
authorIvan Grokhotkov <ivan@espressif.com>
Thu, 12 Apr 2018 06:15:41 +0000 (14:15 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 12 Apr 2018 06:28:54 +0000 (14:28 +0800)
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
tools/ci/test_build_system.sh

index b23872c798975e94c314c0219e35693ff817c448..f2b23642022ee300e6a63fc804b7d3ded4d71700 100644 (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)))
index d2e75ddf9101c51f34ee39780e7c348fb3993a60..d83198bf46bd6888772744f7958ae3a103bd0031 100755 (executable)
@@ -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:"