You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
I have searched the issue tracker for a similar issue and not found a similar issue.
IDF version.
v5.5-dev-2119-g0461e2ff88
Operating System used.
Linux
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
What is the expected behavior?
The build system should auto-include a components test directory and the c files within.
What is the actual behavior?
Build system doesn't include components test directory or doesn't find the c files within.
Steps to reproduce.
Create a new project from the unit_test example.
Compile/flash/monitor the device.
No tests are run: 0 tests 0 failures 0 ignored.
Comment out the idf_build_set_property(MINIMAL_BUILD ON) line.
Compile/flash/monitor the device.
Tests are run: 3 Tests 1 Failures 0 Ignored
...
Build or installation Logs.
More Information.
The example program contains the minimal requirements to show the error and the workaround of not trimming the build.
My actual application/components code can't be compiled using an untrimmed build as a workaround because it is using some mocks and this causes the code to fail to compile with an error because not all drivers are mocked.
Another workaround using the example program:
It is possible to copy the test_mean.c from the components/testable/test/ directory to the application test/main/ and amend the CMakeLists.txt file to add the file in the SRCS section, add testable to the PRIV_REQUIRES section, but only if WHOLE_ARCHIVE is added. If WHOLE_ARCHIVE is not included then it again fails to pick up the tests (0 tests 0 failures 0 Ignored).
There is another warning/error if changing from a physical device to "linux" which is partially related to this issue but I will raise that in a separate bug report after a few more tests.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
Setting minimal build on or COMPONENT main causes the build to not include the component test sub-directory
Setting minimal build on or COMPONENT main causes the build to not include the component test sub-directory (IDFGH-14746)
Feb 27, 2025
thank you very much for highlighting the issue with the minimal build and test components. You are correct that when the minimal build is enabled, the components specified with set(TEST_COMPONENTS ...) are not included in the build.
The following patch seems to fix the issue.
diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake
index cfb95b95cec2..a8f3cea063fa 100644
--- a/tools/cmake/project.cmake+++ b/tools/cmake/project.cmake@@ -504,7 +504,7 @@ function(__project_init components_var test_components_var)
message(WARNING "The MINIMAL_BUILD property is disregarded because the COMPONENTS variable is defined.")
set(minimal_build OFF)
else()
- set(COMPONENTS main)+ set(COMPONENTS main ${TEST_COMPONENTS})
set(minimal_build ON)
endif()
else()
Hello @i400s, thank you very much and apologies for the inconvenience. I've already submitted an internal merge request to address this. Let's see what others think. Please let me know if you encounter any other issues related to this.
idf_build_set_property(MINIMAL_BUILD ON) now works as expected and includes the code under the component_name/test/ directory.
However it doesn't work if set(COMPONENTS main) is specified (which I think was the old way of creating a minimal build).
Using the code you showed, if I amend my project CMakefile.txt to have set(COMPONENTS main ${TEST_COMPONENTS}) it works. I'm guessing because although part of the esp_idf code knows about TEST_COMPONENTS the part that "builds" doesn't if its not included in the COMPONENTS list.
Now I understand the process a bit more an obvious fix would be to always append to COMPONENTS if TEST_COMPONENTS has a list (as apposed to the proposed change within the conditional, line 504)... but I'm guessing people who may have found this issue with the old method (and understand CMake) may have made the change I did to their project CMakefile... so I'm not sure what the implications of appending the TEST_COMPONENTS would make if the COMPONENTS already has the same items. eg. (main a_component mytest_component a_component mytest_component).
I'm still very new at this (c and cmake), so I will leave this in your capable hands.
Answers checklist.
IDF version.
v5.5-dev-2119-g0461e2ff88
Operating System used.
Linux
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
What is the expected behavior?
The build system should auto-include a components test directory and the c files within.
What is the actual behavior?
Build system doesn't include components test directory or doesn't find the c files within.
Steps to reproduce.
...
Build or installation Logs.
More Information.
The example program contains the minimal requirements to show the error and the workaround of not trimming the build.
My actual application/components code can't be compiled using an untrimmed build as a workaround because it is using some mocks and this causes the code to fail to compile with an error because not all drivers are mocked.
Another workaround using the example program:
It is possible to copy the test_mean.c from the components/testable/test/ directory to the application test/main/ and amend the CMakeLists.txt file to add the file in the SRCS section, add testable to the PRIV_REQUIRES section, but only if WHOLE_ARCHIVE is added. If WHOLE_ARCHIVE is not included then it again fails to pick up the tests (0 tests 0 failures 0 Ignored).
There is another warning/error if changing from a physical device to "linux" which is partially related to this issue but I will raise that in a separate bug report after a few more tests.
The text was updated successfully, but these errors were encountered: