chiark / gitweb /
debian/update-build-deps: Use a real TOML parser
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 15 Jun 2023 18:05:38 +0000 (19:05 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 15 Jun 2023 19:24:49 +0000 (20:24 +0100)
That old code was quite horrible.

No change to the output.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.gitlab-ci.yml
debian/update-build-deps

index 8e78cd72ce6679ce62911d041dff40671effb0de..3bca531a30dc1e521b1f2203fd885b1c00df903e 100644 (file)
@@ -47,6 +47,8 @@ maint-checks:
   stage: check
   image: "rust:latest"
   script:
+    - apt-get -y update
+    - apt-get -y install libtoml-perl
     - debian/update-build-deps --check
     - set +e; env git grep -i 'XX[X]'; test $? = 1
 
index b20ba8addef4fd2b295d9b04b4168a63fce3eb3e..3bc866fe869c07436efe0b13a2112cfa963ed24e 100755 (executable)
@@ -1,6 +1,9 @@
 #!/usr/bin/perl -w
 use strict;
 
+use IO::Handle;
+use TOML qw(from_toml);
+
 our $mode =
   "@ARGV" eq '--check' ? 'check' :
   "@ARGV" eq '' ? 'install' :
@@ -22,23 +25,35 @@ while (<I>) {
     next if m{^ +librust[-+a-z0-9.]+ (?:\(.*\) )?\<!upstream-cargo\>,?\s*$};
     if (m{^\S} && !m{^\#}i) {
       local ($_);
-      open C, "Cargo.toml" or die $!;
-      while (<C>) {
-       next unless m{^\[dependencies\]} ... m{^\[};
-       next unless m{^\s*([-_0-9a-z+]+)\s*=};
-       my $p = $1;
-       next if m{path ?= ?\"};
-       $p =~ y/_/-/;
-       my $dep = $replace{$p};
-       if (!defined $dep) {
-         my $f = $need_features{$p} // '';
-         $dep = "librust-$p$f-dev";
-       }
-       if (length $dep) {
-         print O "    $dep <!upstream-cargo>,\n" or die $!;
+      my %outputs;
+      foreach my $file (qw(Cargo.toml)) {
+       open C, $file or die "$file $!";
+       my $toml = do { local $/ = undef; <C> // die "$file $!"; };
+       C->error and die "$file $!";
+       $toml = from_toml($toml) || die "$file ?";
+       foreach my $kw (qw(dependencies)) {
+         foreach my $p (keys %{ $toml->{$kw} }) {
+           my $info = $toml->{$kw}{$p};
+           if (!ref $info) {
+             $info = { 'version' => $info };
+           }
+           next if length $info->{path};
+
+           $p =~ y/_/-/;
+           my $dep = $replace{$p};
+           if (!defined $dep) {
+             my $f = $need_features{$p} // '';
+             $dep = "librust-$p$f-dev";
+           }
+           if (length $dep) {
+             $outputs{"$dep <!upstream-cargo>"}++;
+           }
+         }
        }
       }
-      C->error and die $!;
+      foreach my $output (sort keys %outputs) {
+       print O "    $output,\n" or die $!;
+      }
     }
   }
   print O or die $!;