cancel
Showing results for 
Search instead for 
Did you mean: 

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

Javier1
Principal

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

Available for consulting/freelancing , hit me up in https://github.com/javiBajoCero
1 ACCEPTED SOLUTION

Accepted Solutions

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
.........

View solution in original post

3 REPLIES 3
Javier1
Principal

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=";

 :(

Available for consulting/freelancing , hit me up in https://github.com/javiBajoCero

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

Available for consulting/freelancing , hit me up in https://github.com/javiBajoCero

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
.........