tags:

views:

373

answers:

2

I want to call a function (which calculates my version number) when my NSIS script is compiling, but not while it's executing. Is this possible? It uses nsExec and basic string manipulation functions.

+1  A: 

Sweet! It's possible: see http://nsis.sourceforge.net/Invoking_NSIS_run-time_commands_on_compile-time

The basic idea is:

  1. Compile a separate script that generates an executable
  2. Run the executable (via !system, at compile time) in your main script - and this generates a text file (which !defines whatever you need)
  3. !include the text file in your main script

and presto! You've got some stuff generated at compile time in your script.

Jesse Beder
+2  A: 

You could do this:

!system '"calculate_version.exe" "tempfile.tmp"'
!searchparse /file "tempfile.tmp" `APP_VERSION=` APPVERSION

What this does: calls calculate_version.exe (this could be a simple NSIS script which calls your function). This executable should output the version number to tempfile.tmp. The format of the version doesn't matter; in this example I've chosen "APP_VERSION=something" (this could be written using WriteINIStr).

In the next line, we open the temp file and search it for the line we wrote; then we set ${APPVERSION} to whatever we find there.

Piskvor
I actually prefer the idea in the article I cited (it's almost the same as yours) since the hard work gets done in the associated script (writing the !defines, and so on) instead of having to parse what you need in the main script.
Jesse Beder
You have a point. On the other hand, I don't really like the idea of compiling in a file which may or may not be the output of the given program. A matter of preference, I guess =)
Piskvor