From: Ian Jackson Date: Thu, 15 Jun 2023 18:05:38 +0000 (+0100) Subject: debian/update-build-deps: Use a real TOML parser X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=0606a230ea0b1765a3fdd8c940f6b437af745449;p=hippotat.git debian/update-build-deps: Use a real TOML parser That old code was quite horrible. No change to the output. Signed-off-by: Ian Jackson --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8e78cd7..3bca531 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/debian/update-build-deps b/debian/update-build-deps index b20ba8a..3bc866f 100755 --- a/debian/update-build-deps +++ b/debian/update-build-deps @@ -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 () { next if m{^ +librust[-+a-z0-9.]+ (?:\(.*\) )?\,?\s*$}; if (m{^\S} && !m{^\#}i) { local ($_); - open C, "Cargo.toml" or die $!; - while () { - 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 ,\n" or die $!; + my %outputs; + foreach my $file (qw(Cargo.toml)) { + open C, $file or die "$file $!"; + my $toml = do { local $/ = undef; // 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 "}++; + } + } } } - C->error and die $!; + foreach my $output (sort keys %outputs) { + print O " $output,\n" or die $!; + } } } print O or die $!;