Dynamic sections in platformio.ini

Hello:

Is there a way, in the platformio.ini file, to select or ignore sections depending on system environment (or other reliable method) to determine what OS is running? An if / endif like thing.

I use a Linux (Ubuntu 24), a Win7, and a Win10 for development depending is several unimportant factors.

Example, on Windows there is a system environment variable called OS that is set to Windows_NT, and in Linux I can make one called OS and set it to Ubuntu (or something)

then select (or ignore) a platformio.ini section based on that system environment setting.

I use MEGA to sync Windows MyDocuments and Linux Documents so the source and libraries are the same,

Thanks, Mark.

There is no conditional swiching available directly to the platformio.ini.
But you can use Advanced Scripting — PlatformIO latest documentation

What problem are you trying to solve?

Unfortunately, I am thinking this whole thread may become moot as I am disliking Linux more and more lately and thinking of going back to Windows,

That will take me a few days to do, so this thread will have to take a back seat for a while.

Thanks for your time.

Mark.

1 Like

This deserves a thread on its own :wink:

What do you dislike the most?

Ugh, my head is getting sore from beating it against my computer.

As I try to install Win10 (triple boot with Ubuntu, and Mint) I remembered setting up a new computer from scratch is a PITA. (sorry, just ranting a bit.)

So, that is taking a lower priority and back to this issue.

sivar2311 mentioned Advanced Scripting, and while that may someday be an option, I’d rather not get too much into the weeds there. However, while researching that, I ran across Interpolation in the platformIO.ini file. So…

I created a system environment…
in Windows…
PIOport = COM6
and in Linux…
PIOport = /dev/ttyUSB0

Then in my platformio.ini I put

upload_port = ${sysenv.PIOport}
monitor_port = ${sysenv.PIOport}

I’ll let you know if this works.

As for the home folder, the documentation says I can use
${sysenv.HOME}
so I did…
build_flags = -I ${sysenv.HOME}"\Documents\_Projects\ESP_stuff\MyLibs"

and OMG that compiled on Windows at least!! :slight_smile: I’ll let you know if it works on Linux.

Thanks,
Mark.

PS, zapta, I started going down a rabbit hole and rant about issues with Linux, but decided this wasn’t the place. Thank you for asking. I spent 30 minutes typing up my issues then deleted it as this wasn’t the place. (I do that a lot when I need to vent.)

I feel better now.

You can handle this more easily:

Simply put the libraries relative to your projects and use lib_deps in combination with symlink. It’s just a matter of how you organize things. Take a look at this: Platformio ignores dependencies of local library - #2 by sivar2311

Ah, you are suggesting there is more then one way to skin that. :cat: