How to use: exec_command/cli command in platformio.ini

Hi

I would like to add the build count to the build_flags inside the platformio.ini.
this is a way to control the OTA update via webserver on the esp8266.

So far all my tries are failing.

I believe that I somehow miss the right syntax.

the command: git rev-list HEAD --count
is working on cli level inside the IDE.

platformio.ini
[global]
build_flags = -D VERBOSE

[exec_command]
build_flags = !echo $(git rev-list HEAD --count)

[env:trial]
platform = espressif8266
board = huzzah
build_flags = -D VERSION=${exec_command.build_flags}
framework = arduino

When starting the run I got this as the output:

cli output
pio run -e trial
[Sun Dec 18 17:33:40 2016] Processing trial (platform: espressif8266, board: huzzah, framework: arduino, build_flags: -D VERSION=!echo $(git rev-
list HEAD --count))

Verbose mode can be enabled via -v, --verbose option
Collected 30 compatible libraries
Looking for dependencies…
Library Dependency Graph

Compiling .pioenvs/trial/src/main.o
Archiving .pioenvs/trial/libFrameworkArduinoVariant.a
sh: -c: line 0: syntax error near unexpected token )' sh: -c: line 0: xtensa-lx106-elf-g++ -o “.pioenvs/trial/src/main.o” -c -fno-rtti -fno-exceptions -std=c++11 -Os -mlongcalls -mtext-section-liter
als -falign-functions=4 -ffunction-sections -fdata-sections --count) -DARDUINO=20300 -DLWIP_OPEN_SRC -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH -
DPLATFORMIO=30201 -DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_ESP12 -DVERSION=!echo -U__STRICT_ANSI__ -I/Users/wolfgang.keller/.platformio
/packages/framework-arduinoespressif8266/tools/sdk/include -I/Users/wolfgang.keller/.platformio/packages/framework-arduinoespressif8266/tools/sdk
/lwip/include -I/Users/wolfgang.keller/.platformio/packages/framework-arduinoespressif8266/cores/esp8266 -I/Users/wolfgang.keller/.platformio/pac
kages/framework-arduinoespressif8266/variants/adafruit -I.piolibdeps/PubSubClient_ID89/src “-I.piolibdeps/Adafruit Unified Sensor_ID31” "-I.pioli

bdeps/DHT sensor library_ID19" -I/Users/wolfgang.keller/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src -I/Users/wo
lfgang.keller/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient/src -I/Users/wolfgang.keller/.platformio/packages/f
ramework-arduinoespressif8266/libraries/ESP8266httpUpdate/src -I.piolibdeps/Streaming_ID560 -I/Users/wolfgang.keller/.platformio/packages/framewo
rk-arduinoespressif8266/libraries/ESP8266WebServer/src -I/Users/wolfgang.keller/.platformio/packages/framework-arduinoespressif8266/libraries/EEP
ROM -I/Users/wolfgang.keller/.platformio/packages/framework-arduinoespressif8266/libraries/DNSServer/src -I/Users/wolfgang.keller/.platformio/pac
kages/framework-arduinoespressif8266/libraries/Ticker -I.piolibdeps/WiFiManager_ID1265 -I.piolibdeps/ArduinoJson_ID64 -Isrc “src/main.cpp”’
Indexing .pioenvs/trial/libFrameworkArduinoVariant.a
Compiling .pioenvs/trial/FrameworkArduino/Esp.o
sh: -c: line 0: syntax error near unexpected token `)’

=========================================================== [ERROR] Took 0.85 seconds ===========================================================

=================================================================== [SUMMARY] ===================================================================
Environment trial [ERROR]

We example for this use case. See Redirecting...

[env:exec_command]
; get VCS revision "on-the-fly"
build_flags = !echo "-DPIO_SRC_REV="$(git rev-parse HEAD)

Hi

thanks for the answer. I played around with it again - some new thought in mind.

the following I observed IS working:

[global]
build_flags = -D VERBOSE
version = !echo “-D VERSION=\"”$(git rev-list HEAD --count)“\"”

[env:trial]
platform = espressif8266
board = huzzah
;build_flags = !echo “-D VERSION=\"”$(git rev-list HEAD --count)“\"”
build_flags = ${global.version} ${global.build_flags} -D BUTTON=4 -D RELAY=15 -D LEDOFF=LOW
framework = arduino

strangely the following is NOT working - showing same problem like above.

[global]
build_flags = -D VERBOSE
version = !echo “-D VERSION=\"”$(git rev-list HEAD --count)“\"”

[env:trial]
platform = espressif8266
board = huzzah
;build_flags = !echo “-D VERSION=\"”$(git rev-list HEAD --count)“\"”
build_flags = ${global.build_flags} ${global.version} -D BUTTON=4 -D RELAY=15 -D LEDOFF=LOW
framework = arduino

thanks