[Pkg-ocaml-maint-commits] [SCM] oasis2debian project branch, master, updated. 94ae27000298101188a629fbcc6b28420021fe10

Sylvain Le Gall gildor at debian.org
Sat Nov 20 00:58:51 UTC 2010


The following commit has been merged in the master branch:
commit 688a804b34fbd160fb2795a873c84365120ff3c0
Author: Sylvain Le Gall <gildor at debian.org>
Date:   Fri Nov 19 13:43:18 2010 +0100

    More reduction of version comparisons of build depends

diff --git a/src/BuildDepends.ml b/src/BuildDepends.ml
index 2bf40c1..9bfecb7 100644
--- a/src/BuildDepends.ml
+++ b/src/BuildDepends.ml
@@ -2,6 +2,7 @@
 open OASISTypes
 open OASISUtils
 open OASISMessage
+open OASISVersion
 open Common
 open ExtString
 open FileUtil
@@ -30,8 +31,8 @@ let cmp_opt_merge v1_opt v2_opt =
   match v1_opt, v2_opt with
     | Some v1, Some v2 -> 
         Some 
-          (OASISVersion.comparator_reduce 
-             (OASISVersion.VAnd (v1, v2)))
+          (OASISVersionExt.comparator_reduce 
+             (VAnd (v1, v2)))
     | None, opt | opt, None ->
         opt
 
@@ -54,15 +55,29 @@ let add_depends ?(arch_spec=`All) nm ver_opt st =
 
     SetDepends.add (nm, ver_opt, arch_spec) st
 
-let string_of_depends (nm, ver_opt, arch_spec) = 
+let string_of_depends ~ctxt (nm, ver_opt, arch_spec) = 
   let arch_str = 
     Arch.Spec.to_string_build_depends arch_spec
   in
   let ver_str =
     match ver_opt with 
       | Some v ->
-          Printf.sprintf " (%s)"
-            (OASISVersion.string_of_comparator v)
+          begin
+            begin
+              match v with 
+                | VGreater _ | VGreaterEqual _ 
+                | VLesser _ | VLesserEqual _  
+                | VEqual _ ->
+                    ()
+                | VOr _ | VAnd _ ->
+                    error ~ctxt 
+                      "Version constraint '%s' on build depends '%s' is too complex"
+                      (string_of_comparator v)
+                      nm
+            end;
+            Printf.sprintf " (%s)"
+              (string_of_comparator v)
+          end
       | None ->
           ""
   in
@@ -346,7 +361,7 @@ let get ~ctxt pkg =
 
   let debian_depends = 
     let cos = 
-      OASISVersion.comparator_of_string 
+      comparator_of_string 
     in
       List.fold_right 
         SetDepends.add 
@@ -390,6 +405,6 @@ let get ~ctxt pkg =
     (* Translate depends into string *)
     SetDepends.fold
       (fun dep lst ->
-         string_of_depends dep :: lst)
+         string_of_depends ~ctxt dep :: lst)
       debian_depends
 
diff --git a/src/OASISVersionExt.ml b/src/OASISVersionExt.ml
new file mode 100644
index 0000000..850918e
--- /dev/null
+++ b/src/OASISVersionExt.ml
@@ -0,0 +1,77 @@
+
+open OASISVersion
+
+(*
+let debug_compare cmp = 
+  Format.fprintf Format.std_formatter
+    "@[<v>Comparator '%s':@ @[%a@]@]\n"
+    (string_of_comparator cmp)
+    (fun fmt cmp -> ODN.pp_odn fmt cmp)
+    (odn_of_comparator cmp)
+ *)
+
+let comparator_reduce cmp = 
+
+  let vmin v1 v2 = 
+    if version_compare v1 v2 < 0 then
+      v1
+    else
+      v2
+  in
+
+  let vmax v1 v2 =
+    if version_compare v1 v2 < 0 then
+      v2
+    else
+      v1
+  in
+
+  let rec reduce cmp = 
+(*
+    debug_compare cmp;
+ *)
+    match cmp with
+      (* TODO: this can be improved to reduce more *)
+      | VAnd (VGreater v1, VGreater v2) ->
+          VGreater (vmax v1 v2)
+      | VAnd (VGreaterEqual v1, VGreaterEqual v2) ->
+          VGreaterEqual (vmax v1 v2)
+
+      | VAnd (VLesser v1, VLesser v2) ->
+          VLesser (vmin v1 v2)
+      | VAnd (VLesserEqual v1, VLesserEqual v2) ->
+          VLesserEqual (vmin v1 v2)
+
+      | VAnd (c1, c2) ->
+          begin
+            match reduce c1, reduce c2 with 
+              | c1', c2' when c1' = c2' -> c1'
+              | c1', c2' -> VAnd (c1', c2')
+          end
+
+      | VOr (c1, c2) ->
+          begin
+            match reduce c1, reduce c2 with
+              | c1', c2' when c1' = c2' -> c1'
+              | c1', c2' -> VOr (c1', c2')
+          end
+
+      | cmp ->
+          cmp
+  in
+    reduce cmp
+
+
+(*
+let red_cmp str = 
+  Printf.printf "%s -> %s"
+    str
+    (string_of_comparator (comparator_reduce (comparator_of_string str)))
+
+
+let () = 
+  List.iter red_cmp 
+    [
+      ">= 3.10.2 || >= 3.11.1-3~";
+    ]
+ *)

-- 
oasis2debian project



More information about the Pkg-ocaml-maint-commits mailing list