Skip to content
⌘ NSIS Forum Archive

Redefine only if empty

7 posts

Mircea M#

Redefine only if empty

Hi,

i have the following scenario: our build server calls makensis.exe with (among others) a parameter that contains Service Pack information. In case the current release is a Service Pack, the parameter has a value. In case it is not, it is empty.

The following code calls makensis.exe:
makensis.exe /DINSTALLER_VERSION_STRING=%v% /DINSTALLER_BUILD_NUMBER=%b% /DINSTALLER_SERVICEPACK_STRING=%sp%
I then use this information to set the product information in the setup.exe as such:
VIProductVersion "${INSTALLER_VERSION_STRING}.${INSTALLER_SERVICEPACK_STRING}.0.${INSTALLER_BUILD_NUMBER}"
My problem occurs when the build server sends an empty string as INSTALLER_SERVICEPACK_STRING. in this case, the VIProductVersion returns the following error:
Error: invalid VIProductVersion format, should be X.X.X.X
.

What I would like to do is assign to INSTALLER_SERVICEPACK_STRING the value "0" in case it is empty. I tried using this:
${If} ${INSTALLER_SERVICEPACK_STRING} ""
!define /redef INSTALLER_SERVICEPACK_STRING "0"
${EndIf}
This returns the following error:
!insertmacro: macro "_If" requires 4 parameter(s), passed 2!
I also tried using this:
StrCmp ${INSTALLER_SERVICEPACK_STRING} "" 0 +2
!define /redef INSTALLER_SERVICEPACK_STRING "0"
This doesn't return an error but the value is not changed (I still get the original error about the VIProductInfo).

Any help is appreciated!

Mircea
Mircea M#
And i found my answer thanks to "search" and eccles:

!define EmptySP${INSTALLER_SERVICEPACK_STRING}

!ifdef EmptySP
!define /redef INSTALLER_SERVICEPACK_STRING "0"
!endif
JasonFriday13#
Ah, another case of mixing compile time code with runtime code. You can't use runtime code to change compile time code, it all has to be done with compile time code. ${If} and StrCmp are runtime functions.
DarthAndroid#
The proper way to do this is with:

!define /ifndef INSTALLER_SERVICEPACK_STRING "0"

This will set the define to "0" if it is not set by your build server. If the build server sets the define when it calls makensis, then the line will be ignored (/ifndef) and whatever the build server specified will prevail.
Anders#
Originally Posted by DarthAndroid View Post
The proper way to do this is with:

!define /ifndef INSTALLER_SERVICEPACK_STRING "0"

This will set the define to "0" if it is not set by your build server. If the build server sets the define when it calls makensis, then the line will be ignored (/ifndef) and whatever the build server specified will prevail.
The OP has a empty define, not a non-existing define.
Anders#
NSIS treats "" as 0 in math operations so you can add 0 to the input:

!define /redef /math INSTALLER_SERVICEPACK_STRING "${INSTALLER_SERVICEPACK_STRING}" + 0