PlatformIO Community

No longer able to build on windows using sysenv

I define machine-level env variables using this script (run from PS ISE running as admin):

[System.Environment]::SetEnvironmentVariable('MESH_PREFIX','MACS Mesh',[System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('MESH_PASSWORD','test',[System.EnvironmentVariableTarget]::Machine)

Here is the platform.ini that consumes these valuse:

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
monitor_speed = 115200
upload_port = COM3 ; Leaf
monitor_filters =
    log2file
    time
    default
board_build.filesystem = littlefs
lib_ldf_mode = chain
build_flags =
    -fexceptions
    -D MESH_PREFIX=${sysenv.MESH_PREFIX}
    -D MESH_PASSWORD=${sysenv.MESH_PASSWORD}

When I do a verbose build, I see that the MESH_PREFIX sysenv var was incorrectly read:

-DMESH_PREFIX=MACS -DMESH_PASSWORD=test

As well, I get two build failures:

lib\Protocols\MeshClient.cpp: In member function 'virtual void MacsMesh::MeshClient::DoSetup()':
<command-line>: error: 'MACS' was not declared in this scope; did you mean 'MAC0'?
lib\Protocols\MeshClient.cpp:11:25: note: in expansion of macro 'MESH_PREFIX'
   11 |     m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
      |                         ^~~~~~~~~~~
<command-line>: error: 'test' was not declared in this scope
lib\Protocols\MeshClient.cpp:11:38: note: in expansion of macro 'MESH_PASSWORD'
   11 |     m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
      |                                      ^~~~~~~~~~~~~

I wrote this code several months ago and used it successfully for several projects. When I decided to reflash one of the same boards running this code, I found that I could no longer build.

I know you hate to hear this, but: it’s the same source code, and the same physical device. The only difference that I am aware of is that I have updated VS Code and platformio since the last time this code built.

If I remove the space, changing ‘MACS Mesh’ to ‘MACS_Mesh,’ I get the following errors:

lib\Protocols\MeshClient.cpp: In member function 'virtual void MacsMesh::MeshClient::DoSetup()':
<command-line>: error: 'MACS_Mesh' was not declared in this scope
lib\Protocols\MeshClient.cpp:11:25: note: in expansion of macro 'MESH_PREFIX'
   11 |     m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
      |                         ^~~~~~~~~~~
<command-line>: error: 'test' was not declared in this scope
lib\Protocols\MeshClient.cpp:11:38: note: in expansion of macro 'MESH_PASSWORD'
   11 |     m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
      |                                      ^~~~~~~~~~~~~

I am at a loss, as this code has been working perfectly on several projects. Please advise and thanks in advance!

But there’s no string escaping there, it’s read as if its a regular code identifier. What happens when yo use

build_flags =
    -fexceptions
    -D MESH_PREFIX=\"${sysenv.MESH_PREFIX}\"
    -D MESH_PASSWORD=\"${sysenv.MESH_PASSWORD}\"

instead?

(Reference: How could the main.cpp read the parameters at platformio.ini? - #3 by maxgerhardt and Removing Secrets from SRC - #16 by gzor)

Hi Max. Thanks for the speedy response.

No, that did not work. I see things like this now:

-DMESH_PREFIX="MACS -DMESH_PASSWORD=“test”

which gives me these types of warning:

: warning: missing terminating " character

I am frustrated by the fact that this has been working for quite some time, and now I am dead in the water.

Indeed, that does not work with this escape style because the space in the environment var break it. However, using

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
build_flags =
    "-D MESH_PREFIX=\"${sysenv.MESH_PREFIX}\""
    "-D MESH_PASSWORD=\"${sysenv.MESH_PASSWORD}\""

grafik

it works.

The PlatformIO core 6.x might have a regression there. Although it looks to me as if it never should have worked without any string quoting anyways, I might also be wrong. You can file an issue in Issues · platformio/platformio-core · GitHub.

2 Likes

Hey Max,

Sorry for the late reply – we just had a holiday here, so I was a little preoccupied.

Anyhow, that worked swimmingly! I’m back up and running!

I think you are correct – there must have been some sort of regression; just to show you I’m not crazy, my last checkin to my platformio.ini file was last Jan, and my approach worked perfectly for months:

image

Just noticed your location, so I won’t say thanks. Rather: Ich bedanke mich sehr! (Ich wohnte fuenf Jahre in Pirmesans, so ich kann ein bisschen H.D (u. e’ bissel Pfaeltzisch, auch!).)

Tony