You can write compile-time code to query the current date, and get the
version number from an environment variable:

    #lang racket
    (require (for-syntax racket/date))
    (define-syntax (embed-version stx)
      (syntax-case stx ()
        [_ #`(format "~a - ~a"
                     #,(date->seconds (current-date))
                     #,(getenv "VERSION"))]))
    (displayln (embed-version))


    $ VERSION=3 racket test-date.rkt         
    1483670494 - 3
    $ VERSION=3 raco make test-date.rkt         
    $ racket test-date.rkt
    1483670499 - 3
    $ racket test-date.rkt
    1483670499 - 3

Note: the reason I'm using environment variables is that command-line
arguments are harder to pass through raco make. Probably doable, though.

Vincent


On Thu, 05 Jan 2017 20:08:57 -0600,
Alex Harsanyi wrote:
> 
> I would like to embed versioning and build date information in my application
> executable, and I'm not sure how to do that.  To clarify, in C or C++, I would
> write the following:
> 
>    #include <stdio.h>
> 
>    #ifndef APPVER
>    #define APPVER "no version"
>    #endif
> 
>    void main()
>    {
>         printf("%s\n", APPVER);
>    }
> 
> I can than compile the code by passing "-D APPVER=1.0" to the compiler command
> line and have it print the correct version.
> 
> How can this be done in Racket?
> 
> I don't really want to check-in a file with the version number in it, and
> besides, I would like to add my GIT commit ID and build date as well in the
> same way.
> 
> My idea is that the build script would write a file like this at build time:
> 
>    #lang racket/base
>    (define (app-version) "1.0")
>    (define (app-commit-id) "abcdefg")
>    (define (app-build-date) "06-01-2017T09:10:12")
>    (provide app-version app-commit-id app-build-date)
> 
> I would than require this file from other places, but only if it exists,
> something like this:
> 
>    (if (file-exists? "app-version.rkt")
>        (require "app-version.rkt")
>        (begin
>          (define (app-version) "dev build")
>          (define (app-commit-id) "unknown")
>          (define (app-build-date) "no build")))
> 
> Unfortunately, the code above does not work because require needs to be
> defined at top level.
> 
> Does anyone have any suggestions?
> 
> Thanks,
> Alex.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to