Search code examples
batch-fileembeddedmsp430iarpre-build-event

IAR Pre-Build batch file python call not working


I'm trying to setup a script to increment a build number inside a version file in IAR EW430. I've got the python script and the batch file working from the command line, but when I run it on the IAR IDE, the build number doesn't increment.

In the IAR Project, I have Options > Build Actions > Pre-build command line set to:

$PROJ_DIR$\pre-build.bat "$PROJ_DIR$"

The batch file pre-build.bat is:

@echo off
set arg1=%1
python VersionInc.py %arg1%
echo on

Right now, arg1 is just the path to the "version.h" file that python manipulates, and is the same path as the project for these tests.

When I recompile in IAR, the build message reports "Performing Pre-Build Action" and shows the correct path and argument being sent and I see a command window pop up for a short time, but the file doesn't get manipulated. What am I missing?

Thanks


Solution

  • You can't assume which directory you are executing Python in. You need to specify the directory where your script is located.

    pushd {path to VersionInc.py directory}
    python VersionInc.py %arg1%
    popd
    

    or alternatively, if your script can be executed from any directory:

    python {path to VersionInc.py directory}\VersionInc.py %arg1%