Batch compile with process log

From ISXKB

Revision as of 20:24, 14 November 2007 by Markus (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Introduction

Batch compile describes how to compile several scripts in one go with a batch file.

Bigger projects require bigger efforts, so here's a more complicated approach.

We want

  • a batch file to compile the entire project that consists of
  • several Inno Setup scripts.
  • Error handling goes without saying.
  • A log file would be great. This requires that you either install Logtext or copy logtext.exe into the project's folder.

The directory structure

There's a project root directory, let's say 'MyInnoProjects' on the C: drive. The scripts shall reside in a directory called 'MyCurrentScripts'. The compile log files could be in a subfolder called 'CompileLogs'.

C:\MyInnoProjects\MyCurrentScripts\
                                   script1.iss
                                   script2.iss
                                   script3.iss
                                   ...
                                   CompileLogs\
                                               CompileLog1 (current)...
                                               ...


The batch file(s)

With minor changes we can take the batch file from Batch compile that uses a text file for the input scripts. The PAUSE command would stop everything so we remove it and replace it with an error message.

Copy the contents in a file called 'CompileScripts.cmd':

@ECHO OFF
SETLOCAL

SET ScriptName=%0
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%" "%*">"%*.log"
	IF %ERRORLEVEL% NEQ 0 GOTO :EndErr
	ECHO '%*' compiled ok.
GOTO :EOF

:EndErr
REM ECHO Press any key to exit.
REM PAUSE>NUL
ECHO Compile script '%ScriptName%' aborted.

:End
ENDLOCAL

Create a text file containing all the scripts to compile in the right order, one in each line as shown in Batch compile and call it 'ScriptsToCompile.txt'.

script1.iss
script2.iss
script3.iss

Now we have:

C:\MyInnoProjects\MyCurrentScripts\
                                   CompileScripts.cmd
                                   ScriptsToCompile.txt
                                   script1.iss
                                   script2.iss
                                   script3.iss
                                   ...
                                   CompileLogs\
                                               CompileLog1 (current)...
                                               ...

Create an additional batch file and call it 'CompileScriptsWrapper.cmd' with the following content:

CompileScripts.cmd 2>&1|LOGTEXT.EXE CompileLogs\CompileLog "" ECHO STDIN

If you would like to double click on this file from Windows Explorer then an additional PAUSE command would not make the window disappear automatically and possible error or success reports will be visible:

CompileScripts.cmd 2>&1|LOGTEXT.EXE CompileLogs\CompileLog "" ECHO STDIN
PAUSE

The new folder structure and contents:

C:\MyInnoProjects\MyCurrentScripts\
                                   CompileScripts.cmd
                                   CompileScriptsWrapper.cmd
                                   logtext.exe
                                   ScriptsToCompile.txt
                                   script1.iss
                                   script2.iss
                                   script3.iss
                                   ...
                                   CompileLogs\
                                               CompileLog1 (current)...
                                               ...

Running 'CompileScriptsWrapper.cmd' will now compile the scripts with exact timing information and produce log files in the folder 'CompileLogs'. Change the file CompileScriptsWrapper.cmd' to

CompileScripts.cmd 2>&1|LOGTEXT.EXE CompileLogs\CompileLog "" ECHO STDIN 10
PAUSE

to keep the log files for 10 days.

That's what the log file 'CompileLogs\CompileLogt2007-11-13.log' looks like after an unsuccessful compile process:

2007-11-13 01:05:53.614+00:00 Trying to compile 'script1.iss'...
2007-11-13 01:05:53.614+00:00 Error on line 9 in C:\MyInnoProjects\MyCurrentScripts\script1.iss: Unrecognized [Setup] section directive "DisableStartu pPrompt"
2007-11-13 01:05:53.624+00:00 Compile aborted.
2007-11-13 01:05:53.624+00:00 Compile script 'CompileScripts.cmd' aborted.

See also

External links

Personal tools
Ads: