[Pkg-ocaml-maint-commits] [SCM] oasis2debian project branch, master, updated. 9e7f2f8d6c194da78572a83d896cc068a30e3c1d

Sylvain Le Gall gildor at debian.org
Thu Nov 18 13:00:38 UTC 2010


The following commit has been merged in the master branch:
commit 9e7f2f8d6c194da78572a83d896cc068a30e3c1d
Author: Sylvain Le Gall <gildor at debian.org>
Date:   Thu Nov 18 12:46:43 2010 +0000

    Only take into account library/exec/doc built
    
    Split Arch/Expr out of BuilDepends and generation of package out of
    Main.ml. Evaluate expressions to know if a library/exec/doc is built.

diff --git a/src/Arch.ml b/src/Arch.ml
new file mode 100644
index 0000000..63c7484
--- /dev/null
+++ b/src/Arch.ml
@@ -0,0 +1,123 @@
+
+(** Debian architectures 
+  *)
+
+type t = 
+      {
+        arch_name: string;
+        arch_conf: (string * string) list;
+      }
+
+let compare t1 t2 = 
+  String.compare t1.arch_name t2.arch_name
+
+
+let rall = 
+  ref []
+
+let mk nm conf = 
+  let res = 
+    {
+      arch_name = nm;
+      arch_conf = conf;
+    }
+  in
+    rall := res :: !rall;
+    res
+
+let linux_i386 = 
+  mk "i386" []
+
+let linux_amd64 = 
+  mk "amd64" []
+
+(*
+    "alpha", linux_alpha;
+    "armel", linux_armel;
+    "hppa", linux_hppa;
+    "hurd-i386", hurd_i386;
+    "ia64", linux_ia64;
+    "kfreebsd-amd64", kfreebsd_amd64;
+    "kfreebsd-i386", kfreebsd_i386;
+    "mips", linux_mips;
+    "mipsel", linux_mipsel;
+    "powerpc", linux_powerpc;
+    "s390", linux_s390;
+    "sparc", linux_sparc;
+*)
+
+let all () = 
+  !rall
+
+
+let to_string {arch_name = nm} =
+  nm
+
+(** Handle list of architectures 
+  *)
+module Spec =
+struct
+
+  type arch = t
+  type t = [ `All | `Only of arch * arch list ]
+
+  let mem t arch = 
+    match t with
+      | `All -> true (* Match all arches *)
+      | `Only (a, lst) ->
+          List.exists
+            (fun a' -> compare arch a' = 0) 
+            (a :: lst)
+
+  let merge t1 t2 = 
+    match t1, t2 with 
+      | `All, `Only _ 
+      | `Only _, `All 
+      | `All, `All ->
+          `All
+
+      | t, `Only (a, lst) ->
+          begin
+            List.fold_left
+              (fun t e ->
+                 match t, mem t e with 
+                   | `Only (a, lst), false ->
+                       `Only (a, e :: lst)
+                   | t, _ ->
+                       t)
+              t
+              (a :: lst)
+          end
+
+
+  let to_string_build_depends = 
+    function
+      | `All -> 
+          ""
+      | `Only (hd, tl) as t ->
+          begin
+            (* All arches of the package *)
+            let lst = hd :: tl in 
+            let neg =
+              List.map 
+                (fun arch -> "!"^(to_string arch)) 
+                (List.filter 
+                   (* Remove arches of the package *)
+                   (fun arch -> not (mem t arch)) 
+                   (* All arches *)
+                   (all ()))
+            in
+            let lst = 
+              List.map to_string lst
+            in
+
+            let lst =
+              if List.length neg < List.length lst then
+                neg
+              else
+                lst
+            in            
+              Printf.sprintf " [%s]" (String.concat ", " lst)
+          end
+end
+
diff --git a/src/BuildDepends.ml b/src/BuildDepends.ml
index edbbad2..8f40bc1 100644
--- a/src/BuildDepends.ml
+++ b/src/BuildDepends.ml
@@ -7,10 +7,6 @@ open ExtString
 open FileUtil
 open FilePath
 
-type arch = 
-  | ArchAll
-  | ArchOnly of string * string list
-
 module SetExec = 
   Set.Make
     (String)
@@ -22,112 +18,42 @@ module SetFindlib =
        let compare = Pervasives.compare
      end)
 
-let all_confs = 
-  let linux_i386 = 
-    []
-  in
-
-  let linux_amd64 = 
-    []
-  in
-
-    [
-      "i386", linux_i386;
-      "amd64", linux_amd64;
-(*
-      "alpha", linux_alpha;
-      "armel", linux_armel;
-      "hppa", linux_hppa;
-      "hurd-i386", hurd_i386;
-      "ia64", linux_ia64;
-      "kfreebsd-amd64", kfreebsd_amd64;
-      "kfreebsd-i386", kfreebsd_i386;
-      "mips", linux_mips;
-      "mipsel", linux_mipsel;
-      "powerpc", linux_powerpc;
-      "s390", linux_s390;
-      "sparc", linux_sparc;
- *)
-    ]
-
 module SetDepends =
   Set.Make
     (struct
-       type t = string * OASISVersion.comparator option * arch 
+       type t = string * OASISVersion.comparator option * Arch.Spec.t
        let compare (nm1, _, _) (nm2, _, _) = 
          String.compare nm1 nm2
      end)
 
-let add_depends ?arch nm ver_opt st =
-  let ver_opt', arch' =
+let add_depends ?(arch_spec=`All) nm ver_opt st =
+  let ver_opt, arch_spec =
     try 
-      let _, ver_opt', arch' = 
+      let _, ver_opt', arch_spec' = 
         List.find
           (fun (nm', _, _) -> nm' = nm)
           (SetDepends.elements st)
       in
-        ver_opt', Some arch'
+      let ver_opt = 
+        match ver_opt', ver_opt with
+          | Some v1, Some v2 -> 
+              Some 
+                (OASISVersion.comparator_reduce 
+                   (OASISVersion.VAnd (v1, v2)))
+          | None, opt | opt, None ->
+              opt
+      in
+        ver_opt, Arch.Spec.merge arch_spec arch_spec'
 
     with Not_found ->
-      None, None
-  in
-
-  let ver_opt = 
-    match ver_opt, ver_opt' with
-      | Some v1, Some v2 ->
-          Some 
-            (OASISVersion.comparator_reduce 
-               (OASISVersion.VAnd (v1, v2)))
-      | None, opt
-      | opt, _ ->
-          opt
+      ver_opt, arch_spec
   in
 
-  let arch =
-    match arch, arch' with
-      | Some a, None -> 
-          ArchOnly (a, [])
-
-      | Some _, Some ArchAll ->
-          ArchAll
-
-      | Some a, Some (ArchOnly (hd, tl)) ->
-          if not (List.mem a (hd :: tl)) then
-            ArchOnly (hd, a :: tl)
-          else
-            ArchOnly (hd, tl)
-
-      | None, _ ->
-          ArchAll
-  in
+    SetDepends.add (nm, ver_opt, arch_spec) st
 
-    SetDepends.add (nm, ver_opt, arch) st
-
-let string_of_depends (nm, ver_opt, arch) = 
+let string_of_depends (nm, ver_opt, arch_spec) = 
   let arch_str = 
-    match arch with 
-      | ArchAll -> ""
-      | ArchOnly (hd, tl) ->
-          begin
-            (* All arches of the package *)
-            let lst = hd :: tl in 
-            let neg =
-              List.map ((^) "!") 
-                (List.filter 
-                   (* Remove arches of the package *)
-                   (fun nm -> not (List.mem nm lst)) 
-                   (* All arches *)
-                   (List.map fst all_confs))
-            in
-
-            let lst =
-              if List.length neg < List.length lst then
-                neg
-              else
-                lst
-            in            
-              Printf.sprintf " [%s]" (String.concat ", " lst)
-          end
+    Arch.Spec.to_string_build_depends arch_spec
   in
   let ver_str =
     match ver_opt with 
@@ -142,66 +68,50 @@ let string_of_depends (nm, ver_opt, arch) =
 (* Compute build dependencies, against real debian packages
  *)
 let get ~ctxt pkg = 
-
-  let depends_of_conf conf acc = 
-    let eval conf = 
-      OASISExpr.choose
-        (fun nm -> 
-           try 
-             List.assoc nm conf
-           with Not_found as e ->
-             error ~ctxt "OASIS variable '%s' not defined" nm;
-             raise e)
-    in
-
-    let conf = 
-      (* Evaluate flag values and add then to conf *)
-      List.fold_left 
-        (fun conf ->
-           function 
-             | Flag (cs, flag) ->
-                 (cs.cs_name, 
-                  string_of_bool (eval conf flag.flag_default))
-                 :: conf
-             | Library _ | Executable _ | Doc _ | Test _ | SrcRepo _ ->
-                 conf)
-        conf
-        pkg.sections
+  let eval = 
+    let t = 
+      Expr.create ~ctxt pkg
     in
+      Expr.choose ~ctxt t 
+  in
 
+  let depends_of_arch arch acc = 
     let depends_of_bs bs ((exec, fndlb) as acc) =
-      if eval conf bs.bs_build && eval conf bs.bs_install then
-        begin
-          let exec = 
-            List.fold_left 
-              (fun exec ->
-                 function
-                   | ExternalTool nm -> 
-                       SetExec.add nm exec
-                   | InternalExecutable _ ->
-                       exec)
-              exec
-              bs.bs_build_tools
-          in
+      let eval  =
+        eval (`Only arch)
+      in
+        if eval bs.bs_build && eval bs.bs_install then
+          begin
+            let exec = 
+              List.fold_left 
+                (fun exec ->
+                   function
+                     | ExternalTool nm -> 
+                         SetExec.add nm exec
+                     | InternalExecutable _ ->
+                         exec)
+                exec
+                bs.bs_build_tools
+            in
 
-          let fndlb =
-            List.fold_left
-              (fun fndlb ->
-                 function
-                   | FindlibPackage (nm, ver_opt) ->
-                       SetFindlib.add (nm, ver_opt) fndlb
-                   | InternalLibrary _ ->
-                       fndlb)
-              fndlb
-              bs.bs_build_depends
-          in
+            let fndlb =
+              List.fold_left
+                (fun fndlb ->
+                   function
+                     | FindlibPackage (nm, ver_opt) ->
+                         SetFindlib.add (nm, ver_opt) fndlb
+                     | InternalLibrary _ ->
+                         fndlb)
+                fndlb
+                bs.bs_build_depends
+            in
 
-            exec, fndlb
-        end
-      else
-        begin
-          acc
-        end
+              exec, fndlb
+          end
+        else
+          begin
+            acc
+          end
     in
 
       List.fold_left 
@@ -226,7 +136,7 @@ let get ~ctxt pkg =
             "Cannot determine ocaml standard library directory"
   in
 
-  let debian_depends_of_depends ?arch exec fndlb st = 
+  let debian_depends_of_depends ?arch_spec exec fndlb st = 
     (* Find file *)
     let find_file ?(dev_pkg=false) fn = 
       let filter lst = 
@@ -368,26 +278,29 @@ let get ~ctxt pkg =
     let st = 
       SetExec.fold
         (fun nm st ->
-           add_depends ?arch (find_exec nm) None st)
+           add_depends ?arch_spec (find_exec nm) None st)
         exec
         st
     in
 
       SetFindlib.fold
         (fun (nm, ver_opt) st ->
-           add_depends ?arch (find_findlib nm) ver_opt st)
+           add_depends ?arch_spec (find_findlib nm) ver_opt st)
         fndlb
         st
   in
 
   let lst = 
-    List.map
-      (fun (nm, conf) ->
-         nm, 
-         depends_of_conf 
-           conf 
-           (SetExec.empty, SetFindlib.empty))
-      all_confs
+    List.rev_map
+      (fun arch ->
+         let arch_spec = 
+           `Only (arch, [])
+         in
+           arch_spec, 
+           depends_of_arch
+             arch
+             (SetExec.empty, SetFindlib.empty))
+      (Arch.all ())
   in
 
   (* Compute common dependencies *)
@@ -408,8 +321,8 @@ let get ~ctxt pkg =
     List.fold_right 
       SetDepends.add 
       [
-        "ocaml-findlib", pkg.findlib_version, ArchAll;
-        "ocaml-nox", pkg.ocaml_version, ArchAll;
+        "ocaml-findlib", pkg.findlib_version, `All;
+        "ocaml-nox", pkg.ocaml_version, `All;
       ]
       SetDepends.empty
   in
@@ -425,11 +338,11 @@ let get ~ctxt pkg =
   (* Check for extra dependencies for particular architecture *)
   let debian_depends = 
     List.fold_left 
-      (fun st (arch, (exec, fndlb)) ->
+      (fun st (arch_spec, (exec, fndlb)) ->
          let exec'  = SetExec.diff exec common_exec in
          let fndlb' = SetFindlib.diff fndlb common_fndlb in
            debian_depends_of_depends
-             ~arch
+             ~arch_spec
              exec'
              fndlb'
              st)
diff --git a/src/Common.ml b/src/Common.ml
index a9b9542..45283a4 100644
--- a/src/Common.ml
+++ b/src/Common.ml
@@ -16,6 +16,7 @@ type t =
     homepage:      string;
     uploader:      string;
     pkg:           OASISTypes.package;
+    expr:          Expr.t;
 
     (* Standard Debian package *)
     deb_std:       deb_pkg option;
@@ -94,3 +95,5 @@ let assert_command_output ~ctxt cmd =
 let output_content str chn = 
   output_string chn (str^"\n")
 
+
+module MapString = Map.Make(String)
diff --git a/src/Expr.ml b/src/Expr.ml
new file mode 100644
index 0000000..83e4248
--- /dev/null
+++ b/src/Expr.ml
@@ -0,0 +1,87 @@
+
+open OASISTypes
+open OASISMessage
+
+module MapString = 
+  Map.Make(String)
+
+module MapArch = 
+  Map.Make(Arch)
+
+type t = (string MapString.t) MapArch.t
+
+let choose_simple ~ctxt conf = 
+  OASISExpr.choose
+    (fun nm -> 
+       try 
+         MapString.find nm conf
+       with Not_found as e ->
+         error ~ctxt "OASIS variable '%s' not defined" nm;
+         raise e)
+
+let create ~ctxt pkg = 
+
+  let add_arch mp arch = 
+    let conf = 
+      (* Convert assoc list into a map *)
+      List.fold_left
+        (fun mp (nm, vl) -> MapString.add nm vl mp)
+        MapString.empty
+        arch.Arch.arch_conf
+    in
+
+    let conf = 
+      (* Evaluate flag values and add them to conf *)
+      List.fold_left 
+        (fun conf ->
+           function 
+             | Flag (cs, flag) ->
+                 MapString.add
+                   cs.cs_name
+                   (string_of_bool 
+                      (choose_simple ~ctxt conf flag.flag_default))
+                   conf
+             | Library _ | Executable _ | Doc _ | Test _ | SrcRepo _ ->
+                 conf)
+        conf
+        pkg.sections
+    in
+      MapArch.add arch conf mp
+  in
+
+    List.fold_left 
+      add_arch 
+      MapArch.empty 
+      (Arch.all ())
+
+type query_arch = 
+        [ 
+          `All of bool -> bool -> bool 
+          (** Combine results *)
+
+        | `Only of Arch.t
+        ]
+
+
+let choose ~ctxt t arch choice = 
+  match arch with 
+    | `All f ->
+        begin
+          let acc = 
+            MapArch.fold
+              (fun _ conf acc ->
+                 (choose_simple ~ctxt conf choice) :: acc)
+              t
+              []
+          in
+            match acc with 
+              | hd :: tl ->
+                  List.fold_left f hd tl
+              | [] ->
+                  invalid_arg "Expr.choose"
+        end
+
+    | `Only arch ->
+        choose_simple ~ctxt (MapArch.find arch t) choice
+
+
diff --git a/src/GenPkg.ml b/src/GenPkg.ml
new file mode 100644
index 0000000..841c283
--- /dev/null
+++ b/src/GenPkg.ml
@@ -0,0 +1,156 @@
+
+(** Compute package to generate 
+  *)
+
+open OASISTypes
+open Common
+
+let library_name = 
+  Conf.create 
+    ~cli:"--library-name"
+    "Short name of the library (XXX in libXXX-ocaml-dev)"
+    (Conf.Fun
+       (fun () ->
+          failwith "Not set"))
+
+let set ~ctxt t = 
+  let eval = 
+    Expr.choose 
+      ~ctxt 
+      t.expr 
+      (`All (fun x y -> x || y))
+  in
+
+  let lib, doc, bin =
+    List.fold_left
+      (fun ((lib, doc, bin) as acc) ->
+         function
+           | Library (cs, bs, lib') ->
+               if eval bs.bs_build && eval bs.bs_install then
+                 ((cs, bs, lib') :: lib), doc, bin
+               else
+                 acc
+
+           | Executable (cs, bs, exec) ->
+               if eval bs.bs_build && eval bs.bs_install then
+                 lib, doc, ((cs, bs, exec) :: bin)
+               else
+                 acc
+
+           | Doc (cs, doc') ->
+               if eval doc'.doc_build && eval doc'.doc_install then
+                 lib, ((cs, doc') :: doc), bin
+               else
+                 acc
+
+           | Flag _ | Test _ | SrcRepo _ ->
+               acc)
+      ([], [], [])
+      t.pkg.sections
+  in
+
+  let arch lst = 
+    let is_all = 
+      List.for_all
+        (function
+           |  {bs_compiled_object = Byte} ->
+               true
+
+           | _ -> 
+               false)
+        (List.rev_map 
+           (fun (_, bs, _) -> bs)
+           lst)
+    in
+      if is_all then
+        "all"
+      else
+        "any"
+  in
+
+  let mk_deb nm lst = 
+    {name = nm; arch = arch lst}
+  in
+
+  let base_name = 
+    if Conf.is_set library_name then
+      begin
+        Conf.get ~ctxt library_name 
+      end
+    else
+      begin
+        match OASISLibrary.group_libs t.pkg with 
+          | [hd] ->
+              (* First method: if there is a single findlib library use its name
+               *)
+              OASISLibrary.findlib_of_group hd
+
+          | _ ->
+              (* Default method: try to guess the target name using source name 
+               *)
+              List.fold_left
+                (fun name pat -> 
+                   Pcre.replace ~pat ~templ:"" name)
+
+                (* Start with the package name *)
+                t.pkg.OASISTypes.name
+                ["^ocaml-?"; "-?ocaml$"]
+      end
+  in
+
+  let spf fmt = 
+    Printf.sprintf fmt
+  in
+
+  let add_doc nm t = 
+    (* Add doc package, only if more than one documentation
+     * shipped.
+     *)
+    if List.length doc > 1 then
+      {t with 
+           deb_doc = Some (mk_deb nm [])}
+    else
+      t
+  in
+
+  let t =
+    (* Determine if we have bin+dev+runtime *)
+    match lib, bin with
+      | [], bin ->
+          begin
+            (* Only a binary package, name = source name *)
+            let base_name = 
+              t.pkg.OASISTypes.name
+            in
+              add_doc 
+                (base_name^"-doc")
+                {t with deb_std = Some (mk_deb base_name bin)} 
+          end
+
+      | lib, bin ->
+          begin 
+            (* Library only *)
+            let t  = 
+              {t with 
+                   deb_dev = 
+                     Some (mk_deb (spf "lib%s-ocaml-dev" base_name) lib,
+                           mk_deb (spf "lib%s-ocaml" base_name) lib)}
+            in
+
+            (* Also executables ? *)
+            let t =
+              if bin <> [] then
+                {t with 
+                     deb_std = 
+                       Some (mk_deb (spf "lib%s-ocaml-bin" base_name) bin)}
+              else
+                t
+            in
+
+              add_doc 
+                (spf "lib%s-ocaml-doc" base_name)
+                t
+          end
+  in
+
+    t
diff --git a/src/Main.ml b/src/Main.ml
index 950d295..c6a15bc 100644
--- a/src/Main.ml
+++ b/src/Main.ml
@@ -31,14 +31,6 @@ let uploader =
           with _ ->
             failwith "Unable to guess uploader"))
 
-let library_name = 
-  Conf.create 
-    ~cli:"--library-name"
-    "Short name of the library (XXX in libXXX-ocaml-dev)"
-    (Conf.Fun
-       (fun () ->
-          failwith "Not set"))
-
 let () = 
   let () = 
     (* Clean ENV *)
@@ -56,6 +48,10 @@ let () =
       ~ctxt
       "_oasis"
   in
+                 
+  let expr = 
+    Expr.create ~ctxt pkg
+  in
 
   let dflt r x =
     match x, Conf.is_set r with 
@@ -90,134 +86,16 @@ let () =
       homepage      = Conf.get ~ctxt homepage;
       uploader      = Conf.get ~ctxt uploader;
       pkg           = pkg;
+      expr          = expr;
       deb_std       = None;
       deb_dev       = None;
       deb_doc       = None;
     }
   in
 
-  let lib, doc, bin =
-    List.fold_left
-      (fun ((lib, doc, bin) as acc) ->
-         function
-           | Library (cs, bs, lib') ->
-               ((cs, bs, lib') :: lib), doc, bin
-           | Executable (cs, bs, exec) ->
-               lib, doc, ((cs, bs, exec) :: bin)
-           | Doc (cs, doc') ->
-               lib, ((cs, doc') :: doc), bin
-           | Flag _ | Test _ | SrcRepo _ ->
-               acc)
-      ([], [], [])
-      pkg.sections
-  in
-
-  let arch lst = 
-    let is_all = 
-      List.for_all
-        (function
-           | {bs_install = [OASISExpr.EBool true, false]} ->
-               (* No install, don't take into account for arch *)
-               true 
-                 
-           |  {bs_compiled_object = Byte} ->
-               true
-
-           | _ -> 
-               false)
-        (List.rev_map 
-           (fun (_, bs, _) -> bs)
-           lst)
-    in
-      if is_all then
-        "all"
-      else
-        "any"
-  in
-
-  let mk_deb nm lst = 
-    {name = nm; arch = arch lst}
-  in
-
-  let base_name = 
-    if Conf.is_set library_name then
-      begin
-        Conf.get ~ctxt library_name 
-      end
-    else
-      begin
-        match OASISLibrary.group_libs pkg with 
-          | [hd] ->
-              (* First method: if there is a single findlib library use its name
-               *)
-              OASISLibrary.findlib_of_group hd
-
-          | _ ->
-              (* Default method: try to guess the target name using source name 
-               *)
-              List.fold_left
-                (fun name pat -> 
-                   Pcre.replace ~pat ~templ:"" name)
-
-                (* Start with the package name *)
-                t.pkg.OASISTypes.name
-                ["^ocaml-?"; "-?ocaml$"]
-      end
-  in
-
-  let spf fmt = 
-    Printf.sprintf fmt
-  in
-
-  let add_doc nm t = 
-    (* Add doc package, only if more than one documentation
-     * shipped.
-     *)
-    if List.length doc > 1 then
-      {t with 
-           deb_doc = Some (mk_deb nm [])}
-    else
-      t
-  in
-
-  let t =
-    (* Determine if we have bin+dev+runtime *)
-    match lib, bin with
-      | [], bin ->
-          begin
-            (* Only a binary package, name = source name *)
-            let base_name = 
-              t.pkg.OASISTypes.name
-            in
-              add_doc 
-                (base_name^"-doc")
-                {t with deb_std = Some (mk_deb base_name bin)} 
-          end
-
-      | lib, bin ->
-          begin 
-            (* Library only *)
-            let t  = 
-              {t with 
-                   deb_dev = 
-                     Some (mk_deb (spf "lib%s-ocaml-dev" base_name) lib,
-                           mk_deb (spf "lib%s-ocaml" base_name) lib)}
-            in
-
-            (* Also executables ? *)
-            let t =
-              if bin <> [] then
-                {t with 
-                     deb_std = 
-                       Some (mk_deb (spf "lib%s-ocaml-bin" base_name) bin)}
-              else
-                t
-            in
-
-              add_doc 
-                (spf "lib%s-ocaml-doc" base_name)
-                t
-          end
+  let t = 
+    (* Fix package generated *)
+    GenPkg.set ~ctxt t
   in
 
   (* Create debian/ and debian/compat *)

-- 
oasis2debian project



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