summaryrefslogtreecommitdiffstats
path: root/bin/rdeps
blob: 13016a5f1556c4bd8931d61c494a0e7f8a396390 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/perl

=head1 NAME

rdeps - List ProteanOS package reverse dependencies

=cut

use strict;
use warnings;
no indirect;
use autovivification;
use English qw(-no_match_vars);

use Getopt::Long;
use LWP::Simple;
use POSIX qw(strftime);

my $SOURCE_URL = 'http://git.proteanos.com/depsdot/depsdot.git/';
my $BASE_URL = 'http://files.proteanos.com/pub/proteanos/feeds/dev/trunk';
my @DEP_FIELDS = qw(Build-Depends Depends Recommends Suggests Pre-Depends);

my @rdeps;

sub read_list
{
	my ($list, $dep, $bin, $is_src) = @_;

	foreach my $para (split(m{\n\n}, get($list))) {
		my $package = undef;
		my $source = undef;
		my @deps;
		foreach my $line (split(m{\n}, $para)) {
			my ($name, $value) = split(m{\s*:\s*}, $line);
			if ($name eq 'Package') {
				$package = $value;
			}
			if ($name eq 'Source') {
				$source = $value;
			}
			if (grep(m{^\Q$name\E$}, @DEP_FIELDS)) {
				push(@deps, split(m{\s*,\s*}, $value));
			}
		}
		next if not defined($source);
		map({ $_ =~ s{[\s(].*$}{}; } @deps);  # Vim: )
		if ($bin) {
			$package .= ' (src:' . $source . ')';
		} else {
			$package = $source;
		}
		if (grep(m{^\Q$dep\E$}, @deps) and not
				grep(m{^\Q$package\E$}, @rdeps)) {
			push(@rdeps, $package);
		}
	}

	return;
}

sub usage
{
	my ($fh) = @_;

	$fh->printf("Usage: %s <pkg>\n", $PROGRAM_NAME);

	return;
}

sub main
{
	my %opts;
	my $dep;
	my @manifest;

	Getopt::Long::Configure('no_ignore_case', 'bundling', 'gnu_compat',
		'no_getopt_compat');
	if (not GetOptions(\%opts,
			'b|binary',
			'h|help',
		)) {
		usage(*STDERR);
		return 1;
	}
	if (exists($opts{'h'})) {
		usage(*STDERR);
		return 0;
	}
	if ($#ARGV lt 0) {
		usage(*STDERR);
		return 1;
	}
	$dep = $ARGV[0];

	@manifest = split(m{\n}, get($BASE_URL . '/Manifest'));
	foreach my $aps (@manifest) {
		read_list($BASE_URL . '/' . $aps . '/Packages', $dep,
			exists($opts{'b'}), ($aps =~ m{^src/}));
	}
	STDOUT->print(join("\n", sort(@rdeps)));

	return 0;
}

exit(main());

__END__

=head1 SYNOPSIS

B<rdeps>

=head1 DESCRIPTION

B<rdeps> lists the source packages providing build- and run-time dependencies of
a ProteanOS binary package.

=head1 OUTPUT

B<rdeps> writes a list of source packages to standard output.

=head1 COPYRIGHT

Copyright (C) 2019-2020 Patrick McDermott

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

=cut