New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining variables on the command line breaks for strings. #526

Closed
skorokithakis opened this Issue Feb 21, 2016 · 16 comments

Comments

Projects
None yet
3 participants
@skorokithakis

skorokithakis commented Feb 21, 2016

I tried to define a variable on the command line (a string), but while the #define FOO "bar baz" works fine in the code, I couldn't get it to work on the console (strings got split no matter what I tried).

I can post a minimal example soon, but it's simple enough to reproduce, just take a string define out of the file and into the command line. If the define contains spaces, building will break.

@ivankravets ivankravets self-assigned this Feb 21, 2016

@ivankravets

This comment has been minimized.

Member

ivankravets commented Feb 21, 2016

How about ?

[env:myenv]
build_flags = '-DFOO="bar baz"'
@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 21, 2016

I don't want to specify it there because my goal is to release an open source repo without my secret keywords (WiFi password) in it. So, I added a build.sh to my gitignore that specifies these options on the command line so secrets won't leave my computer.

Since this doesn't work, I'm forced to keep a public and a private version of a repo, which is cumbersome :-(

@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 21, 2016

Oh, sorry, you meant escaping the space. I'll try that soon, thank you!

@ivankravets

This comment has been minimized.

Member

ivankravets commented Feb 21, 2016

It should work. Please don't close this issue while we will not resolve it. Thanks.

@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 21, 2016

No :(

export PLATFORMIO_SRC_BUILD_FLAGS='-DWIFI_PASS="my\ ssid" -DWIFI_SSID="MyWIFI"'

platformio run --target upload
#ifndef WIFI_PASS
#define WIFI_PASS "your wifi password"
#endif
main.ino:410:1: error: stray '\' in program
<command-line>:0:11: error: 'MyWIFI' was not declared in this scope
main.ino:410:12: note: in expansion of macro 'WIFI_SSID'

Looks like it happens even for things with no spaces, sorry for the mistaken report, but it's worse than I thought.

@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 21, 2016

If you can tell me where in the code this is handled, I can take a look at fixing it.

@ivankravets

This comment has been minimized.

Member

ivankravets commented Feb 21, 2016

Try

export PLATFORMIO_SRC_BUILD_FLAGS="'-DWIFI_PASS=\"my ssid\"' -DWIFI_SSID=MyWIFI"

My output

(develop) ikravets@innomac /V/S/P/G/p/origin> platformio run -d examples/wiring-blink/ -e uno
[Sun Feb 21 17:10:29 2016] Processing uno (platform: atmelavr, board: uno, framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
avr-g++ -o .pioenvs/uno/src/main.o -c -fno-exceptions -fno-threadsafe-statics -std=gnu++11 -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO_AVR_UNO -DARDUINO=10607 "-DWIFI_PASS="my ssid"" -DWIFI_SSID=MyWIFI -DPLATFORMIO=020804 -I.pioenvs/uno/FrameworkArduino -I.pioenvs/uno/FrameworkArduinoVariant src/main.cpp
@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 21, 2016

That still doesn't work, but this does:

export PLATFORMIO_SRC_BUILD_FLAGS="'-DWIFI_PASS=\\\"\"my\ ssid\"\\\"' '-DWIFI_SSID=\\\"\"MyWIFI\"\\\"'"

Wow. That is extremely convoluted. Is there any way PlatformIO command-line options for this could be simplified?

@valeros

This comment has been minimized.

Member

valeros commented Feb 21, 2016

Could you try please:
export PLATFORMIO_SRC_BUILD_FLAGS="'-DWIFI_PASS=\"MY WIFI KEY\"' '-DWIFI_SSID=\"TEST STR\"'"

@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 21, 2016

That doesn't work, unfortunately. The compiler command line becomes -DWIFI_PASS="MY. Escaping the spaces fails on some other error. This is easy to reproduce, you should be able to just use my code above to try it yourself and see.

@ivankravets ivankravets added this to the 2.8.5 milestone Feb 22, 2016

@ivankravets ivankravets added bug and removed help wanted labels Feb 22, 2016

@ivankravets

This comment has been minimized.

Member

ivankravets commented Feb 22, 2016

@skorokithakis I'll look on it and fix from the PlatformIO's side

@ivankravets ivankravets assigned valeros and unassigned ivankravets Feb 24, 2016

@valeros valeros closed this in 1f1dc9c Feb 24, 2016

@valeros

This comment has been minimized.

@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 24, 2016

Nope, this breaks integers:

build_flags = -DMQTT_MAX_PACKET_SIZE=1024
xtensa-lx106-elf-gcc -DMQTT_MAX_PACKET_SIZE=\"1024\"

A better fix would be to preserve whatever quotes are there, rather than indiscriminately add quotes everywhere.

@ivankravets ivankravets reopened this Feb 24, 2016

@valeros valeros closed this in 1c481e0 Feb 25, 2016

@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 25, 2016

Except for the forgotten print statement, that worked, thanks!

@valeros

This comment has been minimized.

@skorokithakis

This comment has been minimized.

skorokithakis commented Feb 25, 2016

I did and they work, thanks! Just the print statement left to take out.

ivankravets added a commit that referenced this issue Mar 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment