OCaml Forge

Detail: [#849] Provide automatic build version

Feature Requests: Browse | Download .csv | Monitor

[#849] Provide automatic build version

Date:
2010-12-29 22:26
Priority:
3
State:
Open
Submitted by:
Török Edwin (edwin)
Assigned to:
Sylvain Le Gall (gildor-admin)
Resolution:
None
Due in version:
None
Product:
OASIS
Component:
Plugin OCamlbuild
Operating System:
All
 
Summary:
Provide automatic build version

Detailed description
Providing something like this in myocamlbuild.ml would be nice:
http://brion.inria.fr/gallium/index.php/Automatic_Version_Generation

It'd be even better if version generation is done based on version from VCS (if VCS present), and
fallback to version specific in _oasis file otherwise. Or provide both (version and build_version).

For some reason

For now I've appended it:
(* OASIS_STOP *)
let version =
Ocamlbuild_pack.My_unix.run_and_open "(git describe --always --dirty || echo 'exported')" (fun ic ->
input_line ic);;

let time =
let tm = Unix.gmtime (Unix.time ()) in
Printf.sprintf "%04d/%02d/%02d %02dh UTC"
(tm.Unix.tm_year + 1900) (tm.Unix.tm_mon + 1) tm.Unix.tm_mday
tm.Unix.tm_hour;;

let make_version _ _ =
let cmd =
Printf.sprintf "value version = %S;\nvalue compile_time = %S;" version time
in
Cmd (S [ A "echo"; Quote (Sh cmd); Sh ">"; P "version.ml" ]);;

Ocamlbuild_plugin.dispatch
(function
| After_rules as e ->
rule "version.ml" ~prod: "version.ml" make_version;
dispatch_default e
| e ->
dispatch_default e)
;;

Followup

Message
Date: 2010-12-30 11:43
Sender: Török Edwin

VersionExtra sounds good, but can ${version_extra} be used to generate a version.ml at build time?
(as opposed to generating it at configure time using FilesAB)
Date: 2010-12-30 11:35
Sender: Sylvain Le Gall

The version cover the whole package, not a single binary. Moreover it is a distinct parameter in _oasis. I use it for example, in oasis-db to sort packages.

The best I can propose to you is to define an extra variable "version_extra" that will be "" in distributed setup.ml and the result of whatever command you like:

Version: 0.2.1
VersionExtra: git describe --always --dirty

The variable will be set according to SourceRepository, if you don't define it. E.g. latest revision number for svn, latest date change for darcs... + tag if there is uncommited changes.

I still need to decide if I use it by default (e.g $version use it automatically) or if you need to use ${version}${version_extra} when doing substitution.
Date: 2010-12-30 08:11
Sender: Török Edwin

Sorry the example should have been:
Executable "foo"
Path: .
MainIs: main.ml
GenerateBuildTime: true
if flag(has_git)
GenerateBuildVersion: "git describe --always --dirty", $version$
else
GenerateBuildVersion: $version$

And thanks for patiently answering all my feature requests :)
Date: 2010-12-30 08:01
Sender: Török Edwin

I think what I actually want are:
- substitution of Version from _oasis (can do with a .ab file already I think)
- flags for availibility of git (I think I can already get this with BuildTools)
- a command to generate a build version

So this feature request is about the latter.
A field like GenerateBuildVersion (that can be conditionally enabled based on some flags) would suffice. It could take 2 params: the command to run, and a fallback string (accepting substitutions).

For C projects I usually embed the git version in released executables as well, if 'git' is available at build time. If it is not (or we're built from a tarball with no .git) then the hardcoded version from configure is used.

I'd like to use something similar for OCaml as well. And since oasis is here I thought it'd be good to have the version generation in one place instead of everyone reinventing the wheel.

I understand the dependency issue, but I think this could be handled in _oasis via a flag:
Executable "foo"
Path: .
MainIs: main.ml
GenerateBuildTime: true
if flag(has_git)
GenerateBuildVersion: "git describe --always --dirty", $version$

And then myocamlbuild.ml would generate a file like this:
version.ml:
let version=0.1;; (* from Version in _oasis *)
let time = "2010/12/30 07h UTC";; (* generated by myocamlbuild.ml *)
let buildversion = "foo-1-gdb60563";;

If git is not available, or we're not in a git repo, or the git command exited with non-zero status, then it would fallback to this:
let version=0.1;; (* from Version in _oasis *)
let time = "2010/12/30 07h UTC";; (* generated by myocamlbuild.ml *)
let buildversion = version;;
Date: 2010-12-29 23:41
Sender: Sylvain Le Gall

At best, I can implement this for the setup-dev mode (i.e. developer mode). It cannot be implemented into setup.ml because it will add a dependency on git/darcs whatever.

I think it may make sense to implement it in setup-dev, do you agree ?

Attached Files:

Changes:

Field Old Value Date By
assigned_tonone2010-12-29 23:50gildor-admin