Execute batch file in Inno Setup preprocessor during compilation with relative Path - inno-setup

I want to start a batch file from [Files] section.
It works with absolute path like
[Files]
#expr Exec("C:\batch.bat");
but how can I start it with relative path?
My batch file is located in the same directory as the .iss file.
I have tried it with
#expr Exec("\Batch.bat");
or something like
#expr Exec("{#SourceDataPath}\Batch.bat");
and with
#expr Exec(ExpandConstant("{#SourceDataPath}\Batch.bat"));
but it just says "Undeclared identifier: ExpandConstant."
But everything I have tried did not work.

Use SourcePath preprocessor predefined variable:
#expr Exec(SourcePath + "\Batch.bat");
Note that it's not really correct to say that you execute the batch file from the [Files] section. It might confuse you to think of it this way. You are executing the batch file in a preprocessing phase. Unless you use results of the batch file in further preprocessor directives (what I believe you do not), you can actually place the Exec call anywhere in the script file. As I believe your batch file only produces files, which are used in the compiling phase that happens only after the complete script is preprocessed. Though it's perfectly fine to place the call where you put it. It's just so that you understand what going's on under the hood.

Related

Inno Setup preprocessor can read a file using FileOpen, but not using ReadIni

This is a clarification required to the existing post mentioned below
How to declare an Inno Setup preprocessor variable by reading from a file
Reading value from .txt file using FileOpen works perfectly fine, while reading .ini file using ReadIni returns an empty string.
The code for reading from txt file is:
#define VerFile FileOpen("common\GlobalConfig.txt")
#define AppVer FileRead(VerFile)
#expr FileClose(VerFile)
#undef VerFile
The txt file has the string Innovation.
The code for reading from ini file is:
#define AppVer ReadIni("common\GlobalConfig.ini", "Productname", "Product")
The content of the ini file is:
[Productname]
Product=Innovation
Both the files are in the same folder location.
The file is encoded with UTF-8 without BOM. I've checked with other types of encoding too, but it is returning only empty. I created with Notepad++.
Thanks in advance!
The relative paths in ReadIni are resolved to the current working directory, what particularly in Inno Setup IDE is not the script directory.
Use absolute paths by using SourcePath predefined variable:
#define AppVer ReadIni( \
SourcePath + "\common\GlobalConfig.ini", "Productname", "Product")
For FileOpen ISPP does that automatically, but not for ReadIni.
While not your case, another possibility is that there's something wrong with the INI file. It has to be UTF-8/ASCII without BOM or UTF-16 LE (with or without BOM).

Return output filename generated by Inno Setup preprocessor to a batch script

I'm setting up a batch file that will compile my application, the compile the installer using Inno Setup.
My setup filename is determined using some ISPP command in Inno Setup (creating the filename from the build version, among other things).
The last step is to upload the setup to my FTP, but for this I need a way to retrieve the installer filename generated by Inno Setup.
Is there a way to do that?
You can write a preprocessor variable value to a file.
One way is to execute an external program to do the writing using Exec function:
#define FileName "foobar"
#expr Exec( \
"cmd.exe", "/c echo " + FileName + "> """ + SourcePath + "\filename.txt""", , , \
SW_HIDE)
You can then read the file in your batch file. Or you can have the preprocessor generate a full FTP upload script and just execute it from the batch file.
Another way is to create an INI file using WriteIni function:
#define FileName "foobar"
#expr WriteIni(SourcePath + "\filename.ini", "Section", "FileName", FileName)
Though personally, I'd generate the file name in the batch file (or replace the batch file with a better language), and pass it to Inno Setup, rather then the other way around.

What is the list file (*.f) for verilog?

I found both ncvlog and Verdi can read the design through *.f which includes *.v files and +incdir commands. It's easy to get an example and modify it fit the new project.
However, is there have any specific description about .f file?
Commonly referred to as "dot-f" files, files that end with an extension of .f contain command-line arguments for the simulator. The .f extension is actually just a convention and not required by the tools. The the file is passed in with a -f or -F option.
Any command-line argument that the tool accepts can be placed within a file that is passed with the -f option.
Here is an excerpt from an old ncvlog manual I found online:
-File arguments_filename
Use the command-line arguments contained in the specified arguments file.
You can store frequently used or lengthy command lines by putting command-line arguments
(command options and top-level design unit names) in a text file. When you invoke the
elaborator with the -file option, the arguments in the arguments file are incorporated with
your command as if they had been entered on the command line.
The arguments file can contain command options, including other -file options, and
top-level design unit names. The individual arguments within the arguments file must be
separated by white space or comments.
As an example, the following two scenarios are equivalent:
Specify command-line arguments directly
$> ncvlog +incdir+foo mod1.v mod2.v mod3.v
Specify command-line arguments in a .f file
args.f:
+incdir+foo
mod1.v
mod2.v
mod3.v
$> ncvlog -f args.f
it's just some arguments, you can put file list, include directory, macro define, and other option here

NSIS: Reading from a file at compile time

I want to read some values from a file (config.json) into some variables when I compile my nsis script.
How can I possibly do that?
Thanks in advance.
The !include command can include any file (at compile time) at the point where it is placed in the nsis script. But the included file must be compliant with the nsis syntax (e.g. it should !define some values).
The !execute command could help you: if you need absolutely to process a json file you could code a third-party batch command file to pre-process the json file and translate it into a suitable nsis file.
You can use !define to pass some value which can be used in compile time. For example lets imagine that you have got this code in you nsis source file:
!define PATHTOFILE "C:\thisfilewillbedeleted.ext"
Delete $PATHTOFILE
If you want to change this walue on compile time you can call nsis in this way:
makensis /DPATHTOFILE="C:\otherfiletodelete.ext"
[EDIT]
If you got *.json file which is generated using external tool and you must use this kind of file I will suggest you to use some building system, for example ant. You can create build.xml which read, parse data from json file and then write those data to *.nsh file. I think it will be better and cleaner than do it all in nsis script.
If you just need to parse your json file on runtime, you can use !define with the /file option:
!define /file OPTIONS json.txt
It will define OPTIONS with the content of json.txt.
If you want to utilize your json file in compile time to alter the generated exe, then you need some kind of precompiler, which is what you're actually doing.
You may use the !searchparse command with the /file switch.
Example :
# search filename.cpp for a line '#define APP_VERSION "2.5"' and set ${VER_MAJOR} to 2, ${VER_MINOR} to 5.
!searchparse /file filename.cpp `#define APP_VERSION "` VER_MAJOR `.` VER_MINOR `"`

nmake: can a batch file run as part of a make command block, affect the environment of the nmake.exe process?

I think in nmake if I do this:
example :
set value=77
echo %%value%%
The result will display 77 on the console.
Is there a way for me to invoke a .cmd or .bat file that will affect the environment of the nmake.exe process? Suppose I put the statement set value=77 in a file called "setvalue.cmd". Then change the makefile to this:
example :
setvalue
echo %%value%%
I get:
%value%
Alternatively, if there's a way to set a macro within a command block, that would also work. Or, a way to set the value of a macro from a batch file, even outside a command block.
You can create an nmake snippet during makefile pre-processing, and read that in. Assuming batch.cmd outputs valid nmake syntax, then
!if [batch.cmd >makefile.auto]
!error *** Could not create makefile.auto
!endif
!include makefile.auto
You should ensure batch.cmd sets %errorlevel% appropriately (e.g., exit /b 22).
makefile.auto can contain anything, but you would probably want stuff like value=77. A couple of points:
Dereference value using nmake syntax ($(value))
You can pass parameters to batch.cmd if necessary ([batch.cmd $(OBJECTS) >makefile.auto])
No, I don't think so.

Resources