Преглед изворни кода

cmake: swap priority between EXTRA_COMPONENT_DIRS and project components

Renz Bagaporo пре 4 година
родитељ
комит
b5c3d4f615

+ 1 - 1
docs/en/api-guides/build-system.rst

@@ -343,7 +343,7 @@ When CMake runs to configure the project, it logs the components included in the
 Multiple components with the same name
 --------------------------------------
 
-When ESP-IDF is collecting all the components to compile, it will do this in the order specified by ``COMPONENT_DIRS``; by default, this means ESP-IDF's internal components first, then the project's components, and finally any components set in ``EXTRA_COMPONENT_DIRS``. If two or more of these directories contain component sub-directories with the same name, the component in the last place searched is used. This allows, for example, overriding ESP-IDF components with a modified version by copying that component from the ESP-IDF components directory to the project components directory and then modifying it there. If used in this way, the ESP-IDF directory itself can remain untouched.
+When ESP-IDF is collecting all the components to compile, it will do this in the order specified by ``COMPONENT_DIRS``; by default, this means ESP-IDF's internal components first (``IDF_PATH/components``), then any components in directories specified in ``EXTRA_COMPONENT_DIRS``, and finally the project's components (``PROJECT_DIR/components``). If two or more of these directories contain component sub-directories with the same name, the component in the last place searched is used. This allows, for example, overriding ESP-IDF components with a modified version by copying that component from the ESP-IDF components directory to the project components directory and then modifying it there. If used in this way, the ESP-IDF directory itself can remain untouched.
 
 .. note:: If a component is overridden in an existing project by moving it to a new location, the project will not automatically see the new component path. Run ``idf.py reconfigure`` (or delete the project build folder) and then build again.
 

+ 13 - 0
tools/ci/test_build_system.sh

@@ -419,6 +419,19 @@ endmenu\n" >> ${IDF_PATH}/Kconfig;
     git checkout -- sdkconfig.rename Kconfig
     popd
 
+    print_status "Project components prioritized over EXTRA_COMPONENT_DIRS"
+    clean_build_dir
+    mkdir -p extra_dir/my_component
+    echo "COMPONENT_CONFIG_ONLY := 1" > extra_dir/my_component/component.mk
+    cp Makefile Makefile.bak # set EXTRA_COMPONENT_DIRS to point to the other directory
+    sed -i "s%PROJECT_NAME := app-template%PROJECT_NAME := app-template\nEXTRA_COMPONENT_DIRS := extra_dir%" Makefile
+    (make list-components | grep "$PWD/extra_dir/my_component") || failure  "Unable to find component specified in EXTRA_COMPONENT_DIRS"
+    mkdir -p components/my_component
+    echo "COMPONENT_CONFIG_ONLY := 1" > components/my_component/component.mk
+    (make list-components | grep "$PWD/components/my_component") || failure  "Project components should be prioritized over EXTRA_COMPONENT_DIRS"
+    mv Makefile.bak Makefile # revert previous modifications
+    rm -rf extra_dir components
+
     print_status "All tests completed"
     if [ -n "${FAILURES}" ]; then
         echo "Some failures were detected:"

+ 13 - 2
tools/ci/test_build_system_cmake.sh

@@ -814,6 +814,19 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
     (idf.py reconfigure | grep "kconfig:$IDF_PATH/components/esp32/Kconfig") || failure  "Failed to verify original `main` directory"
     rm -rf components
 
+    print_status "Project components prioritized over EXTRA_COMPONENT_DIRS"
+    clean_build_dir
+    mkdir -p extra_dir/my_component
+    echo "idf_component_register()" > extra_dir/my_component/CMakeLists.txt
+    cp CMakeLists.txt CMakeLists.bak # set EXTRA_COMPONENT_DIRS to point to the other directory
+    ${SED} -i "s%cmake_minimum_required(VERSION \([0-9]\+\).\([0-9]\+\))%cmake_minimum_required(VERSION \1.\2)\nset(EXTRA_COMPONENT_DIRS extra_dir)%" CMakeLists.txt
+    (idf.py reconfigure | grep "$PWD/extra_dir/my_component") || failure  "Unable to find component specified in EXTRA_COMPONENT_DIRS"
+    mkdir -p components/my_component
+    echo "idf_component_register()" > components/my_component/CMakeLists.txt
+    (idf.py reconfigure | grep "$PWD/components/my_component") || failure  "Project components should be prioritized over EXTRA_COMPONENT_DIRS"
+    mv CMakeLists.bak CMakeLists.txt # revert previous modifications
+    rm -rf extra_dir components
+
     print_status "Create project using idf.py and build it"
     echo "Trying to create project."
     (idf.py -C projects create-project temp_test_project) || failure "Failed to create the project."
@@ -850,8 +863,6 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
     expected_failure $EXPECTED_EXIT_VALUE idf.py create-project --path "$IDF_PATH/example_proj" temp_test_project || failure "Command exit value is wrong."
     rm -rf "$IDF_PATH/example_proj"
 
-
-
     print_status "All tests completed"
     if [ -n "${FAILURES}" ]; then
         echo "Some failures were detected:"

+ 6 - 6
tools/cmake/project.cmake

@@ -180,18 +180,18 @@ function(__project_init components_var test_components_var)
             __project_component_dir(${component_dir})
         endforeach()
     else()
+        if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/main")
+            __project_component_dir("${CMAKE_CURRENT_LIST_DIR}/main")
+        endif()
+
         spaces2list(EXTRA_COMPONENT_DIRS)
         foreach(component_dir ${EXTRA_COMPONENT_DIRS})
             __project_component_dir("${component_dir}")
         endforeach()
 
-        __project_component_dir("${CMAKE_CURRENT_LIST_DIR}/components")
-
         # Look for components in the usual places: CMAKE_CURRENT_LIST_DIR/main,
-        # CMAKE_CURRENT_LIST_DIR/components, and the extra component dirs
-        if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/main")
-            __project_component_dir("${CMAKE_CURRENT_LIST_DIR}/main")
-        endif()
+        # extra component dirs, and CMAKE_CURRENT_LIST_DIR/components
+        __project_component_dir("${CMAKE_CURRENT_LIST_DIR}/components")
     endif()
 
     spaces2list(COMPONENTS)