Count the times that the program has been built.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Johan_Haegg
User
User
Posts: 60
Joined: Wed Apr 30, 2003 2:25 pm
Location: Västerås
Contact:

Count the times that the program has been built.

Post by Johan_Haegg »

One thing i realy would like to see in PureBasic might be quite easy to code into the compiler.

Each time a program is built, when the compiler is checking stuff like ; ExecuteableFormat = Whatever, let it add one to something lite ; Build = X
and put a #Build.l = X at the beginning of the source (only in compiler, not in source-file)

Version is for the user to decide, but its a pain trying to remember the times you have built the program.

Ok, it might get ugly if someone uses the good old trial and error technique, but for those who write serious programs in PureBasic, writeing a few hundred lines of code between the debuging sessions its nice to know (and show) what build the end-user is using.


OT:
If i get a bunch of Euros left from my vacations, its going directly to Fred, i ran into the limit today and im getting tired of people whineing about the Debug-box. ;)
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I know it is not quite the same, but to clearly identify each build, you
could also use the time of compilation.

The compiler stores it in the #PB_Compiler_Date constant. It is the kind
of date format you can use with all the Date functions.

Timo
quidquid Latine dictum sit altum videtur
Johan_Haegg
User
User
Posts: 60
Joined: Wed Apr 30, 2003 2:25 pm
Location: Västerås
Contact:

Post by Johan_Haegg »

Well, that works to, but as you said, it is not quite the same.
#PB_Compiler_Build would be nice and easy to implement.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

I wrote something to handle this, compiler it as an exe and build a batch file or something inbetween, and bobs your ucle.

Code: Select all

; PureBasic Visual Designer v3.70a


;- Window Constants
;
#WINBUMP = 0

;- Gadget Constants
;
#Gadget_0 = 0

;-----------------------------------------------------------------------------
; Title : Bump Revsion
; Code : T.J.Roughton
; Version : 0.1
; Comment : Compiling World.c fatal expection
;-----------------------------------------------------------------------------
IncludeFile "_bumpversion.pb"
Declare Open_WINBUMP()
Structure PARAM
    cmd.s
    action.s
EndStructure
NewList cmdline.PARAM()
Dim cvtable.s(64)
Global numlabellines
Global majver
Global minver
Global revver
Global betaver
Global alphaver
Global build
Global bumpvers.s
Declare ParameterPhase()
Declare Info()
Declare WriteVersion(filename.s)
Declare ReadVersion(filename.s)
Declare BumpVersion()
readcvtable.s=""
Restore codevertable_bb
While readcvtable<>"-1"
    Read readcvtable
    cvtable(i)=readcvtable : i=i+1
Wend
numlabellines=i-2

Open_WINBUMP()
Info()
ParameterPhase()
;Repeat
;    EventID.l = WaitWindowEvent()
;    If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
;        Quit = 1
;    EndIf
;Until Quit = 1
;  

;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
Procedure ParameterPhase()
    param.s=" "
    While param<>""
        AddElement(cmdline())
        param=ProgramParameter()
        cmdline()\cmd=param
        cmdline()\action=ProgramParameter()
    Wend
    ResetList(cmdline())
    bump=#FALSE : mode=#FALSE : load=#FALSE
    While NextElement(cmdline())
        ;AddGadgetItem(#Gadget_0,0,("CMD: "+cmdline()\cmd)
        ;AddGadgetItem(#Gadget_0,0,("ACT: "+cmdline()\action)
        If(cmdline()\cmd="-i")
            infile.s=cmdline()\action
            load=#TRUE
        EndIf
        If(cmdline()\cmd="-b")
           bumpvers=cmdline()\action
           bump=#TRUE
        EndIf
        If(cmdline()\cmd="-m")
            If(cmdline()\action="c")
                Restore codevertable_c
                AddGadgetItem(#Gadget_0,0,"Output C Source")
                mode=#TRUE
            EndIf
            If(cmdline()\action="bb")
                Restore codevertable_bb
                AddGadgetItem(#Gadget_0,0,"Output Blitz Basic Source")
                mode=#TRUE
            EndIf
            If(cmdline()\action="pb")
                Restore codevertable_pb
                AddGadgetItem(#Gadget_0,0,"Output Pure Basic Source")
                mode=#TRUE
            EndIf
        EndIf
    Wend
    If mode=#TRUE
        readcvtable.s=""
        While readcvtable<>"-1"
            Read readcvtable
            cvtable(i)=readcvtable : i=i+1
        Wend
        numlabellines=i-2
    Else
        AddGadgetItem(#Gadget_0,0,"Output Blitz Basic Source")
    EndIf
    If load=#TRUE
        ReadVersion(infile)
    EndIf
    If bump=#TRUE
        BumpVersion()
        WriteVersion(infile)
    EndIf
EndProcedure
;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
Procedure Info()
    AddGadgetItem(#Gadget_0,0,"-----------------------------------------------------------------------------")
    AddGadgetItem(#Gadget_0,0," Bump Revision v"+_FullVer+" "+_CompileTime+" "+_CompileDate)
    AddGadgetItem(#Gadget_0,0,"-----------------------------------------------------------------------------")
    AddGadgetItem(#Gadget_0,0," Written By T.J.Roughton (A.K.A) Inner (FREEWARE)")
    AddGadgetItem(#Gadget_0,0," -i [file] : Input Version File ")
    AddGadgetItem(#Gadget_0,0," -r mnrbai : Reset Version Value")
    AddGadgetItem(#Gadget_0,0," -b mnrbai : Bump Version +1")
    AddGadgetItem(#Gadget_0,0," -m mode   : Output Code Style [default bb]")
    AddGadgetItem(#Gadget_0,0,"             bb = Blitz Basic Source")
    AddGadgetItem(#Gadget_0,0,"             pb = Pure Basic Source")
    AddGadgetItem(#Gadget_0,0,"             c  = C Source")
    AddGadgetItem(#Gadget_0,0,"")
EndProcedure
;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
Procedure BumpVersion()
    If(Mid(bumpvers,1,1)="1")
        majver=majver+1
    EndIf
    If(Mid(bumpvers,2,1)="1")
        minver=minver+1
    EndIf
    If(Mid(bumpvers,3,1)="1")
        revver=revver+1
    EndIf
    If(Mid(bumpvers,4,1)="1")
        betaver=betaver+1
    EndIf
    If(Mid(bumpvers,5,1)="1")
        alphaver=alphaver+1
    EndIf
    If(Mid(bumpvers,6,1)="1")
        build=build+1
    EndIf
EndProcedure
;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
Procedure ReadVersion(filename.s)
    If(ReadFile(0,filename)<>0)
        While Eof(0)=0
            ln.s=ReadString()
            If(Mid(ln,0,1)<>";")
                For i=0 To numlabellines                    
                    If(FindString(ln,cvtable(i),0)>0)
                        foundtablab=i
                    EndIf
                    ln=RemoveString(ln,cvtable(i),1)
                Next
                Select foundtablab
                    Case 0
                        majver=Val(ln)
                    Case 1
                        minver=Val(ln)
                    Case 2
                        revver=Val(ln)
                    Case 3
                        betaver=Val(ln)
                    Case 4
                        alphaver=Val(ln)
                    Case 5
                        build=Val(ln)
                EndSelect
            EndIf            
        Wend
        CloseFile(0)
    Else
        WriteVersion(filename)
    EndIf
EndProcedure 
;-----------------------------------------------------------------------------
; 
;-----------------------------------------------------------------------------
Procedure WriteVersion(filename.s)
    If(CreateFile(0,filename)<>0)
        WriteStringN(";-----------------------------------------------------------------------------")
        WriteStringN("; Bump Revision ")
        WriteStringN(";-----------------------------------------------------------------------------")
        WriteStringN(cvtable(0)+Str(majver))
        WriteStringN(cvtable(1)+Str(minver))
        WriteStringN(cvtable(2)+Str(revver))
        WriteStringN(cvtable(3)+Str(betaver))
        WriteStringN(cvtable(4)+Str(alphaver))
        WriteStringN(cvtable(5)+Str(build))
        _fullver.s=Str(majver)+"."+Str(minver)+"."+Str(revver)+"."+Str(betaver)+"."+Str(alphaver)+" Build "+Str(build)
        WriteStringN(cvtable(6)+Chr(34)+_fullver+Chr(34))
        _midver.s=Str(majver)+"."+Str(minver)+"."+Str(revver)+"."+Str(betaver)+" Build "+Str(build)
        WriteStringN(cvtable(7)+Chr(34)+_midver+Chr(34))
        _smlver.s=Str(majver)+"."+Str(minver)+" Build "+Str(build)
        WriteStringN(cvtable(8)+Chr(34)+_smlver+Chr(34))
        WriteStringN(cvtable(9)+Chr(34)+FormatDate("%dd/%mm/%yy",Date())+Chr(34))
        WriteStringN(cvtable(10)+Chr(34)+FormatDate("%hh:%ii:%ss",Date())+Chr(34))    
        CloseFile(0)
    EndIf
EndProcedure
;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
Procedure Open_WINBUMP()
  If OpenWindow(#WINBUMP, 305, 258, 428, 129,  #PB_Window_SystemMenu | #PB_Window_TitleBar , "Bump Revision v"+_FullVer)
    If CreateGadgetList(WindowID())
      ListViewGadget(#Gadget_0, 5, 5, 420, 120)
       AddGadgetItem(#Gadget_0,0,"FOO")
 
    EndIf
  EndIf
EndProcedure
;-----------------------------------------------------------------------------
;
;-----------------------------------------------------------------------------
DataSection
    codevertable_c:
    Data.s "#Define _MAJORVERSION " 
    Data.s "#Define _MINORVERSION " 
    Data.s "#Define _REVISION     "     
    Data.s "#Define _BETA         "         
    Data.s "#Define _ALPHA        "        
    Data.s "#Define _BUILD        "        
    Data.s "#Define _FULLVER      "    
    Data.s "#Define _MIDVER       "     
    Data.s "#Define _SMLVER       "     
    Data.s "#Define _COMPILEDATE  "
    Data.s "#Define _COMPILETIME  "
    Data.s "-1"
    codevertable_bb:
    Data.s "Global _MajorVersion  :_MajorVersion=" 
    Data.s "Global _MinorVersion  :_MinorVersion=" 
    Data.s "Global _Revision      :_Revision="     
    Data.s "Global _Beta          :_Beta="         
    Data.s "Global _Alpha         :_Alpha="        
    Data.s "Global _Build         :_Build="        
    Data.s "Global _FullVer$      :_FullVer$="    
    Data.s "Global _MidVer$       :_MidVer$="     
    Data.s "Global _SmlVer$       :_SmlVer$="     
    Data.s "Global _CompileDate$  :_CompileDate$="
    Data.s "Global _CompileTime$  :_CompileTime$="
    Data.s "-1"
    codevertable_pb:
    Data.s "Global _MajorVersion  :_MajorVersion=" 
    Data.s "Global _MinorVersion  :_MinorVersion=" 
    Data.s "Global _Revision      :_Revision="     
    Data.s "Global _Beta          :_Beta="         
    Data.s "Global _Alpha         :_Alpha="        
    Data.s "Global _Build         :_Build="        
    Data.s "Global _FullVer.s     :_FullVer.s="    
    Data.s "Global _MidVer.s      :_MidVer.s="     
    Data.s "Global _SmlVer.s      :_SmlVer.s="     
    Data.s "Global _CompileDate.s :_CompileDate.s="
    Data.s "Global _CompileTime.s :_CompileTime.s="
    Data.s "-1"
EndDataSection
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

Would be nice with a such constant
Anden
Enthusiast
Enthusiast
Posts: 135
Joined: Mon Jul 21, 2003 7:23 am
Contact:

Post by Anden »

Yes, this is a minimum requirement for a compiler.

Simple workaround: Use jaPBe, it's already built in there (#jaPBe_ExecuteBuild)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

codecaddy :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

A #PB_Compiler_Build would be nice.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

I agree. But this can only be done when the source code has been saved. (The number of compilations can be saved at the end of the file by the IDE).
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Re: Count the times that the program has been built.

Post by Derek »

Johan_Haegg wrote:Ok, it might get ugly if someone uses the good old trial and error technique, but for those who write serious programs in PureBasic, writeing a few hundred lines of code between the debuging sessions its nice to know (and show) what build the end-user is using.
That's my approach and that means I would be on build 257.42 before my program is released to the one person I wrote it for. :lol: :lol:
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I agree, good idea :)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Don't get me wrong, I think it is a good idea and I do wonder where these great 'build 1.03.05' numbers come from.

What confuses me is what constitutes a build?

Is ironing out a few bugs a new build or is implementing a new routine, which has no effect on the overall look of the program at the user level, a new build?
Post Reply