Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting minimal build on or COMPONENT main causes the build to not include the component test sub-directory (IDFGH-14746) #15485

Open
3 tasks done
i400s opened this issue Feb 27, 2025 · 4 comments
Assignees
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@i400s
Copy link

i400s commented Feb 27, 2025

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • 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.

  1. Create a new project from the unit_test example.
  2. Compile/flash/monitor the device.
  3. No tests are run: 0 tests 0 failures 0 ignored.
  4. Comment out the idf_build_set_property(MINIMAL_BUILD ON) line.
  5. Compile/flash/monitor the device.
  6. 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.

@i400s i400s added the Type: Bug bugs in IDF label Feb 27, 2025
@github-actions github-actions bot 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
@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 27, 2025
@fhrbata
Copy link
Collaborator

fhrbata commented Feb 28, 2025

Hello @i400s,

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()

@i400s
Copy link
Author

i400s commented Feb 28, 2025

Thank you. Will apply the change manually to my clone as an interim solution.

@fhrbata
Copy link
Collaborator

fhrbata commented Feb 28, 2025

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.

@i400s
Copy link
Author

i400s commented Feb 28, 2025

Have just tested.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants