Using env name as board type?

As described here, I often use the following approach in my platformio.ini file, to allow building many different small apps for the same target board:

[env]

src_filter = +<${PIOENV}.cpp>
...

[env:app1]
[env:app2]
[emv:app3]

The other scenario I tend to use is building the same app for different boards, which would benefit from something like this:

[env]
board = $PIOENV
...

[env:disco_f412zg]
[env:nucleo_g431rb]
[env:nucleo_l432kc]

Unfortunately, that does not work. The PIOENV variable does not get expanded for board in the same was as if does for src_filter.

Something related but not quite the same has been discussed here.

Would it be an idea to add support for this? I assume that such a change would not be difficult, but I’m not familiar enough with the PIO code to easily find my way around. I can have a go at extending the Python code if someone helps me out as to which file I’d need to look into …

Another option I guess, would be to use pio ci [OPTIONS] [SRC]... for this, but that’s a command-line chore which you have to remember each time, whereas the PIOENV expansion can be specified once in the ini file and then automatically kicks in.

-jcw

Update: this topic also addresses the board vs app puzzle.

You’ve typed ${PIOENV} in the first snippet, and $PIOENV (no braces) in the second one, I’m not sure but maybe that makes the difference?

The extra braces are needed to separate “PIOENV” from “.cpp”. Probably best to always use braces, but in the second example, they’re optional (I think!). Either way fails - with braces:

UnknownBoard: Unknown board ID '${PIOENV}'

IOW, there’s no variable expansion taking place.

May have to do something with the order of expansion or rescanning of any variables need to be expanded after substititung in the env?

I think only core people at https://github.com/platformio/platformio-core/issues can answer that.

Thanks. Issue posted: No expansion in "board = ..." · Issue #5206 · platformio/platformio-core · GitHub

It turns out to be a restriction of the config parser (see GitHub issue). Ok, so be it.