Batch compile

From ISXKB

Revision as of 12:58, 28 December 2007 by Markus (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Introduction

Some projects consist of more than just one Inno Setup script or may require additional tasks to be processed before or after the compilation.

The Inno Setup Preprocessor is not always the correct tool for these tasks but Windows itself provides a command interpreter (CMD.EXE).

Starting the batch script

Obtaining Inno Setup's installation path explains how to retrieve the path where Inno Setup has been installed. Starting from there the compilation can be fully automated.

@ECHO OFF
SETLOCAL

SET CompilerExe=
FOR /F "eol=; tokens=1,2* delims=	" %%a IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /v InstallLocation') DO (
	SET CompilerExe=%%c
)
SET CompilerExe=%CompilerExe%ISCC.exe
ECHO Using compiler executable '%CompilerExe%'.

"%CompilerExe%" script1.iss
IF %ERRORLEVEL% NEQ 0 GOTO :EndErr
"%CompilerExe%" script2.iss
IF %ERRORLEVEL% NEQ 0 GOTO :EndErr
"%CompilerExe%" script3.iss
IF %ERRORLEVEL% NEQ 0 GOTO :EndErr

GOTO :End

:EndErr
ECHO Press any key to exit.
PAUSE>NUL

:End
ENDLOCAL

By moving the error checks into a subroutine the compiler invokations look a bit nicer:

@ECHO OFF
SETLOCAL

SET CompilerExe=
FOR /F "eol=; tokens=1,2* delims=	" %%a IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /v InstallLocation') DO (
	SET CompilerExe=%%c
)
SET CompilerExe=%CompilerExe%ISCC.exe
ECHO Using compiler executable '%CompilerExe%'.

CALL :Compile script1.iss
CALL :Compile script2.iss
CALL :Compile script3.iss
CALL :Compile script4.iss
rem ...

GOTO :End

:Compile
	"%CompilerExe%" "%*"
	IF %ERRORLEVEL% NEQ 0 GOTO :EndErr
GOTO :EOF

:EndErr
ECHO Press any key to exit.
PAUSE>NUL

:End
ENDLOCAL

Re-using the batch script

Depending on how many scripts are to be compiled it's even possible to put the script names in a normal text file, one in each line. By doing this there's no need to touch the compile script later again and it can easily be re-used for other projects.

  • Create a batch file, for instance 'CompileScripts.cmd', with the following contents:
@ECHO OFF
SETLOCAL

SET CompilerExe=
FOR /F "eol=; tokens=1,2* delims=	" %%a IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" /v InstallLocation') DO (
	SET CompilerExe=%%c
)
SET CompilerExe=%CompilerExe%ISCC.exe
ECHO Using compiler executable '%CompilerExe%'.

FOR /F "eol=; tokens=* delims=" %%a IN ('TYPE "ScriptsToCompile.txt"') DO CALL :Compile %%a

GOTO :End

:Compile
	ECHO Trying to compile '%*'...
	"%CompilerExe%" "%*"
	IF %ERRORLEVEL% NEQ 0 GOTO :EndErr
GOTO :EOF

:EndErr
ECHO Press any key to exit.
PAUSE>NUL

:End
ENDLOCAL
  • Then create a text file 'ScriptsToCompile.txt' with the scripts to compile:
script1.iss
script2.iss
script3.iss

Make sure that the last line is properly terminated with a carriage return (CR) and a line feed (LF). In other words hit the enter key once at the end of the last line.

If you don't like all the output you can redirect it into a file. Replace the line

	"%CompilerExe%" "%*"

with

	"%CompilerExe%" "%*">"%*.log"

See also

External links

Personal tools
Ads: