Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: third_party/dpkg-dev/scripts/Dpkg/Vendor.pm

Issue 2425693003: Revert of Linux build: Use sysroot when calculating dependencies (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright © 2008-2009 Raphaël Hertzog <hertzog@debian.org>
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16 package Dpkg::Vendor;
17
18 use strict;
19 use warnings;
20
21 our $VERSION = '1.01';
22
23 use Dpkg ();
24 use Dpkg::ErrorHandling;
25 use Dpkg::Gettext;
26 use Dpkg::BuildEnv;
27 use Dpkg::Control::HashCore;
28
29 use Exporter qw(import);
30 our @EXPORT_OK = qw(get_vendor_info get_current_vendor get_vendor_file
31 get_vendor_dir get_vendor_object run_vendor_hook);
32
33 my $origins = "$Dpkg::CONFDIR/origins";
34 $origins = $ENV{DPKG_ORIGINS_DIR} if $ENV{DPKG_ORIGINS_DIR};
35
36 =encoding utf8
37
38 =head1 NAME
39
40 Dpkg::Vendor - get access to some vendor specific information
41
42 =head1 DESCRIPTION
43
44 The files in $Dpkg::CONFDIR/origins/ can provide information about various
45 vendors who are providing Debian packages. Currently those files look like
46 this:
47
48 Vendor: Debian
49 Vendor-URL: http://www.debian.org/
50 Bugs: debbugs://bugs.debian.org
51
52 If the vendor derives from another vendor, the file should document
53 the relationship by listing the base distribution in the Parent field:
54
55 Parent: Debian
56
57 The file should be named according to the vendor name.
58
59 =head1 FUNCTIONS
60
61 =over 4
62
63 =item $dir = Dpkg::Vendor::get_vendor_dir()
64
65 Returns the current dpkg origins directory name, where the vendor files
66 are stored.
67
68 =cut
69
70 sub get_vendor_dir {
71 return $origins;
72 }
73
74 =item $fields = Dpkg::Vendor::get_vendor_info($name)
75
76 Returns a Dpkg::Control object with the information parsed from the
77 corresponding vendor file in $Dpkg::CONFDIR/origins/. If $name is omitted,
78 it will use $Dpkg::CONFDIR/origins/default which is supposed to be a symlink
79 to the vendor of the currently installed operating system. Returns undef
80 if there's no file for the given vendor.
81
82 =cut
83
84 sub get_vendor_info(;$) {
85 my $vendor = shift || 'default';
86 my $file = get_vendor_file($vendor);
87 return unless $file;
88 my $fields = Dpkg::Control::HashCore->new();
89 $fields->load($file) or error(_g('%s is empty'), $file);
90 return $fields;
91 }
92
93 =item $name = Dpkg::Vendor::get_vendor_file($name)
94
95 Check if there's a file for the given vendor and returns its
96 name.
97
98 =cut
99
100 sub get_vendor_file(;$) {
101 my $vendor = shift || 'default';
102 my $file;
103 my @tries = ($vendor, lc($vendor), ucfirst($vendor), ucfirst(lc($vendor)));
104 if ($vendor =~ s/\s+/-/) {
105 push @tries, $vendor, lc($vendor), ucfirst($vendor), ucfirst(lc($vendor) );
106 }
107 foreach my $name (@tries) {
108 $file = "$origins/$name" if -e "$origins/$name";
109 }
110 return $file;
111 }
112
113 =item $name = Dpkg::Vendor::get_current_vendor()
114
115 Returns the name of the current vendor. If DEB_VENDOR is set, it uses
116 that first, otherwise it falls back to parsing $Dpkg::CONFDIR/origins/default.
117 If that file doesn't exist, it returns undef.
118
119 =cut
120
121 sub get_current_vendor() {
122 my $f;
123 if (Dpkg::BuildEnv::has('DEB_VENDOR')) {
124 $f = get_vendor_info(Dpkg::BuildEnv::get('DEB_VENDOR'));
125 return $f->{'Vendor'} if defined $f;
126 }
127 $f = get_vendor_info();
128 return $f->{'Vendor'} if defined $f;
129 return;
130 }
131
132 =item $object = Dpkg::Vendor::get_vendor_object($name)
133
134 Return the Dpkg::Vendor::* object of the corresponding vendor.
135 If $name is omitted, return the object of the current vendor.
136 If no vendor can be identified, then return the Dpkg::Vendor::Default
137 object.
138
139 =cut
140
141 my %OBJECT_CACHE;
142 sub get_vendor_object {
143 my $vendor = shift || get_current_vendor() || 'Default';
144 return $OBJECT_CACHE{$vendor} if exists $OBJECT_CACHE{$vendor};
145
146 my ($obj, @names);
147 if ($vendor ne 'Default') {
148 push @names, $vendor, lc($vendor), ucfirst($vendor), ucfirst(lc($vendor) );
149 }
150 foreach my $name (@names, 'Default') {
151 eval qq{
152 require Dpkg::Vendor::$name;
153 \$obj = Dpkg::Vendor::$name->new();
154 };
155 last unless $@;
156 }
157 $OBJECT_CACHE{$vendor} = $obj;
158 return $obj;
159 }
160
161 =item Dpkg::Vendor::run_vendor_hook($hookid, @params)
162
163 Run a hook implemented by the current vendor object.
164
165 =cut
166
167 sub run_vendor_hook {
168 my $vendor_obj = get_vendor_object();
169 $vendor_obj->run_hook(@_);
170 }
171
172 =back
173
174 =head1 CHANGES
175
176 =head2 Version 1.01
177
178 New function: get_vendor_dir().
179
180 =cut
181
182 1;
OLDNEW
« no previous file with comments | « third_party/dpkg-dev/scripts/Dpkg/Vars.pm ('k') | third_party/dpkg-dev/scripts/Dpkg/Vendor/Debian.pm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698