[Debian-bootstrap] [PATCH 1/2] Implement buildprofile support

josch j.schauer at email.de
Mon Jul 23 17:48:05 MSK 2012


 - specified in Build-Depends and Build-Conflicts after the architecture list
 - enclosed in < and >
 - same rules as for architecture list wrt negation
 - sources2packages has to be adapted because of positive buildprofile lists
---
 deb/format822.ml        |    3 +-
 deb/packages_lexer.mll  |    3 +-
 deb/packages_parser.mly |   27 +++++++++++++--
 deb/sources.ml          |   88 +++++++++++++++++++++++++++++++++--------------
 4 files changed, 91 insertions(+), 30 deletions(-)

diff --git a/deb/format822.ml b/deb/format822.ml
index d6f9ec9..1dd3019 100644
--- a/deb/format822.ml
+++ b/deb/format822.ml
@@ -48,6 +48,7 @@ let parse_from_ch _parser ic =
 type name = string
 type version = string
 type architecture = string
+type buildprofile = string
 type vpkgname = (string * architecture option)
 type multiarch = [ `Foreign | `Allowed | `None | `Same ]
 type source = (name * version option)
@@ -58,7 +59,7 @@ type vpkg = (vpkgname * constr option)
 type vpkglist = vpkg list
 type vpkgformula = vpkg list list
 
-type builddep = (vpkg * (bool * architecture) list)
+type builddep = (vpkg * (bool * architecture) list * (bool * buildprofile) list)
 type builddepslist = builddep list
 type builddepsformula = builddep list list
 
diff --git a/deb/packages_lexer.mll b/deb/packages_lexer.mll
index ce8554b..bc580ce 100644
--- a/deb/packages_lexer.mll
+++ b/deb/packages_lexer.mll
@@ -28,7 +28,8 @@ let ident = (letter | digit) (letter | digit | symbols)*
 rule token_deb = parse
   | (">=" | "<=") as op { RELOP op }
   | (">>" | "<<") as op { RELOP op }
-  | ('>' | '<') as op   { RELOP (String.make 1 op) }
+  | '<'                 { LT }
+  | '>'                 { GT }
   | '='                 { EQ }
   | ':'                 { COLON }
   | '/'                 { SLASH }
diff --git a/deb/packages_parser.mly b/deb/packages_parser.mly
index 24261b7..7ee875e 100644
--- a/deb/packages_parser.mly
+++ b/deb/packages_parser.mly
@@ -22,7 +22,7 @@ let parse_multiarch = function
 %}
 
 %token <string> IDENT VIDENT STRING RELOP
-%token LBRACKET RBRACKET LPAREN RPAREN
+%token LBRACKET RBRACKET LPAREN RPAREN LT GT
 %token COMMA PIPE EQ BANG 
 %token PLUS MINUS COLON SLASH
 %token EOL
@@ -84,6 +84,8 @@ source:
 
 relop:
   | RELOP       { $1 }
+  | LT          { "<" }
+  | GT          { ">" }
   | EQ          { "=" }
 ;
 
@@ -124,8 +126,10 @@ or_formula:
 /**************************************/ 
 
 buidldep:
-  |vpkg                            { ($1,[]) }
-  |vpkg LBRACKET buildarchlist RBRACKET { ($1,$3) }
+  |vpkg                            { ($1,[],[]) }
+  |vpkg LBRACKET buildarchlist RBRACKET { ($1,$3,[]) }
+  |vpkg LT buildprofilelist GT { ($1,[],$3) }
+  |vpkg LBRACKET buildarchlist RBRACKET LT buildprofilelist GT { ($1,$3,$6) }
 ;
 
 builddepslist:
@@ -167,6 +171,23 @@ buildarchlist_ne:
 
 /**************************************/ 
 
+buildprofile:
+  | BANG IDENT             { (false,$2) }
+  | IDENT                  { (true,$1)  }
+;
+
+buildprofilelist:
+  |             { [] }
+  | buildprofilelist_ne { $1 }
+;
+
+buildprofilelist_ne:
+  | buildprofile                      { [ $1 ] }
+  | buildprofile buildprofilelist_ne  { $1 :: $2 }
+;
+
+/**************************************/ 
+
 archlist:
   |             { [] }
   | archlist_ne { $1 }
diff --git a/deb/sources.ml b/deb/sources.ml
index 0588013..c565e4a 100644
--- a/deb/sources.ml
+++ b/deb/sources.ml
@@ -87,41 +87,79 @@ let input_raw =
 let sep = ":" ;;
 
 (** transform a list of sources into dummy packages to be then converted to cudf *)
-let sources2packages ?(src="src") archs l =
+let sources2packages ?(profiles=false) ?(src="src") archs l =
   let archs = "all"::"any"::archs in
   (* as per policy, if the first arch restriction contains a !
    * then we assume that all archs on the lists are bang-ed.
-   * cf: http://www.debian.org/doc/debian-policy/ch-relationships.html 7.1 *)
-  let select = function
-    |(v,(((false,_)::_) as al)) when 
+   * cf: http://www.debian.org/doc/debian-policy/ch-relationships.html 7.1
+   * use the same rule for buildprofile lists *)
+  let select profile dep = match dep,profile with
+    |(v,(((true,_)::_) as al),(((false,_)::_))),None when
+      List.exists (fun (_,a) -> List.mem a archs) al -> Some v
+    |(v,(((false,_)::_) as al),(((false,_)::_))),None when
+      List.for_all (fun (_,a) -> not(List.mem a archs)) al -> Some v
+    |(v,(((true,_)::_) as al),(((true,_)::_) as pl)),(Some p) when
+      (List.exists (fun (_,a) -> List.mem a archs) al) &&
+      (List.exists (fun (_,a) -> a = p) pl) -> Some v
+    |(v,(((true,_)::_) as al),(((false,_)::_) as pl)),(Some p) when
+      (List.exists (fun (_,a) -> List.mem a archs) al) &&
+      (List.for_all (fun (_,a) -> a != p) pl) -> Some v
+    |(v,(((false,_)::_) as al),(((true,_)::_) as pl)),(Some p) when
+      (List.for_all (fun (_,a) -> not(List.mem a archs)) al) &&
+      (List.exists (fun (_,a) -> a = p) pl) -> Some v
+    |(v,(((false,_)::_) as al),(((false,_)::_) as pl)),(Some p) when
+      (List.for_all (fun (_,a) -> not(List.mem a archs)) al) &&
+      (List.for_all (fun (_,a) -> a != p) pl) -> Some v
+    |(v,(((false,_)::_) as al),[]),_ when
       List.for_all (fun (_,a) -> not(List.mem a archs)) al -> Some v
-    |(v,(((true,_)::_) as al)) when 
+    |(v,(((true,_)::_) as al),[]),_ when
       List.exists (fun (_,a) -> List.mem a archs) al -> Some v
-    |(v,[]) -> Some v
+    |(v,[],(((false,_)::_) as pl)),(Some p) when
+      List.for_all (fun (_,a) -> a != p) pl -> Some v
+    |(v,[],(((true,_)::_) as pl)),(Some p) when
+      List.exists (fun (_,a) -> a = p) pl -> Some v
+    |(v,[],(((false,_)::_))),None -> Some v
+    |(v,[],[]),_ -> Some v
     |_ -> None
   in
-  let conflicts l = List.filter_map select l in
-  let depends ll = 
+  let conflicts profile l = List.filter_map (select profile) l in
+  let depends profile ll =
     List.filter_map (fun l ->
-      match List.filter_map select l with 
+      match List.filter_map (select profile) l with
       |[] -> None 
       | l -> Some l
     ) ll
   in
   let bins pkg = String.concat "," pkg.binary in
-  List.filter_map (fun pkg ->
-    let pkgarchs = pkg.architecture in
-    if List.exists (fun a -> List.mem a archs) pkgarchs then
-      Some (
-      { Packages.default_package with
-        Packages.name = src ^ sep ^ pkg.name ;
-        source = (pkg.name, Some pkg.version);
-        version = pkg.version;
-        depends = depends (pkg.build_depends_indep @ pkg.build_depends);
-        conflicts = conflicts (pkg.build_conflicts_indep @ pkg.build_conflicts);
-        architecture = String.concat "," pkg.architecture;
-        extras = [("type",src);("binaries",bins pkg)]
-      }
-      )
-    else None
-  ) l
+
+  let src2pkg ?(profile=None) srcpkg =
+    let prefix = match profile with None -> src | Some s -> src^"-"^s in
+    let extras_profile = match profile with None -> [] | Some s -> [("profile", s)] in
+    { Packages.default_package with
+      Packages.name = prefix ^ sep ^ srcpkg.name ;
+      source = (srcpkg.name, Some srcpkg.version);
+      version = srcpkg.version;
+      depends = depends profile (srcpkg.build_depends_indep @ srcpkg.build_depends);
+      conflicts = conflicts profile (srcpkg.build_conflicts_indep @ srcpkg.build_conflicts);
+      architecture = String.concat "," srcpkg.architecture;
+      extras = extras_profile @ [("type",src);("binaries",bins srcpkg)]
+    }
+  in
+
+  (* search in Build-Depends and Build-Conflicts for buildprofiles
+     searching in Build-Depends-Indep and Build-Conflicts-Indep doesnt make sense *)
+  let getprofiles pkg =
+    let deps = pkg.build_conflicts @ (List.concat pkg.build_depends) in
+    List.unique (List.map (fun (_,p) -> p) (List.fold_left (fun l (_,_,pl) -> pl @ l) [] deps))
+  in
+
+  List.fold_left (fun al srcpkg ->
+    let pkgarchs = srcpkg.architecture in
+    if List.exists (fun a -> List.mem a archs) pkgarchs then begin
+      let pkg = src2pkg srcpkg in
+      if profiles then begin
+        pkg :: (List.map (fun p -> src2pkg ~profile:(Some p) srcpkg) (getprofiles srcpkg)) @ al
+      end else
+        pkg::al
+    end else al
+  ) [] l
-- 
1.7.10



More information about the Debian-bootstrap mailing list