summaryrefslogtreecommitdiff
path: root/scripts/cargo.pl
blob: 93e365620b243222b45ad37b61ad95c261e7362b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl

use strict;
use warnings;
use feature qw(:5.34);

open my $cargo, '<', $ARGV[0] or die "can't open $ARGV[0]: $!\n";
my $data = '';
# This block reads in the entire file.
{
	local $/;
	$data = <$cargo>;
}

my @lines = split /(\r?\n){2,}/, $data;
my @cargo;

# Parse the file; we just want the name and version.
foreach my $line (@lines) {
	$line =~ /^name = "(.*?)"$/m;
	my $name = $1;
	next unless defined($name);

	$line =~ /^version = "(.*?)"$/m;
	my $version = $1;
	next unless defined($version);

	next unless $line =~ /^source /m;
	$line =~ /^source = "(.*?)"$/m;
	my $source = $1;
	next unless defined($source);

	if ($source ne 'registry+https://github.com/rust-lang/crates.io-index') {
		warn "Warning: $name lacks a supported registry.\n";
	}
	push @cargo, "$name $version";
}

open my $file, '>', 'crates.txt' or die "can't open output file: $!\n";
# Print the data we pulled out above to a file.
foreach my $pkg (sort @cargo) {
	say $file $pkg;
}