#!/usr/bin/perl -w
use strict;
+use IO::Handle;
+use TOML qw(from_toml);
+
our $mode =
"@ARGV" eq '--check' ? 'check' :
"@ARGV" eq '' ? 'install' :
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 $!;