From 6f2675a79e30e103b7e4af069a8aec899d77c4c3 Mon Sep 17 00:00:00 2001 From: Andre Maroneze <andre.oliveiramaroneze@cea.fr> Date: Wed, 28 Nov 2018 15:36:11 +0100 Subject: [PATCH] [Kernel] add accessors for retrieving major/minor version number --- Makefile.generating | 4 ++++ src/kernel_internals/runtime/config.ml.in | 4 ++++ src/kernel_internals/runtime/config.mli | 8 ++++++++ tests/misc/oracle/version.res.oracle | 2 ++ tests/misc/version.i | 3 +++ tests/misc/version.ml | 20 ++++++++++++++++++++ 6 files changed, 41 insertions(+) create mode 100644 tests/misc/oracle/version.res.oracle create mode 100644 tests/misc/version.i create mode 100644 tests/misc/version.ml diff --git a/Makefile.generating b/Makefile.generating index a369e8ae688..eece5c22c89 100644 --- a/Makefile.generating +++ b/Makefile.generating @@ -41,6 +41,8 @@ tests/ptests_config: Makefile.generating share/Makefile.config $(CHMOD_RO) $@ ALL_LIBRARY_NAMES=$(shell ocamlfind query -r -p-format $(LIBRARY_NAMES) $(LIBRARY_NAMES_GUI)) +MAJOR_VERSION=$(shell $(SED) 's/^\([0-9]\+\)\..*/\1/' VERSION) +MINOR_VERSION=$(shell $(SED) 's/^[0-9]\+\.\([0-9]\+\).*/\1/' VERSION) $(CONFIG_FILE): $(CONFIG_FILE).in VERSION VERSION_CODENAME share/Makefile.config Makefile.generating configure.in $(SED) \ @@ -64,6 +66,8 @@ $(CONFIG_FILE): $(CONFIG_FILE).in VERSION VERSION_CODENAME share/Makefile.config -e "s|@OPTDOT@|$(OPTDOT)|" \ -e "s|@HAS_YOJSON@|$(if $(filter yes,$(HAS_YOJSON)),true,false)|" \ -e "s|@EXE@|$(EXE)|" \ + -e "s|@MAJOR_VERSION@|$(MAJOR_VERSION)|" \ + -e "s|@MINOR_VERSION@|$(MINOR_VERSION)|" \ $< > $@.tmp @touch -r $@.tmp $< $(CP_IF_DIFF) $@.tmp $@ diff --git a/src/kernel_internals/runtime/config.ml.in b/src/kernel_internals/runtime/config.ml.in index c51c4c0be3c..3ae62891227 100644 --- a/src/kernel_internals/runtime/config.ml.in +++ b/src/kernel_internals/runtime/config.ml.in @@ -26,6 +26,10 @@ let version = "@VERSION@" let codename = "@VERSION_CODENAME@" let version_and_codename = version ^ " (" ^ codename ^ ")" +let major_version = @MAJOR_VERSION@ + +let minor_version = @MINOR_VERSION@ + let is_gui = ref false let ocamlc = "@OCAMLC@" diff --git a/src/kernel_internals/runtime/config.mli b/src/kernel_internals/runtime/config.mli index 2d49810b265..1b0e5313f47 100644 --- a/src/kernel_internals/runtime/config.mli +++ b/src/kernel_internals/runtime/config.mli @@ -34,6 +34,14 @@ val version_and_codename: string (** Frama-C version and codename. @since Frama-C+dev *) +val major_version: int +(** Frama-C major version number. + @since Frama-C+dev *) + +val minor_version: int +(** Frama-C minor version number. + @since Frama-C+dev *) + val is_gui: bool ref (** Is the Frama-C GUI running? @since Beryllium-20090601-beta1 *) diff --git a/tests/misc/oracle/version.res.oracle b/tests/misc/oracle/version.res.oracle new file mode 100644 index 00000000000..61e48a31ac5 --- /dev/null +++ b/tests/misc/oracle/version.res.oracle @@ -0,0 +1,2 @@ +[kernel] Parsing tests/misc/version.i (no preprocessing) +[kernel] version numbers match diff --git a/tests/misc/version.i b/tests/misc/version.i new file mode 100644 index 00000000000..cd0bcd0bf86 --- /dev/null +++ b/tests/misc/version.i @@ -0,0 +1,3 @@ +/* run.config + OPT: -load-script tests/misc/version.ml +*/ diff --git a/tests/misc/version.ml b/tests/misc/version.ml new file mode 100644 index 00000000000..2105830a936 --- /dev/null +++ b/tests/misc/version.ml @@ -0,0 +1,20 @@ +let re_version = Str.regexp "^\\([0-9]+\\)\\.\\([0-9]+\\)" + +let run () = + let version_str = Config.version in + if Str.string_match re_version version_str 0 then + let major = Str.matched_group 1 version_str in + let minor = Str.matched_group 2 version_str in + if major = string_of_int Config.major_version && + minor = string_of_int Config.minor_version + then + Kernel.feedback "version numbers match" + else + Kernel.abort + "error parsing major/minor version: expected %s.%s, got %d.%d" + major minor Config.major_version Config.minor_version + else + Kernel.abort + "could not parse Config.version" + +let () = Db.Main.extend run -- GitLab