platformio-core
platformio-core copied to clipboard
escaping $ in build_flags
What kind of issue is this?
-
[ ] Question. This issue tracker is not the place for questions. If you want to ask how to do something, or to understand why something isn't working the way you expect it to, use Community Forums or Premium Support
-
[ ] PlatformIO IDE. All issues related to PlatformIO IDE should be reported to appropriate repository: PlatformIO IDE for Atom or PlatformIO IDE for VSCode
-
[ ] Development Platform or Board. All issues (building, uploading, adding new boards, etc.) related to PlatformIO development platforms should be reported to appropriate repository related to your hardware https://github.com/topics/platformio-platform
-
[x ] Feature Request. Start by telling us what problem you’re trying to solve. Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.
-
[ ] PlatformIO Core. If you’ve found a bug, please provide an information below.
You can erase any parts of this template not applicable to your Issue.
Configuration
Operating system: windwos
PlatformIO Version (platformio --version):
Description of problem
using env.StringifyMacro() doesn't escape special characters also it isn't obvious what the escapes are, for instance "$$" to escape "$" isn't obvious. "\$" produces "/$" which is also baffeling. The docs only say to escape characters they don't say how you do it.
Request: document escape characters and special characters used in .ini build_flags and env variables
Could you provide a platformio.ini example?
example:
Import("env")
import os
secret = "123$$a$$"
# this insanity is required
proper = "123$$$$$$$$a$$$$$$$$"
# add macro definition for code to use in projenv (visible to src/ files)
env.Append(CPPDEFINES=[
("WIFI_PWD", env.StringifyMacro(secret))
])
suck = env.StringifyMacro(secret)
print(" DOH " + suck + " --- " + secret + "\n");
main.cpp
#include <Arduino.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
#pragma message( WIFI_PWD);
printf("thing: %s",WIFI_PWD);
delay(1000);
}
@bdbaddog, @mwichmann, sorry for disturbing you directly.
Could you share with us any ideas on how to disable SCons variable substitution for the CPPDEFINE/Macro?
The env.Append(CPPDEFINES=[("WIFI_PWD", "123$$a$$")]) produces ... -DWIFI_PWD=123$ ... in a verbose mode where SCons tries to evaluate $xxxx.
Thanks in advance.
Two options:
- create your own escape function and set via
env['ESCAPE'](See manpage) - Change
env.Append(CPPDEFINES=[("WIFI_PWD", "123$$a$$")])toenv.Append(CPPDEFINES=[("WIFI_PWD", "123\$$\$$a\$$\$$")])
$$ substitutes to $, then the \ should escape it for the SHELL.
I'd say go ahead and add your example to this existing github issue (if you agree that it's basically the same issue?) https://github.com/SCons/scons/issues/1093
@bdbaddog, thanks for the prompt help!
The 2nd option will work well for us. I tried it and it still "eats" char a. The env.Append(CPPDEFINES=[("WIFI_PWD", "123\$$\$$a\$$\$$")]) produces -DWIFI_PWD=123\$\\$\$.
Also look into Literal
https://scons.org/doc/production/HTML/scons-man.html#f-Literal
I believe we've used that form to get around the irritating ORIGIN token for the binutils linker, like Literal('\\\\$$ORIGIN')
(that appears in one of the tests).
@mwichmann , I tried it with ("WIFI_PWD", env.Literal('\\\\$$ORIGIN')) and it produces -DWIFI_PWD=\\.