Debian Codegraph @

debian/list-packages

raw
1 #!/usr/bin/perl -w
2 # -*- mode: cperl; coding: utf-8 -*-
3 # Most of this code was stolen from Debhelper 7.3.16+. which is:
4 # Joey Hess, GPL copyright 1997-2009.
5 # Adapted for CDBS purposes by Colin Walters <[email protected]>
6 # Copyright © 2010-2011, 2015-2016 Jonas Smedegaard <[email protected]>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 sub error {
22 my $err = shift;
23 print STDERR $err;
24 exit 1;
25 }
26
27 sub samearch {
28 my $arch=shift;
29 my @archlist=split(/\s+/,shift);
30
31 foreach my $a (@archlist) {
32 system("dpkg-architecture", "-a$arch", "-i$a") == 0 && return 1;
33 }
34
35 return 0;
36 }
37
38 sub buildarch {
39 my $value=`dpkg-architecture -qDEB_HOST_ARCH` || error("dpkg-architecture failed: $!");
40 chomp $value;
41 return $value;
42 }
43
44 sub GetPackages {
45 my $type=shift;
46
47 $type="" if ! defined $type;
48
49 my $package="";
50 my $arch="";
51 my @list=();
52 my %seen;
53 my @profiles=();
54 my $included_in_build_profile;
55 if (exists $ENV{'DEB_BUILD_PROFILES'}) {
56 @profiles=split /\s+/, $ENV{'DEB_BUILD_PROFILES'};
57 }
58 open (CONTROL, 'debian/control') ||
59 error("cannot read debian/control: $!\n");
60 while (<CONTROL>) {
61 chomp;
62 s/\s+$//;
63 if (/^Package:\s*(.*)/i) {
64 $package=$1;
65 # Detect duplicate package names in the same control file.
66 if (! $seen{$package}) {
67 $seen{$package}=1;
68 }
69 else {
70 error("debian/control has a duplicate entry for $package");
71 }
72 $included_in_build_profile=1;
73 }
74 if (/^Architecture:\s*(.*)/i) {
75 $arch=$1;
76 }
77
78 # rely on libdpkg-perl providing the parsing functions because
79 # if we work on a package with a Build-Profiles field, then a
80 # high enough version of dpkg-dev is needed anyways
81 if (/^Build-Profiles:\s*(.*)/) {
82 my $build_profiles=$1;
83 eval {
84 require Dpkg::BuildProfiles;
85 my @restrictions=Dpkg::BuildProfiles::parse_build_profiles($build_profiles);
86 if (@restrictions) {
87 $included_in_build_profile=Dpkg::BuildProfiles::evaluate_restriction_formula(\@restrictions, \@profiles);
88 }
89 };
90 if ($@) {
91 error("The control file has a Build-Profiles field. Requires libdpkg-perl >= 1.17.14");
92 }
93 }
94
95 if (!$_ or eof) { # end of stanza.
96 if ($package && $included_in_build_profile &&
97 # (($type eq 'indep' && $arch eq 'all') ||
98 # ($type eq 'arch' && $arch ne 'all') ||
99 # ($type eq 'same' && (samearch(buildarch(), $arch))) ||
100 (($type eq 'indep' && $arch eq 'all') ||
101 ($type eq 'arch' && $arch ne 'all') ||
102 ($type eq 'same' && ($arch eq 'any' ||
103 ($arch ne 'all' &&
104 samearch(buildarch(), $arch)))) ||
105 ! $type)) {
106 push @list, $package;
107 $package="";
108 $arch="";
109 }
110 }
111 }
112 close CONTROL;
113
114 return @list;
115 }
116
117 print join(' ', GetPackages($ARGV[0])) . "\n";