File: dpkg-checkbuilddeps

package info (click to toggle)
dh-buildinfo 0.11+nmu2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 124 kB
  • sloc: perl: 685; makefile: 49; sh: 24
file content (148 lines) | stat: -rwxr-xr-x 4,005 bytes parent folder | download | duplicates (6)
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
140
141
142
143
144
145
146
147
148
#! /usr/bin/perl -w
# GPL copyright 2001 by Joey Hess <joeyh@debian.org>
# Parts copyright 2001 by Yann Dirson <dirson@debian.org>

my $me;
BEGIN {
  my $mydir;
  ($mydir,$me) = $0=~m:(.*)/(.+):;
  push @INC, $mydir;
}
use strict;
use Getopt::Long;
use BuildDeps;

sub usage {
	print STDERR <<EOF;
Usage: dpkg-checkbuild [-B] [-m] [-d builddeps] [-c conflictdeps] [control-file]
	-B		binary-only, ignore -Indep
	-m		output met dependencies on stdout, instead of
			unmet dependencies on stderr
	-V		also print versions of met dependencies
	-d BuildDepStr	use given string for build-depends instead of
			getting it from control file
	-c BldConflStr	use given string for build-conflicts instead of
			getting it from control file
	control-file	control file to process [Default: debian/control]
EOF
}

my $binary_only=0;
my $want_help=0;
my $dump_met=0;
my $dependsexpr;
my $conflictsexpr;
my $printversions;
if (! GetOptions('-B' => \$binary_only,
		 '-m' => \$dump_met,
		 '-V' => \$printversions,
		 '-d=s' => \$dependsexpr,
		 '-c=s' => \$conflictsexpr,
		 '-h' => \$want_help)) {
	usage();
	exit(2);
}
if ($want_help) {
	usage();
	exit(0);
}

my (@met, @unmet, @conflicts);
my @status=parse_status();
push @status, $dump_met, $printversions;

if (defined $dependsexpr or defined $conflictsexpr) {
	if ($dump_met) {
		if (defined $dependsexpr) {
			push @met, BuildDeps::depends($dependsexpr, @status);
		}
		foreach my $met (@met) {
		  printf "%-40s ", $met->[0]; # pkg name
		  print $met->[1] if $#{$met} >= 1;	# version
		  print ' (', $met->[2], ')' if $#{$met} > 1;	# virtual pkg provided
		  print "\n";
		}
	} else {
		if (defined $dependsexpr) {
			push @unmet, BuildDeps::depends($dependsexpr, @status);
		}
		if (defined $dependsexpr) {
			push @unmet, BuildDeps::conflicts($conflictsexpr, @status);
		}

		if (@unmet) {
			print STDERR "$me: Unmet build dependencies: ";
			print STDERR join(", ", @unmet), "\n";
		}
		if (@conflicts) {
			print STDERR "$me: Build conflicts: ";
			print STDERR join(", ", @conflicts), "\n";
		}
		exit 1 if @unmet || @conflicts;
	}
} else {
	my $control=shift || "debian/control";
	my %fields = BuildDeps::parse_control ($control);

	if ($dump_met) {
		if (defined $fields{'Build-Depends'}) {
			push @met, BuildDeps::depends($fields{'Build-Depends'}, @status);
		}
		if (! $binary_only && defined $fields{'Build-Depends-Indep'}) {
			push @met, BuildDeps::depends($fields{'Build-Depends-Indep'}, @status);
		}
		print join("\n", @met), "\n";
	} else {
		if (defined $fields{'Build-Depends'}) {
			push @unmet, BuildDeps::depends($fields{'Build-Depends'}, @status);
		}
		if (defined $fields{'Build-Conflicts'}) {
			push @conflicts, BuildDeps::conflicts($fields{'Build-Conflicts'}, @status);
		}
		if (! $binary_only && defined $fields{'Build-Depends-Indep'}) {
			push @unmet, BuildDeps::depends($fields{'Build-Depends-Indep'}, @status);
		}
		if (! $binary_only && defined $fields{'Build-Conflicts-Indep'}) {
			push @conflicts, BuildDeps::conflicts($fields{'Build-Conflicts-Indep'}, @status);
		}

		if (@unmet) {
			print STDERR "$me: Unmet build dependencies: ";
			print STDERR join(", ", @unmet), "\n";
		}
		if (@conflicts) {
			print STDERR "$me: Build conflicts: ";
			print STDERR join(", ", @conflicts), "\n";
		}
		exit 1 if @unmet || @conflicts;
	}
}

# This part could be replaced. Silly little status file parser.
# thanks to Matt Zimmerman. Returns two hash references that
# are exactly what the other functions need...
sub parse_status {
	my $status=shift || "/var/lib/dpkg/status";
	
	my %providers;
	my %version;
	local $/ = '';
	open(STATUS, "<$status") || die "$status: $!\n";
	while (<STATUS>) {
		next unless /^Status: .*ok installed$/m;
	
		my ($package) = /^Package: (.*)$/m;
		push @{$providers{$package}}, $package;
		($version{$package}) = /^Version: (.*)$/m;
	
		if (/^Provides: (.*)$/m) {
			foreach (split(/,\s*/, $1)) {
				push @{$providers{$_}}, $package;
			}
		}
	}
	close STATUS;

	return \%version, \%providers;
}