Author: Johannes 'josch' Schauer <josch@mister-muffin.de>
Description: Add support for --deb-drop-b-d-arch
Debian-bug: #850943

Index: dose3/applications/deb-buildcheck.ml
===================================================================
--- dose3.orig/applications/deb-buildcheck.ml	2017-01-20 13:18:43.639489470 +0100
+++ dose3/applications/deb-buildcheck.ml	2017-01-20 13:18:43.631489385 +0100
@@ -97,6 +97,7 @@
   (* hostarch can be None *)
   let hostarch = match options.Debian.Debcudf.host with None -> "" | Some s -> s in
   let noindep = options.Debian.Debcudf.drop_bd_indep in
+  let noarch = options.Debian.Debcudf.drop_bd_arch in
   let dropalternatives = OptParse.Opt.get Options.dropalternatives in
   let profiles = options.Debian.Debcudf.profiles in
 
@@ -132,7 +133,7 @@
               ~dropalternatives 
               ~profiles 
               ~filter:filter_external_sources 
-              ~noindep buildarch hostarch h 
+              ~noindep ~noarch buildarch hostarch h 
           in
           let pkglist = Deb.input_raw t in
           (pkglist,srclist)
Index: dose3/applications/deb-coinstall.ml
===================================================================
--- dose3.orig/applications/deb-coinstall.ml	2017-01-20 13:18:43.639489470 +0100
+++ dose3/applications/deb-coinstall.ml	2017-01-20 13:18:43.631489385 +0100
@@ -57,7 +57,7 @@
   let default =
     List.fold_left (fun acc e ->
       List.remove acc e
-    ) StdOptions.DistribOptions.default_options ["deb-host-arch";"deb-drop-b-d-indep";"deb-profiles"]
+    ) StdOptions.DistribOptions.default_options ["deb-host-arch";"deb-drop-b-d-indep";"deb-drop-b-d-arch";"deb-profiles"]
   in
   StdOptions.DistribOptions.add_debian_options ~default options ;
   StdOptions.DistribOptions.add_option options ~long_name:"deb-tupletable"
@@ -121,7 +121,7 @@
     in
     let srclist = 
       if not(Option.is_none sources) then
-        Sources.sources2packages ~noindep:true ~profiles:[] native native origsourcelist
+        Sources.sources2packages ~noindep:true ~noarch:false ~profiles:[] native native origsourcelist
       else []
     in
     let tables = Debian.Debcudf.init_tables ~options (srclist@pkglist) in
Index: dose3/applications/distcheck.ml
===================================================================
--- dose3.orig/applications/distcheck.ml	2017-01-20 13:18:43.639489470 +0100
+++ dose3/applications/distcheck.ml	2017-01-20 13:18:43.635489427 +0100
@@ -49,7 +49,7 @@
     List.fold_left
       List.remove
       StdOptions.DistribOptions.default_options
-      ["deb-host-arch";"deb-drop-b-d-indep";"deb-profiles"]
+      ["deb-host-arch";"deb-drop-b-d-indep";"deb-drop-b-d-arch";"deb-profiles"]
   in
   StdOptions.DistribOptions.add_debian_options ~default options ;
   StdOptions.DistribOptions.add_opam_options ~default options ;;
Index: dose3/deb/debcudf.ml
===================================================================
--- dose3.orig/deb/debcudf.ml	2017-01-20 13:18:43.639489470 +0100
+++ dose3/deb/debcudf.ml	2017-01-20 13:18:43.635489427 +0100
@@ -65,6 +65,7 @@
   ignore_essential : bool;
   builds_from : bool;
   drop_bd_indep : bool;
+  drop_bd_arch : bool;
   profiles : string list; (* list of active build profiles *)
 }
 
@@ -76,6 +77,7 @@
   ignore_essential = false;
   builds_from = false;
   drop_bd_indep = false;
+  drop_bd_arch = false;
   profiles = [];
 }
 
Index: dose3/deb/debcudf.mli
===================================================================
--- dose3.orig/deb/debcudf.mli	2017-01-20 13:18:43.639489470 +0100
+++ dose3/deb/debcudf.mli	2017-01-20 13:18:43.635489427 +0100
@@ -24,6 +24,7 @@
   ignore_essential : bool ;
   builds_from : bool ;    (** whether to add the builds-from relationship from binary to source packages *)
   drop_bd_indep : bool ;  (** whether or not to ignore the Build-Depends-Indep field *)
+  drop_bd_arch : bool ;   (** whether or not to ignore the Build-Depends-Arch field *)
   profiles : string list ; (** list of active build profiles *)
 }
 
Index: dose3/deb/sources.ml
===================================================================
--- dose3.orig/deb/sources.ml	2017-01-20 13:18:43.639489470 +0100
+++ dose3/deb/sources.ml	2017-01-20 13:18:43.635489427 +0100
@@ -169,7 +169,7 @@
 (* XXX src2pkg could be skip using the same trick we use in opam, 
  * where dependencies are giltered at parsing time *)
 (* the package name is encodes as src:<package-name> *)
-let src2pkg ?(dropalternatives=false) ?(profiles=[]) ?(noindep=false) ?(src="src") buildarch hostarch srcpkg =
+let src2pkg ?(dropalternatives=false) ?(profiles=[]) ?(noindep=false) ?(noarch=false) ?(src="src") buildarch hostarch srcpkg =
   let conflicts l = List.filter_map (select hostarch profiles) l in
   (* imitate sbuild behaviour and drop all alternatives except those that have
    * the same name as the first. Search for RESOLVE_ALTERNATIVES in
@@ -189,6 +189,8 @@
   let extras_profiles  = match profiles with [] -> [] | _ -> [("profiles", String.join " " profiles)] in
   let depends_indep   = if noindep then [] else srcpkg#build_depends_indep in
   let conflicts_indep = if noindep then [] else srcpkg#build_conflicts_indep in
+  let depends_arch   = if noarch then [] else srcpkg#build_depends_arch in
+  let conflicts_arch = if noarch then [] else srcpkg#build_conflicts_arch in
   (* when crossbuilding (host != build), implicitly depend on build-essential
    * and crossbuild-essential-$hostarch. When compiling natively, implicitly
    * depend on build-essential *)
@@ -200,8 +202,8 @@
   new Packages.package ~name:("",Some(src ^ sep ^ srcpkg#name)) ~version:("",Some(srcpkg#version))
   ~architecture:("",Some(String.concat "," srcpkg#architecture))
   ~source:("",Some (srcpkg#name, Some srcpkg#version)) 
-  ~depends:("",Some (build_essential @ (depends (depends_indep @ srcpkg#build_depends @ srcpkg#build_depends_arch))))
-  ~conflicts:("",Some (conflicts (conflicts_indep @ srcpkg#build_conflicts @ srcpkg#build_conflicts_arch)))
+  ~depends:("",Some (build_essential @ (depends (depends_indep @ srcpkg#build_depends @ depends_arch))))
+  ~conflicts:("",Some (conflicts (conflicts_indep @ srcpkg#build_conflicts @ conflicts_arch)))
   ~extras:([],Some(extras_profiles @ [("Type",src)])) []
 ;;
 
@@ -209,8 +211,8 @@
  * decide whether to select or drop that dependency *)
 (** transform a list of sources packages into dummy binary packages.
   * This function preserve the order *)
-let sources2packages ?(dropalternatives=false) ?(profiles=[]) ?(noindep=false) ?(src="src") buildarch hostarch =
-  List.map (src2pkg ~dropalternatives ~profiles ~noindep ~src buildarch hostarch)
+let sources2packages ?(dropalternatives=false) ?(profiles=[]) ?(noindep=false) ?(noarch=false) ?(src="src") buildarch hostarch =
+  List.map (src2pkg ~dropalternatives ~profiles ~noindep ~noarch ~src buildarch hostarch)
 ;;
 
 (** Check if a package is of "Type" source as encoded by the function sources2packages *)
Index: dose3/doc/manpages/ceve.pod
===================================================================
--- dose3.orig/doc/manpages/ceve.pod	2017-01-20 13:18:43.639489470 +0100
+++ dose3/doc/manpages/ceve.pod	2017-01-20 13:18:43.635489427 +0100
@@ -304,6 +304,10 @@
 
 Drop Build-Depends-Indep dependencies from Debian source packages.
 
+=item B<--deb-drop-b-d-arch>
+
+Drop Build-Depends-Arch dependencies from Debian source packages.
+
 =back
 
 =head1 EXAMPLES
Index: dose3/doc/manpages/deb-buildcheck.pod
===================================================================
--- dose3.orig/doc/manpages/deb-buildcheck.pod	2017-01-20 13:18:43.639489470 +0100
+++ dose3/doc/manpages/deb-buildcheck.pod	2017-01-20 13:18:43.635489427 +0100
@@ -216,6 +216,10 @@
 
 Drop Build-Indep dependencies
 
+=item B<--deb-drop-b-d-arch>
+
+Drop Build-Arch dependencies
+
 =item B<--deb-include-extra-source>
 
 Include packages with Extra-Source-Only:yes (dropped by default)
Index: dose3/doseparse/stdLoaders.ml
===================================================================
--- dose3.orig/doseparse/stdLoaders.ml	2017-01-20 13:18:43.639489470 +0100
+++ dose3/doseparse/stdLoaders.ml	2017-01-20 13:18:43.635489427 +0100
@@ -49,6 +49,7 @@
 let deb_load_list options ?(status=[]) ?(raw=false) dll =
   Util.Timer.start deb_load_list_timer;
   let noindep = options.Debian.Debcudf.drop_bd_indep in
+  let noarch = options.Debian.Debcudf.drop_bd_arch in
   let profiles = options.Debian.Debcudf.profiles in
   let pkgll = List.map (List.map (function
       | Deb p -> p
@@ -57,7 +58,7 @@
             fatal "--deb-native-arch was not specified while treating Debian Sources File";
         let buildarch = Option.get options.Debian.Debcudf.native in
         let hostarch = Option.get options.Debian.Debcudf.host in
-        Debian.Sources.src2pkg ~noindep ~profiles buildarch hostarch p
+        Debian.Sources.src2pkg ~noindep ~noarch ~profiles buildarch hostarch p
       | _ -> fatal "cannot handle input"
     )) dll 
   in
@@ -444,10 +445,10 @@
 ;;
 
 (** return a list of Debian packages from a debian source file *)
-let deb_load_source ?filter ?(dropalternatives=false) ?(profiles=[]) ?(noindep=false) buildarch hostarch sourcefile =
+let deb_load_source ?filter ?(dropalternatives=false) ?(profiles=[]) ?(noindep=false) ?(noarch=false) buildarch hostarch sourcefile =
   Util.Timer.start deb_load_source_timer;
   let l = Debian.Sources.input_raw ?filter ~archs:[hostarch] [sourcefile] in
-  let r = Debian.Sources.sources2packages ~dropalternatives ~noindep ~profiles buildarch hostarch l in
+  let r = Debian.Sources.sources2packages ~dropalternatives ~noindep ~noarch ~profiles buildarch hostarch l in
   Util.Timer.stop deb_load_source_timer r
 ;;
 
Index: dose3/doseparse/stdOptions.ml
===================================================================
--- dose3.orig/doseparse/stdOptions.ml	2017-01-20 13:18:43.639489470 +0100
+++ dose3/doseparse/stdOptions.ml	2017-01-20 13:18:43.635489427 +0100
@@ -319,6 +319,7 @@
   let deb_ignore_essential = StdOpt.store_true ()
   let deb_builds_from = StdOpt.store_true ()
   let deb_drop_bd_indep = StdOpt.store_true ()
+  let deb_drop_bd_arch = StdOpt.store_true ()
   let deb_profiles = str_list_option ()
 
   let opam_switch = StdOpt.str_option ~default:"system" ()
@@ -332,6 +333,7 @@
     "deb-ignore-essential";
     "deb-builds-from";
     "deb-drop-b-d-indep";
+    "deb-drop-b-d-arch";
     "deb-profiles";
     "opam-switch";
     "opam-switches";
@@ -379,6 +381,7 @@
       ignore_essential = Opt.get deb_ignore_essential;
       builds_from = Opt.get deb_builds_from;
       drop_bd_indep = Opt.get deb_drop_bd_indep;
+      drop_bd_arch = Opt.get deb_drop_bd_arch;
       profiles = profiles;
     }
   ;;
@@ -469,6 +472,9 @@
       if List.mem "deb-drop-b-d-indep" default then
         add options ~group ~long_name:"deb-drop-b-d-indep"
           ~help:"Drop the Build-Depends-Indep field from source packages (build no Architecture:all packages)" deb_drop_bd_indep;
+      if List.mem "deb-drop-b-d-arch" default then
+        add options ~group ~long_name:"deb-drop-b-d-arch"
+          ~help:"Drop the Build-Depends-Arch field from source packages (build no Architecture:any packages)" deb_drop_bd_arch;
       if List.mem "deb-profiles" default then
         add options ~group ~long_name:"deb-profiles"
           ~help:"comma separated list of activated build profiles" deb_profiles;
