Disabling src generates errors for native unit test environment

When I disable the src folder for my unit test environment I get warnings and fails. Here is my platformio.ini:

platform = espressif8266
board = nodemcuv2
framework = arduino
test_ignore = test_desktop
platform = native

This will build both enviroments but obviously fail on the native that I only use for unit_test:

* Looking for Arduino.h dependency? Check our library registry!
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h

 #include <Arduino.h>
compilation terminated.
src\main.cpp:1:10: fatal error: Arduino.h: No such file or directory

So I figured setting the src_filter in native like this

src_filter = -<*>

This fails like this:

Processing native (platform: native)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Error: Nothing to build. Please put your source code files to '...r\src' folder
================================================================================== [FAILED] Took 0.50 seconds ==================================================================================

Environment    Status    Duration
-------------  --------  ------------
nodemcuv2      SUCCESS   00:00:18.499
native         FAILED    00:00:00.496

So I finally came up with a hack that works:

targets = --version

And this gives me all green success:

Processing native (platform: native)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SCons by Steven Knight et al.:
        SCons: v4.0.1.c289977f8b34786ab6c334311e232886da7e8df1, 2020-07-17 01:50:03, by bdbaddog on ProDog2020
        SCons path: ['C:\\Users\\andre\\.platformio\\packages\\tool-scons\\scons-local-4.0.1\\SCons']
Copyright (c) 2001 - 2020 The SCons Foundation
================================================================================== [SUCCESS] Took 0.17 seconds ==================================================================================
Environment    Status    Duration
-------------  --------  ------------
nodemcuv2      SUCCESS   00:00:19.141
native         SUCCESS   00:00:00.169
================================================================================== 2 succeeded in 00:00:19.310 ==================================================================================

But this is not the way targets is supposed to be used. Isn’t there a better way to skip building for a specific environment without warnings? I want to use build-all as I have different platform (not shown in this example) so i get a list of all greens so that I can tell that all platforms compiled as expected.

Okay so you just want to unit-test test in the native environment but not build the src/ directory for it, right?

I’d say you can stick a default_envs directive at the top so that the build for native doesn’t get triggered when you do a normal build.

default_envs = nodemcuv2

But with that it will also only use “Test” on the NodeMCUv2 environment.

Or, stick a semantically empty file in src/ that is only used for the native environment and ignored by all other environments using the src_filter. E.g.,


int main() { return 0; }

And then src_filter = +<*> -<empty_native.c> in all environments but the native ones.

Fun fact, if you just pio run / Build the example Unit testing project, the calculator, it also fails to build ofc.

 #include <Arduino.h>
compilation terminated.
*** [.pio\build\native\src\main.o] Error 1
============================================== [FAILED] Took 4.59 seconds ==============================================

Environment    Status    Duration
-------------  --------  ------------
uno            SUCCESS   00:00:07.975
nodemcu        SUCCESS   00:00:08.330
native         FAILED    00:00:04.590
======================================== 1 failed, 2 succeeded in 00:00:20.895 ========================================

The idea here is that just pio test is invoked to test in ann environments and Build/Upload only on the respective environment(s), with either the VSCode → Project tasks selection by environment or pio run -e env1,env2.

Using default_envs seems to do do the trick, as it accepts multiple arguments it is good enough thanks!