Menu

#415 Add version number option to !define

2.0 Series
closed-fixed
Scripting (152)
2
2016-12-29
2008-01-17
Anonymous
No

I currently use different ugly methods to get a local version number into a constant (compile time). Please add something like this:

!define /FILEVERSION "..\my.dll" MY_DLL_VERSION

${MY_DLL_VERSION} should evaluate to "1.2.3.4" now, so you could use this in VIProductVersion and similar commands. And please allow some more options to format this version number. I regularly need "1.2", "1" and "1.2.3" and even "1.2.4" for more processing. There might be some people who want to have something like "1.0" or "1.2.0" or "120".

Should be flexible like this:

!define /FILEVERSION="a.b.c.d" "..\my.dll" MY_DLL_VERSION
; => "1.2.3.4"

!define /FILEVERSION="ab0" "..\my.dll" MY_DLL_VERSION
; => "120"

Maybe it is better to use "1234" instead of "abcd" or even other codes for the format string.

Thanks
StB

Here's my macro workaround which is not very portable (and quite ugly):

!define FILE_WITH_VERSION "my_main.exe"
!include "..\..\utilities\nsh\define_version.nsh"
!undef FILE_WITH_VERSION

---------------------------------------------

; define_version.nsh
!define TMP_FILE "__tmp_get_version_${FILE_WITH_VERSION}.nsh"
!appendfile "${TMP_FILE}" "dummy"
!delfile "${TMP_FILE}"

!appendfile "${TMP_FILE}" `OutFile "${TMP_FILE}.exe"$\r$\n`
!appendfile "${TMP_FILE}" `Section$\r$\n`
!appendfile "${TMP_FILE}" ` GetDllVersionLocal "${FILE_WITH_VERSION}" $R0 $R1$\r$\n`
!appendfile "${TMP_FILE}" ` IntOp $R2 $R0 / 0x00010000$\r$\n`
!appendfile "${TMP_FILE}" ` IntOp $R3 $R0 & 0x0000FFFF$\r$\n`
!appendfile "${TMP_FILE}" ` IntOp $R4 $R1 / 0x00010000$\r$\n`
!appendfile "${TMP_FILE}" ` IntOp $R5 $R1 & 0x0000FFFF$\r$\n`
!appendfile "${TMP_FILE}" ` FileOpen $1 "${TMP_FILE}" "w"$\r$\n`
!appendfile "${TMP_FILE}" ` FileWrite $1 '!define VERSION "$R2.$R3.$R4.$R5"'$\r$\n`
!appendfile "${TMP_FILE}" ` FileWrite $1 '$`
!appendfile "${TMP_FILE}" `\r$`
!appendfile "${TMP_FILE}" `\n'$\r$\n`
!appendfile "${TMP_FILE}" ` FileWrite $1 '!define VERSION_DISPLAY "$R2.$R3.$R5"'$\r$\n`
!appendfile "${TMP_FILE}" ` FileWrite $1 '$`
!appendfile "${TMP_FILE}" `\r$`
!appendfile "${TMP_FILE}" `\n'$\r$\n`
!appendfile "${TMP_FILE}" ` FileClose $1$\r$\n`
!appendfile "${TMP_FILE}" `SectionEnd$\r$\n`

!system 'c:\programme\nsis\makensis.exe /V1 "${TMP_FILE}"'
!echo '"${TMP_FILE}.exe"'
!system '"${TMP_FILE}.exe" /S'
!include "${TMP_FILE}"
!delfile "${TMP_FILE}.exe"
!delfile "${TMP_FILE}"
!undef TMP_FILE

Discussion

  • Amir Szekely

    Amir Szekely - 2008-01-18
    • priority: 5 --> 2
     
  • Amir Szekely

    Amir Szekely - 2008-01-18

    Logged In: YES
    user_id=584402
    Originator: NO

    Your ugly hack is already portably implemented as __InstallLib_Helper_GetVersion in Library.nsh.

    As for the request itself, I think !define has been abused far too many times. Such very specific cases, which can be solved in a cleaner method with a build system in my opinion, don't qualify as a !define switch. Maybe something else, but not !define. I'm not even sure a preprocessor instruction fits best here. It really seems best outside in a separate build system. And if not, maybe some other prefix?

     
  • Nobody/Anonymous

    Logged In: NO

    Thanks for the hint to LibraryLocal, but I often need special formatting (a.b.d) for the version number at compile time. Of course I use a build system for bigger projects and have a special tool for creating the version include (.nsh). But for small projects I just have some main executable (.exe or .dll) which has the version number in its resource part. All I need is a small installer script to package the tool. And it's easier to just supply the project's source (some code files + nsi file) so the prerequisites are only the corresponding Development Tool (Compiler+IDE) and a default NSIS installation (no more binaries). Those projects do not need a makefile because creating a new release is just two actions away: 1. compile (right click on project file), 2. package (right click on nsi file).

    I don't care whether this would be a !define option or a new preprocessor command. But I think it would be quite useful. It could replace GetDLLVersionLocal, too. The result of GetDLLVersionLocal cannot be used on compile time but the input has to be compile time. There is no need of the output to be a runtime thing.

    Suggestion: !version or !fileversion
    necessary argument: filename
    optional argument: formatting string ("a.b.c.d" or "1.2.3.4" or "\1.\2.\3.\4" or anything like that)
    necessary argument: identifier (constant's name, e.g. MY_DLL_VERSION)

    Maybe you should think of future enhancements for implementing other ways of getting the version number. I think fileversion should be the most useful thing here and most other scenarios could be done with a makefile. But maybe getting the version number out of an .ini file could be useful, too (could be separate command !iniversion).

     
  • Amir Szekely

    Amir Szekely - 2008-08-16

    Logged In: YES
    user_id=584402
    Originator: NO

    Does the new !define /file or !searchparse cover this?

     
  • Amir Szekely

    Amir Szekely - 2008-08-16
    • status: open --> pending
     
  • Stefan Bertels

    Stefan Bertels - 2008-08-17
    • status: pending --> open
     
  • Stefan Bertels

    Stefan Bertels - 2008-08-17

    Logged In: YES
    user_id=1119337
    Originator: NO

    No, at the time the installer is build, the correct version number is not always in a text file (may be already incremented or stored binary or ...)

     
  • Anders

    Anders - 2016-12-29
    • status: open --> closed-fixed
     
  • Anders

    Anders - 2016-12-29

    !getdllversion has now been added.

     

Log in to post a comment.