#!/usr/bin/perl -w use strict; use IO::Handle; use TOML qw(from_toml); our $mode = "@ARGV" eq '--check' ? 'check' : "@ARGV" eq '' ? 'install' : die "$0: bad usage\n"; open I, "debian/control" or die $!; open O, ">debian/control.new" or die $!; our %need_features = qw( clap +derive env-logger +default ); our %replace = ( ); sub convert_version ($) { local ($_) = @_; s{^\>= ?([^,]+)\, \<[^,]+$}{$1}; if (m{^\d+(?:\.\d+){0,2}$}) { return "(>= $_~)"; } else { warn "don't know how to convert Cargo version spec \`$_`"; } } while () { if (m{^\# debian/update-build-deps}i...m{^\S}) { next if m{^ +librust[-+a-z0-9.]+ (?:\(.*\) )?\,?\s*$}; if (m{^\S} && !m{^\#}i) { local ($_); my %outputs; foreach my $file (qw(Cargo.toml macros/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 build-dependencies)) { foreach my $p (keys %{ $toml->{$kw} }) { my $info = $toml->{$kw}{$p}; if (!ref $info) { $info = { 'version' => $info }; } next if length $info->{path}; my $version = $info->{version} // die "$file $p ?"; $version = convert_version($version); $version = " $version" if length $version; $p =~ y/_/-/; my $dep = $replace{$p}; if (!defined $dep) { my $f = $need_features{$p} // ''; $dep = "librust-$p$f-dev"; } if (length $dep) { $outputs{"$dep$version "}++; } } } } foreach my $output (sort keys %outputs) { print O " $output,\n" or die $!; } } } print O or die $!; } I->error and die $!; close O or die $!; if ($mode eq 'install') { rename "debian/control.new", "debian/control" or die $!; } else { exec qw(diff -u), "debian/control", "debian/control.new"; }