caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremie Dimino <jdimino@janestreet.com>
To: "Étienne André" <Etienne.Andre@univ-paris13.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Build number and date in OCaml?
Date: Tue, 9 Apr 2013 13:18:46 +0100	[thread overview]
Message-ID: <CANhEzE7MJ7Kus_TSuYoM8HK4mCjRoZiPb3aJLDmDqeRgd5AAhQ@mail.gmail.com> (raw)
In-Reply-To: <CAB+Vvvgfrez6qedMwyj4_2fjPy+x_DyGzSOBXKQ4paLNEtk3mg@mail.gmail.com>

Hi Etienne,

On Tue, Apr 9, 2013 at 12:38 PM, Étienne André
<Etienne.Andre@univ-paris13.fr> wrote:
> I've been using OCaml for a couple of years, but without using any advanced
> feature; so my question may be a little naive.
> Is there any way to insert easily the current date and time of compiling, as
> well as, e.g., an incremental build number in an OCaml program?
> So that it is printed at runtime, e.g., in the program header.
>
> I quite stupidly used the Unix.gettimeofday() function before realizing that
> it is of course executed at runtime.
>
> Of course, I could do it using an external script that would modify the
> OCaml source code before compiling, but is there any native OCaml feature
> for achieving this in a cleaner manner?

I don't know of such a feature.  One thing you can do is to write a
small camlp4/ppx extension that will replace for instance BUILD_DATE
by the current date.

But I think the standard way to have the build date/number at runtime
is to generate a small file containing this information and link it
with the other units. If you don't want to recompile everything every
time the date changes, just make sure that the other units do not
depend on the implementation on this file (i.e. they must not see the
.cmx), or generate a C file instead of a .ml file.

Cheers,

-- 
Jeremie

  reply	other threads:[~2013-04-09 12:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 11:38 Étienne André
2013-04-09 12:18 ` Jeremie Dimino [this message]
2013-04-10  8:49 ` Julien Signoles
2013-04-10  9:08   ` David Allsopp
2013-04-11 13:00 ` Alain Frisch
2013-04-12 14:38   ` Daniel Weil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANhEzE7MJ7Kus_TSuYoM8HK4mCjRoZiPb3aJLDmDqeRgd5AAhQ@mail.gmail.com \
    --to=jdimino@janestreet.com \
    --cc=Etienne.Andre@univ-paris13.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).