Skip to content

Commit

Permalink
[feature] compiler option: --minimal-version for Makefile
Browse files Browse the repository at this point in the history
   The purpose is to get quickly a clear error message about the version
   of the compiler, rather than a strange error message caused by
   an update in the compiler and/or in the stdlib.

   It is recommended to use this option in your Makefile for applications
   using new features, or new functions of the stdlib, or in any application
   published somewhere, and potentially compiled by people having
   wild and heterogeneous versions of Opa (nightly builds, from sources).
  • Loading branch information
Mathieu Barbin committed Jun 23, 2011
1 parent 7c93de3 commit 607c286
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 28 deletions.
34 changes: 34 additions & 0 deletions buildinfos/buildInfos.ml.post
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,37 @@ let git_version_counter =
let version_id = Printf.sprintf "%d-(%s)"
git_version_counter
opalang_git_sha

let assert_minimal_version s =
let check_int version =
if version > 27000
then
(*
At the time we write this code, the number of build
has been reset to 0.
*)
true
else
version <= opalang_git_version
in
try
let version = int_of_string s in
Some (check_int version)
with
| Failure "int_of_string" ->
(*
The given string may be: v45.
These tests are painful, but we are outside of libbase's scope there :)
*)
if String.length s > 0 && s.[0] = 'v'
then
let sub = String.sub s 1 (pred (String.length s)) in
try Some (check_int (int_of_string sub))
with Failure _ -> None
else
(* or S3.5 *)
if String.length s > 0 && s.[0] = 'S'
then
Some (s <= opa_version_name)
else
None
23 changes: 23 additions & 0 deletions buildinfos/buildInfos.mli
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,26 @@ val git_version_counter : int

(** From the different infos, we build a uniq version identifier *)
val version_id : string

(**
Check if the current version of the compiler is newer than a given string.
The purpose is to get quickly a clear error message about the version
of the compiler, rather than a strange error message caused by
an update in the compiler and/or in the stdlib.
It is recommended to use this option in your Makefile for applications
using new features, or new functions of the stdlib, or in any application
published somewhere, and potentially compiled by people having
wild and heterogeneous versions of Opa (nightly builds, from sources).
Support several formats:
-only the name, like "S3.5"
-simple int, in that case this will compare with the build id
HACK: for backward compatibility (reset of build number)
any number after 27000 is older than numbers between 0 and 27000.
If the function returns [None], that means that the given
string does not make sence as a version name.
*)
val assert_minimal_version : string -> bool option
54 changes: 28 additions & 26 deletions buildinfos/generate_buildinfos.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#!/bin/bash -eu
# -- begin LICENCE
# (c) 2006-2011 MLstate
# All rights reserved.
# This file is confidential and intended solely for the addressee(s).
# Any unauthorized use or dissemination is prohibited.
# end LICENCE --
# Copyright © 2011 MLstate

MLSTATE_DIFFING=${MLSTATE_DIFFING:-"0"}
# This file is part of OPA.

# OPA is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License, version 3, as published by
# the Free Software Foundation.

# OPA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.

# You should have received a copy of the GNU Affero General Public License
# along with OPA. If not, see <http://www.gnu.org/licenses/>.

# This script is used to generate the module BuildInfos
# it is called by bld at build time of the repositories.
# Since this module is very high regarding to the dependencies
# it is regenerated only in release mode, or after a clean.

MLSTATE_DIFFING=${MLSTATE_DIFFING:-"0"}

help () {
cat <<EOF
generating buildInfos.ml
Expand Down Expand Up @@ -66,21 +76,17 @@ git_version_cmd () { git log --pretty=oneline | wc -l; }
git_sha_cmd () { git log -n1 --pretty=format:%h; }
git_date_cmd () { git log -n1 --pretty=format:%ad --date=short; }

# special case for opalang, the origin is the publication
git_opalang_version_cmd () {
local ORIGIN_SHA='fccc6851ccd2cb4fd9e83ba7b8c8d6d780ed3e13'
git log --pretty=oneline "$ORIGIN_SHA".. | wc -l
}

is_git_root () {
LOOKED_FOR_REPO=$1
[ -d .git ] && git remote show -n origin | grep -q 'URL:.*'$LOOKED_FOR_REPO
}

# go_to_git_root () {
# REPO=$1
# if is_git_root $REPO; then return 0
# elif [ "$PWD" = "/" ]; then echo "[!] Git repo $REPO not found" >&2; return 1
# else cd ..; go_to_git_root $REPO
# fi
# }

# go_to_git_root "$ROOT_REPO" || exit 1

in_repo () {
REPO=$1; shift
P=$PWD
Expand Down Expand Up @@ -113,17 +119,13 @@ echo "let opa_version_name = \"${OPA_VERSION}\""
for repo in $REPOS ; do
if [ "$MLSTATE_DIFFING" = 1 ] ; then
echo "let ${repo}_git_version = 0"
else
echo "let ${repo}_git_version = $(in_repo $repo git_version_cmd)"
fi
done
echo

# git sha
for repo in $REPOS ; do
if [ "$MLSTATE_DIFFING" = 1 ] ; then
echo "let ${repo}_git_sha = \"diffing\""
else
if [ "$repo" = "$ROOT_REPO" ] ; then
echo "let ${repo}_git_version = $(in_repo $repo git_opalang_version_cmd)"
else
echo "let ${repo}_git_version = $(in_repo $repo git_version_cmd)"
fi
echo "let ${repo}_git_sha = \"$(in_repo $repo git_sha_cmd)\""
fi
done
Expand Down
36 changes: 34 additions & 2 deletions opalib/opaEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,40 @@ where options are :
("--js-check-bsl-types", Arg.Set js_check_bsl_types, " Enables runtime type checking of the types of bypasses");

(* m *)
("--mlcopt", Arg.String add_mlcopt, "<opt> Give option to ocaml compilation");
("--mllopt", Arg.String add_mllopt, "<opt> Give option to ocaml linking");

"--minimal-version",
Arg.String (fun s ->
match BuildInfos.assert_minimal_version s with
| None ->
OManager.error (
"option --minimal-version: @{<bright>%s@} not recognized@\n"^^
"@[<2>@{<bright>Hint@}:@\n"^^
"try e.g. S3.%%d, v%%d, or %%d@]"
)
s
| Some false ->
OManager.error (
"@[<2>This application needs a more recent version of Opa@\n"^^
"Required version: %s or later@\n"^^
"Current version: %s/%d@]"
)
s
BuildInfos.opa_version_name
BuildInfos.opalang_git_version
| Some true -> ()
),
"<version> Ensure that the compiler is newer than the given version"
;

"--mlcopt",
Arg.String add_mlcopt,
"<opt> Give option to ocaml compilation"
;

"--mllopt",
Arg.String add_mllopt,
"<opt> Give option to ocaml linking"
;

(* n *)

Expand Down

0 comments on commit 607c286

Please sign in to comment.