| 1 | # Copyright © 2008-2009 Raphaël Hertzog <hertzog@debian.org> | ||||||||||||||||||||||||||||
| 2 | # Copyright © 2008-2009, 2012-2017, 2022 Guillem Jover <guillem@debian.org> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 5 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 6 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||
| 7 | # (at your option) any later version. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 12 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =encoding utf8 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | Dpkg::Vendor - get access to some vendor specific information | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | The files in $Dpkg::CONFDIR/origins/ can provide information about various | ||||||||||||||||||||||||||||
| 26 | vendors who are providing Debian packages. Currently those files look like | ||||||||||||||||||||||||||||
| 27 | this: | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Vendor: Debian | ||||||||||||||||||||||||||||
| 30 | Vendor-URL: https://www.debian.org/ | ||||||||||||||||||||||||||||
| 31 | Bugs: debbugs://bugs.debian.org | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | If the vendor derives from another vendor, the file should document | ||||||||||||||||||||||||||||
| 34 | the relationship by listing the base distribution in the Parent field: | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Parent: Debian | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | The file should be named according to the vendor name. The usual convention | ||||||||||||||||||||||||||||
| 39 | is to name the vendor file using the vendor name in all lowercase, but some | ||||||||||||||||||||||||||||
| 40 | variation is permitted. Namely, spaces are mapped to dashes ('-'), and the | ||||||||||||||||||||||||||||
| 41 | file can have the same casing as the Vendor field, or it can be capitalized. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | package Dpkg::Vendor 1.03; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 15 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 15 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 50 | get_current_vendor | ||||||||||||||||||||||||||||
| 51 | get_vendor_info | ||||||||||||||||||||||||||||
| 52 | get_vendor_file | ||||||||||||||||||||||||||||
| 53 | get_vendor_dir | ||||||||||||||||||||||||||||
| 54 | get_vendor_object | ||||||||||||||||||||||||||||
| 55 | run_vendor_hook | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 15 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 15 | ▶ | use List::Util qw(uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 15 | ▶ | use Dpkg (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 15 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 15 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 15 | ▶ | use Dpkg::BuildEnv; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 15 | ▶ | use Dpkg::Control::HashCore; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 15 | my $origins = "$Dpkg::CONFDIR/origins"; | |||||||||||||||||||||||||||
| 68 | 15 | ▶ | $origins = $ENV{DPKG_ORIGINS_DIR} if $ENV{DPKG_ORIGINS_DIR}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =over 4 | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =item $dir = get_vendor_dir() | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Returns the current dpkg origins directory name, where the vendor files | ||||||||||||||||||||||||||||
| 77 | are stored. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub get_vendor_dir { | ||||||||||||||||||||||||||
|
Subroutine
get_vendor_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 1 | return $origins; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =item $ctrl = get_vendor_info([$name]) | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Returns a L<Dpkg::Control> object with the information parsed from the | ||||||||||||||||||||||||||||
| 88 | corresponding vendor file in $Dpkg::CONFDIR/origins/. If $name is omitted, | ||||||||||||||||||||||||||||
| 89 | it will use $Dpkg::CONFDIR/origins/default which is supposed to be a symlink | ||||||||||||||||||||||||||||
| 90 | to the vendor of the currently installed operating system. Returns undef | ||||||||||||||||||||||||||||
| 91 | if there's no file for the given vendor. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 15 | my $vendor_ok_regex = qw{[A-Za-z0-9]+}; | |||||||||||||||||||||||||||
| 96 | 15 | my $vendor_sep_regex = qr{[^A-Za-z0-9]+}; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 544 | ▶ | sub get_vendor_info { | ||||||||||||||||||||||||||
|
Subroutine
get_vendor_info: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 544 | ▶ | my $vendor = shift || 'default'; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 'default'
MC/DC100%1/1
shift() || 'default'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 100 | 544 | my $vendor_key = lc $vendor =~ s{$vendor_sep_regex}{}gr; | |||||||||||||||||||||||||||
| 101 | 544 | state %VENDOR_CACHE; | |||||||||||||||||||||||||||
| 102 | 544 | ▶ | return $VENDOR_CACHE{$vendor_key} if exists $VENDOR_CACHE{$vendor_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 16 | my $file = get_vendor_file($vendor); | |||||||||||||||||||||||||||
| 105 | 16 | ▶ | return unless $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 16 | my $fields = Dpkg::Control::HashCore->new(); | |||||||||||||||||||||||||||
| 107 | 16 | ▶ | $fields->load($file, compression => 0) or error(g_('%s is empty'), $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 16 | $VENDOR_CACHE{$vendor_key} = $fields; | |||||||||||||||||||||||||||
| 109 | 16 | return $fields; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =item $name = get_vendor_file([$name]) | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | Check if there's a file for the given vendor and returns its | ||||||||||||||||||||||||||||
| 115 | name. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | The vendor filename will be derived from the vendor name, by replacing any | ||||||||||||||||||||||||||||
| 118 | number of non-alphanumeric characters (that is B<[^A-Za-z0-9]>) into "B<->", | ||||||||||||||||||||||||||||
| 119 | then the resulting name will be tried in sequence by lower-casing it, | ||||||||||||||||||||||||||||
| 120 | keeping it as is, lower-casing then capitalizing it, and capitalizing it. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 16 | ▶ | sub get_vendor_file { | ||||||||||||||||||||||||||
|
Subroutine
get_vendor_file: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 16 | ▶ | my $vendor = shift || 'default'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'default'
MC/DC0%0/1
shift() || 'default'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 16 | my @names; | |||||||||||||||||||||||||||
| 128 | 16 | my $vendor_sep = $vendor =~ s{$vendor_sep_regex}{-}gr; | |||||||||||||||||||||||||||
| 129 | 16 | push @names, lc $vendor_sep, $vendor_sep, ucfirst lc $vendor_sep, ucfirst $vendor_sep; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 16 | foreach my $name (uniq @names) { | |||||||||||||||||||||||||||
| 132 | 16 | ▶ | next unless -e "$origins/$name"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 16 | return "$origins/$name"; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | 0 | return; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =item $name = get_current_vendor() | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Returns the name of the current vendor. If DEB_VENDOR is set, it uses | ||||||||||||||||||||||||||||
| 141 | that first, otherwise it falls back to parsing $Dpkg::CONFDIR/origins/default. | ||||||||||||||||||||||||||||
| 142 | If that file doesn't exist, it returns undef. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 543 | ▶ | sub get_current_vendor { | ||||||||||||||||||||||||||
|
Subroutine
get_current_vendor: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 543 | my $f; | |||||||||||||||||||||||||||
| 148 | 543 | ▶ | if (Dpkg::BuildEnv::has('DEB_VENDOR')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 257 | $f = get_vendor_info(Dpkg::BuildEnv::get('DEB_VENDOR')); | |||||||||||||||||||||||||||
| 150 | 257 | ▶ | return $f->{'Vendor'} if defined $f; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 286 | $f = get_vendor_info(); | |||||||||||||||||||||||||||
| 153 | 286 | ▶ | return $f->{'Vendor'} if defined $f; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | return; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =item $object = get_vendor_object($name) | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | Return the Dpkg::Vendor::* object of the corresponding vendor. | ||||||||||||||||||||||||||||
| 160 | If $name is omitted, return the object of the current vendor. | ||||||||||||||||||||||||||||
| 161 | If no vendor can be identified, then return the L<Dpkg::Vendor::Default> | ||||||||||||||||||||||||||||
| 162 | object. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | The module name will be derived from the vendor name, by splitting parts | ||||||||||||||||||||||||||||
| 165 | around groups of non alphanumeric character (that is B<[^A-Za-z0-9]>) | ||||||||||||||||||||||||||||
| 166 | separators, by either capitalizing or lower-casing and capitalizing each part | ||||||||||||||||||||||||||||
| 167 | and then joining them without the separators. So the expected casing is based | ||||||||||||||||||||||||||||
| 168 | on the one from the B<Vendor> field in the F<origins> file. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 542 | ▶ | sub get_vendor_object { | ||||||||||||||||||||||||||
|
Subroutine
get_vendor_object: called CC=8 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 542 | ▶ | my $vendor = shift || get_current_vendor() || 'Default'; | ||||||||||||||||||||||||||
|
Condition60%3/5
shift() || get_current_vendor() || 'Default'
shift() or get_current_vendor()
MC/DC0%0/2
shift() || get_current_vendor() || 'Default'
shift()
get_current_vendor()
Truth table66%2/3
A or B
A= shift()B= get_current_vendor()
| |||||||||||||||||||||||||||||
| 174 | 542 | my $vendor_key = lc $vendor =~ s{$vendor_sep_regex}{}gr; | |||||||||||||||||||||||||||
| 175 | 542 | state %OBJECT_CACHE; | |||||||||||||||||||||||||||
| 176 | 542 | ▶ | return $OBJECT_CACHE{$vendor_key} if exists $OBJECT_CACHE{$vendor_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 17 | my @vendor_parts = $vendor =~ m{$vendor_ok_regex}g; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 17 | my @names; | |||||||||||||||||||||||||||
| 181 | 17 | push @names, join q{}, map { ucfirst } @vendor_parts; | |||||||||||||||||||||||||||
| 182 | 17 | push @names, join q{}, map { ucfirst lc } @vendor_parts; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 17 | foreach my $name (uniq @names) { | |||||||||||||||||||||||||||
| 185 | 18 | my $module = "Dpkg::Vendor::$name"; | |||||||||||||||||||||||||||
| 186 | 18 | eval qq{ | |||||||||||||||||||||||||||
| 187 | require $module; | ||||||||||||||||||||||||||||
| 188 | }; | ||||||||||||||||||||||||||||
| 189 | 18 | ▶ | next if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 16 | my $obj = $module->new(); | |||||||||||||||||||||||||||
| 192 | 16 | $OBJECT_CACHE{$vendor_key} = $obj; | |||||||||||||||||||||||||||
| 193 | 16 | return $obj; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 1 | my $info = get_vendor_info($vendor); | |||||||||||||||||||||||||||
| 197 | 1 | ▶ | if (defined $info and defined $info->{'Parent'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $info and defined $info->{"Parent"}
MC/DC0%0/2
defined $info and defined $info->{"Parent"}
defined $info
defined $info->{"Parent"}
Truth table33%1/3
A and B
A= defined $infoB= defined $info->{"Parent"}
| |||||||||||||||||||||||||||||
| 198 | 1 | return get_vendor_object($info->{'Parent'}); | |||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||
| 200 | 0 | return get_vendor_object('Default'); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =item run_vendor_hook($hookid, @params) | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | Run a hook implemented by the current vendor object. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =cut | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 537 | ▶ | sub run_vendor_hook { | ||||||||||||||||||||||||||
|
Subroutine
run_vendor_hook: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 537 | my @args = @_; | |||||||||||||||||||||||||||
| 212 | 537 | my $vendor_obj = get_vendor_object(); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 537 | $vendor_obj->run_hook(@args); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =back | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =head2 Version 1.03 (dpkg 1.22.12) | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Obsolete behavior: get_vendor_file() and get_vendor_object() no longer | ||||||||||||||||||||||||||||
| 224 | support the deprecated behavior from 1.02. | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head2 Version 1.02 (dpkg 1.21.10) | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | Deprecated behavior: get_vendor_file() loading vendor files with no special | ||||||||||||||||||||||||||||
| 229 | characters remapping. get_vendor_object() loading vendor module names with | ||||||||||||||||||||||||||||
| 230 | no special character stripping. | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =head2 Version 1.01 (dpkg 1.17.0) | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | New function: get_vendor_dir(). | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =head2 Version 1.00 (dpkg 1.16.1) | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | Mark the module as public. | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | L<deb-origin(5)>. | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =cut | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 15 | 1; | |||||||||||||||||||||||||||