Safety-certified tools Tools for Automotive Applications C-STAT Static analysis C-RUN Runtime analysis Debugging and trace probes
IAR Embedded Workbench for RISC-V now releasedTools for Risc-V
This Technical Note gives comments on and suggestions for the use of pre- and post-build actions.
Pre-build and post-build command line environment
When specifying pre-build and post-build action command lines:
IAR Embedded Workbench Argument Variables can be used
The directory $TOOLKIT_DIR$\bin is included in the environment variable PATH.
The initial working directory is $EW_DIR$\common\bin
Using IAR Embedded Workbench for ARM as an example, any of the following commands can be used to display the version of ielfdumparm.exe in the build log window.
Figure 1 ielfdumparm --version
To use shell-internal commands such as DIR, ECHO, PATH, or REM a shell must be started. See the screenshot below for an example.
Figure 2 - CMD.EXE /C DIR "$PROJ_DIR$\*.c"
Shell I/O redirection
Using the shell it is possible to redirect output from shell commands and executables to a file. The following examples use a fictive Windows executable named app.exe.
Example I/O-1 -- Interactively at a windows command prompt:
app.exe > output.txt 2>&1
Example I/O-2 -- From a build action command line:
CMD /C "app.exe > $PROJ_DIR$\output.txt 2>&1"
Example I/O-3 -- Ditto, if/ when only one ”CMD /C” leaves the output file empty:
CMD /C "CMD /C "app.exe > $PROJ_DIR$\output.txt 2>&1""
Using .cmd files
Using a .cmd file, you get a shell automatically and thus need one less "CMD /C" compared to a plain build action command line.
With a file build.cmd located in the project directory, a build action
and build.cmd containing
PATH > %1\output.txt 2>&1
could be an alternative to Example I/O-3.
To see output from build actions in the Build Log window, use the context menu in that window and select All.
When the project is up-to-date, the build actions will not be invoked, that is, build actions are only performed if at least one tool in the toolchain is invoked.
See example configuration XA for one way to ensure that build actions are invoked.
IAR Embedded Workbench Argument Variables and Microsoft Environment Variables are similar. However, they are not the same. To use the value of an argument variable like $PROJ_DIR$ in a .cmd file, pass the wanted argument variable as a parameter.
If the pre-build or post-build command returns an error code (return value != 0 ), the entire Build/Make command is aborted.
See example configuration XB.
Example files are available via this link.
Note that these project files (.ewp) require IAR Embedded Workbench for ARM 7.80 or later.
This Technical Note gives comments on and suggestions for the use of pre-build and post-build actions as available in IAR Embedded Workbench.
While based on practical use of Microsoft products and documentation, these comments and suggestions are to be viewed as guidelines and inspiration.
All product names are trademarks or registered trademarks of their respective owners.