Build Actions (pre-build and post-build)

Technical Note 99436

Targets:
All

Component:
IDE

Updated:
1/15/2018 3:35 PM

Introduction

This Technical Note gives comments on and suggestions for the use of pre- and post-build actions.

Discussion

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.

$TOOLKIT_DIR$\bin\ielfdumparm.exe --version

ielfdumparm.exe --version

ielfdumparm --version

fig_1_ielfdumparm--version.png

Figure 1 ielfdumparm --version

Shell commands

To use shell-internal commands such as DIR, ECHO, PATH, or REM a shell must be started. See the screenshot below for an example.

fig2_cmd.exe-c-dir-$proj_dir$.c.png

 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

$PROJ_DIR$\build.cmd "$PROJ_DIR$"

and build.cmd containing  

PATH > %1\output.txt 2>&1

could be an alternative to Example I/O-3.

 

Notes

  • To see output from build actions in the Build Log window, use the context menu in that window and select All.

    • In an older IDE (that is, common components 7 or older) enable the option Tools > Options > IDE Options… > Messages > Show build messages > 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

Example files are available via this link.

Note that these project files (.ewp) require IAR Embedded Workbench for ARM 7.80 or later.

Conclusion

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.

Realated Tech Notes

© IAR Systems 1995-2018 - All rights reserved.

We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies