Resolve virtual packages in dependencies
authorHilko Bengen <bengen@debian.org>
Mon, 11 Mar 2024 23:05:54 +0000 (00:05 +0100)
committerHilko Bengen <bengen@debian.org>
Mon, 11 Mar 2024 23:34:48 +0000 (00:34 +0100)
Gbp-Pq: Name 0002-Resolve-virtual-packages-in-dependencies.patch

src/ph_dpkg.ml

index 6d4fce1be1f8d9c9096032c9d20953a060fcaad2..d284a923536e51b87f6da67d3e29560864a9c2a7 100644 (file)
@@ -57,15 +57,31 @@ let dpkg_packages = Hashtbl.create 13
 let dpkg_package_of_string str =
   if Hashtbl.length dpkg_packages == 0 then (
     let cmd =
-      sprintf "%s --show --showformat='${Package} ${Version} ${Architecture} ${Status}\\n'"
+      sprintf "%s --show --showformat='${Package} ${Version} ${Architecture} ${Status}; ${Provides}\\n'"
         Config.dpkg_query in
     let lines = run_command_get_lines cmd in
     List.iter (
       fun line ->
-        match string_split " " line with
-        | [ name; version; arch; _; _; "installed" ] ->
-          let dpkg = { name = name; version = version; arch = arch } in
-          Hashtbl.add dpkg_packages name dpkg
+        match string_split "; " line with
+        | [ install; provides ] -> (
+          match string_split " " install with
+          | [ name; version; arch; _; _; "installed" ] ->
+             let dpkg = { name = name; version = version; arch = arch } in
+             Hashtbl.add dpkg_packages name dpkg;
+             let virt = string_split ", " provides in
+             (* Also record virtual packages so that dependencies are
+                resolved to the actual pacakge. Individual entries
+                produced by dpkg-query's ${Provides} field are
+                formatted as "name (= version)"; we only care about
+                the name. *)
+             List.iter (
+               fun item ->
+                 match string_split " " item with
+                 | name :: _  -> Hashtbl.add dpkg_packages name dpkg;
+                 | _ -> ();
+               ) virt
+          | _ -> ();
+        )
         | _ -> ();
     ) lines
   );