Passing a "build variable" to a library.json that has a default

We have a library where we need the includer of our library to be able to select which subsets of our library’s components end up in the build. We already do this when we are built with CMake and make; we’d like the mechanism to look similar when we are built under PlatformIO.

In the make/CMake case, our library is passed a build variable containing “component_a component_b component_c”; if we are passed no such build variable we create one which includes all components. The rest of our make/CMake build script then selects source/header files based on the components that are listed in the build variable.

What would be the “canonical” way to do this in PlatformIO? I can think of a few ways, I’m really interested here in what is the right way from a PlatformIO point of view.

In the end we did this by having our pre-build Python script check for an environment variable with a known name, e.g. OURLIB_FEATURES, which the user can set to “component_a component_c” etc.; if the environment variable is not found the script will create it, set to the default, “component_a component_b component_c”. This works fine, hope it is “right”.