Skip to main content
Javier1
Principal
Jun 7, 2021 12:33 PM UTC
Solved

How can i use Build variables? pre-build shell script

I want the IDE to save inside a buildinfo.h various const strings containing build timestamp names and other system variables.

0693W00000BaHb5QAF.pngBut im unable to use them inside my pre-build script:

#!/bin/sh
echo "this is the pre-build script!:D"
 
set _current_date=${current_date}
echo ${current_date}
echo ${_current_date}
echo "static const char BUILD_INFO[] = \"build_date=_current_date\";" > buildinfo.h

The pre-build script creates the build.infofile but the variable current_date is not shown...

0693W00000BaHcwQAF.png0693W00000BaHccQAF.png

This topic has been closed for replies.
Pavel A.
Pavel A.Best answer
Jun 7, 2021 7:32 PM UTC

The eclipse variables can be substituted in the command line, but not in the script file itself.

Try to change the command so:

cd..;./script.sh ${current_date}

and in the script:

#!/bin/sh
echo "this is the pre-build script!:D"
 
set _current_date=$1
.........

3 replies

Javier1
Javier1Author
Principal
Jun 7, 2021 12:35 PM UTC

I first tested

#!/bin/sh
 echo "this is the pre-build script!:D"
 
 echo "static const char BUILD_INFO[] = \"build_date=${current_date}\";" > buildinfo.h

and this got generated inside buildinfo.h:

static const char BUILD_INFO[] = "build_date=";

 :(

hit me up in https://www.linkedin.com/in/javiermuñoz/
Javier1
Javier1Author
Principal
Jun 7, 2021 1:47 PM UTC

It works when i use the date GNU command but i would like to use the IDE build variables.

echo "this is the pre-build script!:D"
cd Core/Inc
NOW=$(date +"%Y-%m-%d_%T")
echo "static const char BUILD_INFO[] = \"build_date="$NOW"\";" > buildinfo.h

hit me up in https://www.linkedin.com/in/javiermuñoz/
Pavel A.
Pavel A.Best answer
Jun 7, 2021 7:32 PM UTC

The eclipse variables can be substituted in the command line, but not in the script file itself.

Try to change the command so:

cd..;./script.sh ${current_date}

and in the script:

#!/bin/sh
echo "this is the pre-build script!:D"
 
set _current_date=$1
.........