Is there a way to compile only partial (private) libraries (here: components) for specific (testing) environments? For example using subdirectories?
Background
I would like to structure the source files of my project with two levels:
- on a “component” level
- on a “unit” level
Any similarities to terms used in PIO documentation is not intentional.
And I would like to test those units using dedicated environments (using platform = native
).
The PlatformIO documentation explains:
By default, PlatformIO does not build the main source code from the
src_dir
folder in pair with a test source code. […] We recommend splitting the source code into multiple components and placing them into thelib_dir
(project’s private libraries and components).
Thus I put my components into the ./lib
directory.
The component level shall represent architectural boundaries. Different directories shall represent different parts of the software. These parts may change for different reasons. The Dependency Rule is checked for those components. The component directories shall be within one common directory (./lib
).
The units shall be software parts which are tested individually. Unity is used for unit tests. Units shall be tested isolated. A test for one unit shall not require to compile separate source files which are not under test. Units are part of components. Testing a single unit shall not require to compile the the whole component. This shall simplify mocking. Also this shall simplify to avoid dependencies to code which does not compile with the test environment. For example when I test a unit on the native platform I do not want that neighboring units from the same component are also compiled which may not be compatible to that platform.
My problem is, that:
- When I try to test a unit, the other source files outside of the unit directory (
lib/comp1/unit1
), which are in the same component directory (lib/comp1
) are also compiled (usinglib_ldf_mode = chain
). This is bad, as those may have other requirements for building, in particular other dependencies which may not compile for the test environment. - If I set
lib_ldf_mode = off
the source for the UUT is not found. But I can not add the source explicitly to the LDF, as subdirectories can not be specified using for examplelib_deps = comp1/unit1
. Or is there a way to specifiy a subdirectorylib/comp1/unit1
as dependency? - Using
lib_ldf_mode = off
andlib_deps = comp1
does attempt to build every source file in that directory (which may fail, see above).