Auto increment build number for all platform (windows, linux and android)



  • Hi,

    I have a piece of code which will compile for all 3 platforms (windows, linux and android). I'm trying to keep track all the changes have gone into the each of the platforms. I did google, there's quite a few suggestion using the batch script for windows and bash script for linux. But now i'm stuck for Android version.

    I have a script for window and linux and configured .pro file of the project,

    #This is to auto generate the build number and build timestamp
    build_nr.target = $$PWD/build_number.h
    linux-g++-32{
    build_nr.commands = cd $$PWD; chmod +x build_number.sh; $$PWD/build_number.sh
    }
    win32{
    build_nr.commands = $$PWD/build_number.bat
    }
    
    build_nr.depends = FORCE
    QMAKE_EXTRA_TARGETS += build_nr
    PRE_TARGETDEPS += $$PWD/build_number.h
    }
    

    they are working but either on of it doesn't work when i tried to compile and generate APK (for android) no matter i build on windows or linux. Anyone have any idea how can i do the same thing for the Android platform?

    Thanks.

    Regards,
    jenny



  • Unfortunately I'm unable to help, in fact, I'd like to ask you to share the contents of build_number.bat and build_number.sh



  • Hi @liewjls,

    I haven't done any Qt Android development myself (yet), but looking at qmake's spec files, there's a separate android platform value which you should be able to use scope an Android-specific build-number script, such as:

    android {
        build_nr.commands = <whatever you do to update Android resources>
    }
    

    I hope that helps.

    Cheers.


  • Moderators

    @liewjls said in Auto increment build number for all platform (windows, linux and android):

    they are working but either on of it doesn't work when i tried to compile and generate APK (for android) no matter i build on windows or linux. Anyone have any idea how can i do the same thing for the Android platform?

    what is the content of the whole pro file?
    I guess you are sharing some output/intermediate folders among the different target build platforms?



  • @liewjls
    Hi, friend. welcome.

    I search the Qt help. found the following Q_OS_*macros. maybe it can help you.

    Q_OS_AIX
    Defined on AIX.
    Q_OS_ANDROID
    Defined on Android.
    Q_OS_BSD4
    Defined on Any BSD 4.4 system.
    Q_OS_BSDI
    Defined on BSD/OS.
    Q_OS_CYGWIN
    Defined on Cygwin.
    Q_OS_DARWIN
    Defined on Darwin-based operating systems such as OS X, iOS, watchOS, and tvOS.
    Q_OS_DGUX
    Defined on DG/UX.
    Q_OS_DYNIX
    Defined on DYNIX/ptx.
    Q_OS_FREEBSD
    Defined on FreeBSD.
    Q_OS_HPUX
    Defined on HP-UX.
    Q_OS_HURD
    Defined on GNU Hurd.
    Q_OS_IOS
    Defined on iOS.
    Q_OS_IRIX
    Defined on SGI Irix.
    Q_OS_LINUX
    Defined on Linux.
    Q_OS_LYNX
    Defined on LynxOS.
    Q_OS_NETBSD
    Defined on NetBSD.
    Q_OS_OPENBSD
    Defined on OpenBSD.
    Q_OS_OSF
    Defined on HP Tru64 UNIX.
    Q_OS_OSX
    Defined on OS X.
    Q_OS_QNX
    Defined on QNX Neutrino.
    Q_OS_RELIANT
    Defined on Reliant UNIX.
    Q_OS_SCO
    Defined on SCO OpenServer 5.
    Q_OS_SOLARIS
    Defined on Sun Solaris.
    Q_OS_TVOS
    Defined on tvOS.
    Q_OS_ULTRIX
    Defined on DEC Ultrix.
    Q_OS_UNIX
    Defined on Any UNIX BSD/SYSV system.
    Q_OS_UNIXWARE
    Defined on UnixWare 7, Open UNIX 8.
    Q_OS_WATCHOS
    Defined on watchOS.
    Q_OS_WIN32
    Defined on 32-bit and 64-bit versions of Windows (not on Windows CE).
    Q_OS_WIN64
    Defined on 64-bit versions of Windows.
    Q_OS_WIN
    Defined on all supported versions of Windows. That is, if Q_OS_WIN32, Q_OS_WIN64, Q_OS_WINCE or Q_OS_WINRT is defined.
    Q_OS_WINCE
    Defined on Windows CE.
    Q_OS_WINPHONE
    Defined on Windows Phone 8.
    Q_OS_WINRT
    Defined for Windows Runtime (Windows Store apps) on Windows 8, Windows RT, and Windows Phone 8.
    
    


  • Hi all,
    Thanks for all suggestion.

    @raven-worx I actually found out when I use the contains(QMAKE_HOST.os,Windows) in my pro file, it works on all platforms (no matter i build Android on Windows or Linux).

    QT += core
    QT -= gui
    
    CONFIG += c++11
    VER_MAJ=1
    VER_MIN=0
    
    
    QT_varfile = ""
    for(var, $$list($$find($$list($$enumerate_vars()), ^(VERSION*|VER_MAJ*|VER_MIN*|DEFINES*).*$))) {
        line = $$var "$$eval($$var)"
        QT_varfile += $$join(line, "=")
    }
    
    write_file($$absolute_path("VARIABLES.txt", $$OUT_PWD), QT_varfile)
    
    
    contains(QMAKE_HOST.os,Windows) {
        message("Host is windows")
        build_nr.target = extra
        build_nr.commands = $$PWD/build_number.bat $$VER_MAJ $$VER_MIN "$$cat($$OUT_PWD/build.txt)"
        build_nr.depends = FORCE
        QMAKE_EXTRA_TARGETS += build_nr
        PRE_TARGETDEPS += extra
    }
    else {
        message("Host is linux")
        build_nr.target = extra
        build_nr.commands = chmod +x $$PWD/build_version.sh; $$PWD/build_version.sh $$VER_MAJ $$VER_MIN
        build_nr.depends = FORCE
        QMAKE_EXTRA_TARGETS += build_nr
        PRE_TARGETDEPS += extra
        build_nr.target = $$OUT_PWD/version.h
    }
    
    
    TARGET = qtConsole
    CONFIG += console
    CONFIG -= app_bundle
    
    TEMPLATE = app
    
    SOURCES += main.cpp
    
    HEADERS += $$OUT_PWD/build_number.h
    

    But I got a problem now. When i build my APK, the script will run twice. Anyone can help me to resolve this please?

    @VRonin yes, not a problem. I did google around (sorry, i lost track with the links), come out with this

    build_number.sh

    @echo off
    cd /d %dirPath%
    set /a VERSION_BUILD=0
    
    REM Read values from file
    for /f "tokens=*" %%S in (VARIABLES.txt) do set %%S
    echo Script has been run %VERSION_BUILD% time(s)
    
    set /a VERSION_MAJOR=%1
    set /a VERSION_MINOR=%2
    set /a VERSION_BUILD+=1
    
    set VERSION_STR=%VERSION_MAJOR%.%VERSION_MINOR%.%VERSION_BUILD%
    
    REM Write new values to file
    break > VARIABLES.txt
    set VERSION >> VARIABLES.txt
    
    for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
    set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
    
    echo #define TIMESTAMP  "%ldt%" > version.h
    echo #define VER_STR "%VERSION_STR%">> version.h
    

    build_number.sh

    #!/bin/bash
    dir="$PWD"
    versionFile=$dir"/VARIABLES.txt"
    
    . $versionFile
    
    echo "VERSION"$VERSION
    echo "VERSION_BUILD:"$VERSION_BUILD
    echo "VERSION_MAJOR:"$VERSION_MAJOR
    echo "VERSION_MINOR:"$VERSION_MINOR
    echo "VERSION_STR:"$VERSION_STR
    
    VERSION_BUILD=$((VERSION_BUILD+1))
    
    VERSION_MAJOR=$1
    VERSION_MINOR=$2
    VERSION_STR=$VERSION_MAJOR"."$VERSION_MINOR"."$VERSION_BUILD
    
    #Update the new value to the file.
    echo -e "VERSION="$VERSION"\nVERSION_MAJOR="$VERSION_MAJOR"\nVERSION_MINOR="$VERSION_MINOR"\nVERSION_BUILD="$VERSION_BUILD"\nVERSION_STR="$VERSION_STR | tee $versionFile
    
    today=`date +%Y-%m-%d" "%H:%M:%S`
    
    echo -e "#define VERS_STR "\"$VERSION_STR\" "\n#define TIMESTAMP  "\"$today\" | tee version.h
    

    My scripting skills isn't great, any comments to help me improve these 2 scripts that would be great.

    thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.