A racket application usually has an `info.rkt` file in the root directory
of the project/package/collection.
see https://docs.racket-lang.org/raco/getinfo.html

You can put your meta information in that file than read it with
(get-info/full dirpath) which returns a function that works like `hash-ref`.

I recommend that way, there are also other alternatives.
One that match your example is, just (write)ing a racket list into
"app-version.rktl" (note, "rktl" is also a conventional name, the "l"
stands for "load"),
then you can (read) back it:

(match-define (list app-version app-commit-id app-build-date)
  (with-handlers ([exn:fail:filesystem? (lambda [e] (list "dev build"
"unknown" "no build"))])
    (call-with-input-file "app-version.rkt" read)))

This alternative is simpler than the one using `info.rkt` when you update
the meta information programmatically.


On Fri, Jan 6, 2017 at 10:08 AM, Alex Harsanyi <[email protected]>
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 [email protected].
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to