Deps.pm 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  1. # Copyright © 2007-2009 Raphaël Hertzog <hertzog@debian.org>
  2. # Copyright © 2012 Guillem Jover <guillem@debian.org>
  3. #
  4. # This program is free software; you may 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 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. # Several parts are inspired by lib/Dep.pm from lintian (same license)
  18. #
  19. # Copyright © 1998 Richard Braakman
  20. # Portions Copyright © 1999 Darren Benham
  21. # Portions Copyright © 2000 Sean 'Shaleh' Perry
  22. # Portions Copyright © 2004 Frank Lichtenheld
  23. # Portions Copyright © 2006 Russ Allbery
  24. package Dpkg::Deps;
  25. =encoding utf8
  26. =head1 NAME
  27. Dpkg::Deps - parse and manipulate dependencies of Debian packages
  28. =head1 DESCRIPTION
  29. The Dpkg::Deps module provides objects implementing various types of
  30. dependencies.
  31. The most important function is deps_parse(), it turns a dependency line in
  32. a set of Dpkg::Deps::{Simple,AND,OR,Union} objects depending on the case.
  33. =head1 FUNCTIONS
  34. All the deps_* functions are exported by default.
  35. =over 4
  36. =cut
  37. use strict;
  38. use warnings;
  39. our $VERSION = '1.02';
  40. use Dpkg::Version;
  41. use Dpkg::Arch qw(get_host_arch get_build_arch);
  42. use Dpkg::BuildProfiles qw(get_build_profiles);
  43. use Dpkg::ErrorHandling;
  44. use Dpkg::Gettext;
  45. use Exporter qw(import);
  46. our @EXPORT = qw(deps_concat deps_parse deps_eval_implication deps_compare);
  47. =item deps_eval_implication($rel_p, $v_p, $rel_q, $v_q)
  48. ($rel_p, $v_p) and ($rel_q, $v_q) express two dependencies as (relation,
  49. version). The relation variable can have the following values that are
  50. exported by Dpkg::Version: REL_EQ, REL_LT, REL_LE, REL_GT, REL_GT.
  51. This functions returns 1 if the "p" dependency implies the "q"
  52. dependency. It returns 0 if the "p" dependency implies that "q" is
  53. not satisfied. It returns undef when there's no implication.
  54. The $v_p and $v_q parameter should be Dpkg::Version objects.
  55. =cut
  56. sub deps_eval_implication {
  57. my ($rel_p, $v_p, $rel_q, $v_q) = @_;
  58. # If versions are not valid, we can't decide of any implication
  59. return unless defined($v_p) and $v_p->is_valid();
  60. return unless defined($v_q) and $v_q->is_valid();
  61. # q wants an exact version, so p must provide that exact version. p
  62. # disproves q if q's version is outside the range enforced by p.
  63. if ($rel_q eq REL_EQ) {
  64. if ($rel_p eq REL_LT) {
  65. return ($v_p <= $v_q) ? 0 : undef;
  66. } elsif ($rel_p eq REL_LE) {
  67. return ($v_p < $v_q) ? 0 : undef;
  68. } elsif ($rel_p eq REL_GT) {
  69. return ($v_p >= $v_q) ? 0 : undef;
  70. } elsif ($rel_p eq REL_GE) {
  71. return ($v_p > $v_q) ? 0 : undef;
  72. } elsif ($rel_p eq REL_EQ) {
  73. return ($v_p == $v_q);
  74. }
  75. }
  76. # A greater than clause may disprove a less than clause. An equal
  77. # cause might as well. Otherwise, if
  78. # p's clause is <<, <=, or =, the version must be <= q's to imply q.
  79. if ($rel_q eq REL_LE) {
  80. if ($rel_p eq REL_GT) {
  81. return ($v_p >= $v_q) ? 0 : undef;
  82. } elsif ($rel_p eq REL_GE) {
  83. return ($v_p > $v_q) ? 0 : undef;
  84. } elsif ($rel_p eq REL_EQ) {
  85. return ($v_p <= $v_q) ? 1 : 0;
  86. } else { # <<, <=
  87. return ($v_p <= $v_q) ? 1 : undef;
  88. }
  89. }
  90. # Similar, but << is stronger than <= so p's version must be << q's
  91. # version if the p relation is <= or =.
  92. if ($rel_q eq REL_LT) {
  93. if ($rel_p eq REL_GT or $rel_p eq REL_GE) {
  94. return ($v_p >= $v_p) ? 0 : undef;
  95. } elsif ($rel_p eq REL_LT) {
  96. return ($v_p <= $v_q) ? 1 : undef;
  97. } elsif ($rel_p eq REL_EQ) {
  98. return ($v_p < $v_q) ? 1 : 0;
  99. } else { # <<, <=
  100. return ($v_p < $v_q) ? 1 : undef;
  101. }
  102. }
  103. # Same logic as above, only inverted.
  104. if ($rel_q eq REL_GE) {
  105. if ($rel_p eq REL_LT) {
  106. return ($v_p <= $v_q) ? 0 : undef;
  107. } elsif ($rel_p eq REL_LE) {
  108. return ($v_p < $v_q) ? 0 : undef;
  109. } elsif ($rel_p eq REL_EQ) {
  110. return ($v_p >= $v_q) ? 1 : 0;
  111. } else { # >>, >=
  112. return ($v_p >= $v_q) ? 1 : undef;
  113. }
  114. }
  115. if ($rel_q eq REL_GT) {
  116. if ($rel_p eq REL_LT or $rel_p eq REL_LE) {
  117. return ($v_p <= $v_q) ? 0 : undef;
  118. } elsif ($rel_p eq REL_GT) {
  119. return ($v_p >= $v_q) ? 1 : undef;
  120. } elsif ($rel_p eq REL_EQ) {
  121. return ($v_p > $v_q) ? 1 : 0;
  122. } else {
  123. return ($v_p > $v_q) ? 1 : undef;
  124. }
  125. }
  126. return;
  127. }
  128. =item my $dep = deps_concat(@dep_list)
  129. This function concatenates multiple dependency lines into a single line,
  130. joining them with ", " if appropriate, and always returning a valid string.
  131. =cut
  132. sub deps_concat {
  133. my (@dep_list) = @_;
  134. return join(', ', grep { defined $_ } @dep_list);
  135. }
  136. =item my $dep = deps_parse($line, %options)
  137. This function parses the dependency line and returns an object, either a
  138. Dpkg::Deps::AND or a Dpkg::Deps::Union. Various options can alter the
  139. behaviour of that function.
  140. =over 4
  141. =item use_arch (defaults to 1)
  142. Take into account the architecture restriction part of the dependencies.
  143. Set to 0 to completely ignore that information.
  144. =item host_arch (defaults to the current architecture)
  145. Define the host architecture. By default it uses
  146. Dpkg::Arch::get_host_arch() to identify the proper architecture.
  147. =item build_arch (defaults to the current architecture)
  148. Define the build architecture. By default it uses
  149. Dpkg::Arch::get_build_arch() to identify the proper architecture.
  150. =item reduce_arch (defaults to 0)
  151. If set to 1, ignore dependencies that do not concern the current host
  152. architecture. This implicitely strips off the architecture restriction
  153. list so that the resulting dependencies are directly applicable to the
  154. current architecture.
  155. =item use_profiles (defaults to 1)
  156. Take into account the profile restriction part of the dependencies. Set
  157. to 0 to completely ignore that information.
  158. =item build_profiles (defaults to no profile)
  159. Define the active build profiles. By default no profile is defined.
  160. =item reduce_profiles (defaults to 0)
  161. If set to 1, ignore dependencies that do not concern the current build
  162. profile. This implicitly strips off the profile restriction list so
  163. that the resulting dependencies are directly applicable to the current
  164. profiles.
  165. =item reduce_restrictions (defaults to 0)
  166. If set to 1, ignore dependencies that do not concern the current set of
  167. restrictions. This implicitly strips off any restriction list so that the
  168. resulting dependencies are directly applicable to the current restriction.
  169. This currently implies C<reduce_arch> and C<reduce_profiles>, and overrides
  170. them if set.
  171. =item union (defaults to 0)
  172. If set to 1, returns a Dpkg::Deps::Union instead of a Dpkg::Deps::AND. Use
  173. this when parsing non-dependency fields like Conflicts.
  174. =item build_dep (defaults to 0)
  175. If set to 1, allow build-dep only arch qualifiers, that is “:native”.
  176. This should be set whenever working with build-deps.
  177. =back
  178. =cut
  179. sub deps_parse {
  180. my $dep_line = shift;
  181. my %options = (@_);
  182. $options{use_arch} = 1 if not exists $options{use_arch};
  183. $options{reduce_arch} = 0 if not exists $options{reduce_arch};
  184. $options{host_arch} = get_host_arch() if not exists $options{host_arch};
  185. $options{build_arch} = get_build_arch() if not exists $options{build_arch};
  186. $options{use_profiles} = 1 if not exists $options{use_profiles};
  187. $options{reduce_profiles} = 0 if not exists $options{reduce_profiles};
  188. $options{build_profiles} = [ get_build_profiles() ]
  189. if not exists $options{build_profiles};
  190. $options{reduce_restrictions} = 0 if not exists $options{reduce_restrictions};
  191. $options{union} = 0 if not exists $options{union};
  192. $options{build_dep} = 0 if not exists $options{build_dep};
  193. if ($options{reduce_restrictions}) {
  194. $options{reduce_arch} = 1;
  195. $options{reduce_profiles} = 1;
  196. }
  197. # Strip trailing/leading spaces
  198. $dep_line =~ s/^\s+//;
  199. $dep_line =~ s/\s+$//;
  200. my @dep_list;
  201. foreach my $dep_and (split(/\s*,\s*/m, $dep_line)) {
  202. my @or_list = ();
  203. foreach my $dep_or (split(/\s*\|\s*/m, $dep_and)) {
  204. my $dep_simple = Dpkg::Deps::Simple->new($dep_or, host_arch =>
  205. $options{host_arch},
  206. build_arch =>
  207. $options{build_arch},
  208. build_dep =>
  209. $options{build_dep});
  210. if (not defined $dep_simple->{package}) {
  211. warning(_g("can't parse dependency %s"), $dep_or);
  212. return;
  213. }
  214. $dep_simple->{arches} = undef if not $options{use_arch};
  215. if ($options{reduce_arch}) {
  216. $dep_simple->reduce_arch($options{host_arch});
  217. next if not $dep_simple->arch_is_concerned($options{host_arch});
  218. }
  219. $dep_simple->{restrictions} = undef if not $options{use_profiles};
  220. if ($options{reduce_profiles}) {
  221. $dep_simple->reduce_profiles($options{build_profiles});
  222. next if not $dep_simple->profile_is_concerned($options{build_profiles});
  223. }
  224. push @or_list, $dep_simple;
  225. }
  226. next if not @or_list;
  227. if (scalar @or_list == 1) {
  228. push @dep_list, $or_list[0];
  229. } else {
  230. my $dep_or = Dpkg::Deps::OR->new();
  231. $dep_or->add($_) foreach (@or_list);
  232. push @dep_list, $dep_or;
  233. }
  234. }
  235. my $dep_and;
  236. if ($options{union}) {
  237. $dep_and = Dpkg::Deps::Union->new();
  238. } else {
  239. $dep_and = Dpkg::Deps::AND->new();
  240. }
  241. foreach my $dep (@dep_list) {
  242. if ($options{union} and not $dep->isa('Dpkg::Deps::Simple')) {
  243. warning(_g('an union dependency can only contain simple dependencies'));
  244. return;
  245. }
  246. $dep_and->add($dep);
  247. }
  248. return $dep_and;
  249. }
  250. =item deps_compare($a, $b)
  251. Implements a comparison operator between two dependency objects.
  252. This function is mainly used to implement the sort() method.
  253. =back
  254. =cut
  255. my %relation_ordering = (
  256. undef => 0,
  257. REL_GE() => 1,
  258. REL_GT() => 2,
  259. REL_EQ() => 3,
  260. REL_LT() => 4,
  261. REL_LE() => 5,
  262. );
  263. sub deps_compare {
  264. my ($a, $b) = @_;
  265. return -1 if $a->is_empty();
  266. return 1 if $b->is_empty();
  267. while ($a->isa('Dpkg::Deps::Multiple')) {
  268. return -1 if $a->is_empty();
  269. my @deps = $a->get_deps();
  270. $a = $deps[0];
  271. }
  272. while ($b->isa('Dpkg::Deps::Multiple')) {
  273. return 1 if $b->is_empty();
  274. my @deps = $b->get_deps();
  275. $b = $deps[0];
  276. }
  277. my $ar = $a->{relation} // 'undef';
  278. my $br = $b->{relation} // 'undef';
  279. return (($a->{package} cmp $b->{package}) ||
  280. ($relation_ordering{$ar} <=> $relation_ordering{$br}) ||
  281. ($a->{version} cmp $b->{version}));
  282. }
  283. package Dpkg::Deps::Simple;
  284. =head1 OBJECTS - Dpkg::Deps::*
  285. There are several kind of dependencies. A Dpkg::Deps::Simple dependency
  286. represents a single dependency statement (it relates to one package only).
  287. Dpkg::Deps::Multiple dependencies are built on top of this object
  288. and combine several dependencies in a different manners. Dpkg::Deps::AND
  289. represents the logical "AND" between dependencies while Dpkg::Deps::OR
  290. represents the logical "OR". Dpkg::Deps::Multiple objects can contain
  291. Dpkg::Deps::Simple object as well as other Dpkg::Deps::Multiple objects.
  292. In practice, the code is only meant to handle the realistic cases which,
  293. given Debian's dependencies structure, imply those restrictions: AND can
  294. contain Simple or OR objects, OR can only contain Simple objects.
  295. Dpkg::Deps::KnownFacts is a special object that is used while evaluating
  296. dependencies and while trying to simplify them. It represents a set of
  297. installed packages along with the virtual packages that they might
  298. provide.
  299. =head2 COMMON FUNCTIONS
  300. =over 4
  301. =item $dep->is_empty()
  302. Returns true if the dependency is empty and doesn't contain any useful
  303. information. This is true when a Dpkg::Deps::Simple object has not yet
  304. been initialized or when a (descendant of) Dpkg::Deps::Multiple contains
  305. an empty list of dependencies.
  306. =item $dep->get_deps()
  307. Returns a list of sub-dependencies. For Dpkg::Deps::Simple it returns
  308. itself.
  309. =item $dep->output([$fh])
  310. =item "$dep"
  311. Returns a string representing the dependency. If $fh is set, it prints
  312. the string to the filehandle.
  313. =item $dep->implies($other_dep)
  314. Returns 1 when $dep implies $other_dep. Returns 0 when $dep implies
  315. NOT($other_dep). Returns undef when there's no implication. $dep and
  316. $other_dep do not need to be of the same type.
  317. =item $dep->sort()
  318. Sorts alphabetically the internal list of dependencies. It's a no-op for
  319. Dpkg::Deps::Simple objects.
  320. =item $dep->arch_is_concerned($arch)
  321. Returns true if the dependency applies to the indicated architecture. For
  322. multiple dependencies, it returns true if at least one of the
  323. sub-dependencies apply to this architecture.
  324. =item $dep->reduce_arch($arch)
  325. Simplifies the dependency to contain only information relevant to the given
  326. architecture. A Dpkg::Deps::Simple object can be left empty after this
  327. operation. For Dpkg::Deps::Multiple objects, the non-relevant
  328. sub-dependencies are simply removed.
  329. This trims off the architecture restriction list of Dpkg::Deps::Simple
  330. objects.
  331. =item $dep->get_evaluation($facts)
  332. Evaluates the dependency given a list of installed packages and a list of
  333. virtual packages provided. Those lists are part of the
  334. Dpkg::Deps::KnownFacts object given as parameters.
  335. Returns 1 when it's true, 0 when it's false, undef when some information
  336. is lacking to conclude.
  337. =item $dep->simplify_deps($facts, @assumed_deps)
  338. Simplifies the dependency as much as possible given the list of facts (see
  339. object Dpkg::Deps::KnownFacts) and a list of other dependencies that are
  340. known to be true.
  341. =item $dep->has_arch_restriction()
  342. For a simple dependency, returns the package name if the dependency
  343. applies only to a subset of architectures. For multiple dependencies, it
  344. returns the list of package names that have such a restriction.
  345. =item $dep->reset()
  346. Clears any dependency information stored in $dep so that $dep->is_empty()
  347. returns true.
  348. =back
  349. =head2 Dpkg::Deps::Simple
  350. Such an object has four interesting properties:
  351. =over 4
  352. =item package
  353. The package name (can be undef if the dependency has not been initialized
  354. or if the simplification of the dependency lead to its removal).
  355. =item relation
  356. The relational operator: "=", "<<", "<=", ">=" or ">>". It can be
  357. undefined if the dependency had no version restriction. In that case the
  358. following field is also undefined.
  359. =item version
  360. The version.
  361. =item arches
  362. The list of architectures where this dependency is applicable. It's
  363. undefined when there's no restriction, otherwise it's an
  364. array ref. It can contain an exclusion list, in that case each
  365. architecture is prefixed with an exclamation mark.
  366. =item archqual
  367. The arch qualifier of the dependency (can be undef if there's none).
  368. In the dependency "python:any (>= 2.6)", the arch qualifier is "any".
  369. =back
  370. =head3 METHODS
  371. =over 4
  372. =item $simple_dep->parse_string('dpkg-dev (>= 1.14.8) [!hurd-i386]')
  373. Parses the dependency and modifies internal properties to match the parsed
  374. dependency.
  375. =item $simple_dep->merge_union($other_dep)
  376. Returns true if $simple_dep could be modified to represent the union of
  377. both dependencies. Otherwise returns false.
  378. =back
  379. =cut
  380. use strict;
  381. use warnings;
  382. use Carp;
  383. use Dpkg::Arch qw(debarch_is);
  384. use Dpkg::Version;
  385. use Dpkg::ErrorHandling;
  386. use Dpkg::Gettext;
  387. use Dpkg::Util qw(:list);
  388. use parent qw(Dpkg::Interface::Storable);
  389. sub new {
  390. my ($this, $arg, %opts) = @_;
  391. my $class = ref($this) || $this;
  392. my $self = {};
  393. bless $self, $class;
  394. $self->reset();
  395. $self->{host_arch} = $opts{host_arch} || Dpkg::Arch::get_host_arch();
  396. $self->{build_arch} = $opts{build_arch} || Dpkg::Arch::get_build_arch();
  397. $self->{build_dep} = $opts{build_dep} || 0;
  398. $self->parse_string($arg) if defined($arg);
  399. return $self;
  400. }
  401. sub reset {
  402. my ($self) = @_;
  403. $self->{package} = undef;
  404. $self->{relation} = undef;
  405. $self->{version} = undef;
  406. $self->{arches} = undef;
  407. $self->{archqual} = undef;
  408. $self->{restrictions} = undef;
  409. }
  410. sub parse {
  411. my ($self, $fh, $desc) = @_;
  412. my $line = <$fh>;
  413. chomp($line);
  414. return $self->parse_string($line);
  415. }
  416. sub parse_string {
  417. my ($self, $dep) = @_;
  418. return if not $dep =~
  419. m{^\s* # skip leading whitespace
  420. ([a-zA-Z0-9][a-zA-Z0-9+.-]*) # package name
  421. (?: # start of optional part
  422. : # colon for architecture
  423. ([a-zA-Z0-9][a-zA-Z0-9-]*) # architecture name
  424. )? # end of optional part
  425. (?: # start of optional part
  426. \s* \( # open parenthesis for version part
  427. \s* (<<|<=|=|>=|>>|<|>) # relation part
  428. \s* (.*?) # do not attempt to parse version
  429. \s* \) # closing parenthesis
  430. )? # end of optional part
  431. (?: # start of optional architecture
  432. \s* \[ # open bracket for architecture
  433. \s* (.*?) # don't parse architectures now
  434. \s* \] # closing bracket
  435. )? # end of optional architecture
  436. (?: # start of optional restriction
  437. \s* < # open bracket for restriction
  438. \s* (.*?) # don't parse restrictions now
  439. \s* > # closing bracket
  440. )? # end of optional restriction
  441. \s*$ # trailing spaces at end
  442. }x;
  443. if (defined($2)) {
  444. return if $2 eq 'native' and not $self->{build_dep};
  445. $self->{archqual} = $2;
  446. }
  447. $self->{package} = $1;
  448. $self->{relation} = version_normalize_relation($3) if defined($3);
  449. if (defined($4)) {
  450. $self->{version} = Dpkg::Version->new($4);
  451. }
  452. if (defined($5)) {
  453. $self->{arches} = [ split(/\s+/, $5) ];
  454. }
  455. if (defined($6)) {
  456. $self->{restrictions} = [ map { lc } split /\s+/, $6 ];
  457. }
  458. }
  459. sub output {
  460. my ($self, $fh) = @_;
  461. my $res = $self->{package};
  462. if (defined($self->{archqual})) {
  463. $res .= ':' . $self->{archqual};
  464. }
  465. if (defined($self->{relation})) {
  466. $res .= ' (' . $self->{relation} . ' ' . $self->{version} . ')';
  467. }
  468. if (defined($self->{arches})) {
  469. $res .= ' [' . join(' ', @{$self->{arches}}) . ']';
  470. }
  471. if (defined($self->{restrictions})) {
  472. $res .= ' <' . join(' ', @{$self->{restrictions}}) . '>';
  473. }
  474. if (defined($fh)) {
  475. print { $fh } $res;
  476. }
  477. return $res;
  478. }
  479. # _arch_is_superset(\@p, \@q)
  480. #
  481. # Returns true if the arch list @p is a superset of arch list @q.
  482. # The arguments can also be undef in case there's no explicit architecture
  483. # restriction.
  484. sub _arch_is_superset {
  485. my ($p, $q) = @_;
  486. my $p_arch_neg = defined($p) && $p->[0] =~ /^!/;
  487. my $q_arch_neg = defined($q) && $q->[0] =~ /^!/;
  488. # If "p" has no arches, it is a superset of q and we should fall through
  489. # to the version check.
  490. if (not defined $p) {
  491. return 1;
  492. }
  493. # If q has no arches, it is a superset of p and there are no useful
  494. # implications.
  495. elsif (not defined $q) {
  496. return 0;
  497. }
  498. # Both have arches. If neither are negated, we know nothing useful
  499. # unless q is a subset of p.
  500. elsif (not $p_arch_neg and not $q_arch_neg) {
  501. my %p_arches = map { $_ => 1 } @{$p};
  502. my $subset = 1;
  503. for my $arch (@{$q}) {
  504. $subset = 0 unless $p_arches{$arch};
  505. }
  506. return 0 unless $subset;
  507. }
  508. # If both are negated, we know nothing useful unless p is a subset of
  509. # q (and therefore has fewer things excluded, and therefore is more
  510. # general).
  511. elsif ($p_arch_neg and $q_arch_neg) {
  512. my %q_arches = map { $_ => 1 } @{$q};
  513. my $subset = 1;
  514. for my $arch (@{$p}) {
  515. $subset = 0 unless $q_arches{$arch};
  516. }
  517. return 0 unless $subset;
  518. }
  519. # If q is negated and p isn't, we'd need to know the full list of
  520. # arches to know if there's any relationship, so bail.
  521. elsif (not $p_arch_neg and $q_arch_neg) {
  522. return 0;
  523. }
  524. # If p is negated and q isn't, q is a subset of p if none of the
  525. # negated arches in p are present in q.
  526. elsif ($p_arch_neg and not $q_arch_neg) {
  527. my %q_arches = map { $_ => 1 } @{$q};
  528. my $subset = 1;
  529. for my $arch (@{$p}) {
  530. $subset = 0 if $q_arches{substr($arch, 1)};
  531. }
  532. return 0 unless $subset;
  533. }
  534. return 1;
  535. }
  536. # _arch_qualifier_allows_implication($p, $q)
  537. #
  538. # Returns true if the arch qualifier $p and $q are compatible with the
  539. # implication $p -> $q, false otherwise. $p/$q can be
  540. # undef/"any"/"native" or an architecture string.
  541. sub _arch_qualifier_allows_implication {
  542. my ($p, $q) = @_;
  543. if (defined $p and $p eq 'any') {
  544. return 1 if defined $q and $q eq 'any';
  545. return 0;
  546. } elsif (defined $p and $p eq 'native') {
  547. return 1 if defined $q and ($q eq 'any' or $q eq 'native');
  548. return 0;
  549. } elsif (defined $p) {
  550. return 1 if defined $q and ($p eq $q or $q eq 'any');
  551. return 0;
  552. } else {
  553. return 0 if defined $q and $q ne 'any' and $q ne 'native';
  554. return 1;
  555. }
  556. }
  557. # Returns true if the dependency in parameter can deduced from the current
  558. # dependency. Returns false if it can be negated. Returns undef if nothing
  559. # can be concluded.
  560. sub implies {
  561. my ($self, $o) = @_;
  562. if ($o->isa('Dpkg::Deps::Simple')) {
  563. # An implication is only possible on the same package
  564. return if $self->{package} ne $o->{package};
  565. # Our architecture set must be a superset of the architectures for
  566. # o, otherwise we can't conclude anything.
  567. return unless _arch_is_superset($self->{arches}, $o->{arches});
  568. # The arch qualifier must not forbid an implication
  569. return unless _arch_qualifier_allows_implication($self->{archqual},
  570. $o->{archqual});
  571. # If o has no version clause, then our dependency is stronger
  572. return 1 if not defined $o->{relation};
  573. # If o has a version clause, we must also have one, otherwise there
  574. # can't be an implication
  575. return if not defined $self->{relation};
  576. return Dpkg::Deps::deps_eval_implication($self->{relation},
  577. $self->{version}, $o->{relation}, $o->{version});
  578. } elsif ($o->isa('Dpkg::Deps::AND')) {
  579. # TRUE: Need to imply all individual elements
  580. # FALSE: Need to NOT imply at least one individual element
  581. my $res = 1;
  582. foreach my $dep ($o->get_deps()) {
  583. my $implication = $self->implies($dep);
  584. unless (defined($implication) && $implication == 1) {
  585. $res = $implication;
  586. last if defined $res;
  587. }
  588. }
  589. return $res;
  590. } elsif ($o->isa('Dpkg::Deps::OR')) {
  591. # TRUE: Need to imply at least one individual element
  592. # FALSE: Need to not apply all individual elements
  593. # UNDEF: The rest
  594. my $res = undef;
  595. foreach my $dep ($o->get_deps()) {
  596. my $implication = $self->implies($dep);
  597. if (defined($implication)) {
  598. if (not defined $res) {
  599. $res = $implication;
  600. } else {
  601. if ($implication) {
  602. $res = 1;
  603. } else {
  604. $res = 0;
  605. }
  606. }
  607. last if defined($res) && $res == 1;
  608. }
  609. }
  610. return $res;
  611. } else {
  612. croak 'Dpkg::Deps::Simple cannot evaluate implication with a ' .
  613. ref($o);
  614. }
  615. }
  616. sub get_deps {
  617. my $self = shift;
  618. return $self;
  619. }
  620. sub sort {
  621. # Nothing to sort
  622. }
  623. sub arch_is_concerned {
  624. my ($self, $host_arch) = @_;
  625. return 0 if not defined $self->{package}; # Empty dep
  626. return 1 if not defined $self->{arches}; # Dep without arch spec
  627. my $seen_arch = 0;
  628. foreach my $arch (@{$self->{arches}}) {
  629. $arch=lc($arch);
  630. if ($arch =~ /^!/) {
  631. my $not_arch = $arch;
  632. $not_arch =~ s/^!//;
  633. if (debarch_is($host_arch, $not_arch)) {
  634. $seen_arch = 0;
  635. last;
  636. } else {
  637. # !arch includes by default all other arches
  638. # unless they also appear in a !otherarch
  639. $seen_arch = 1;
  640. }
  641. } elsif (debarch_is($host_arch, $arch)) {
  642. $seen_arch = 1;
  643. last;
  644. }
  645. }
  646. return $seen_arch;
  647. }
  648. sub reduce_arch {
  649. my ($self, $host_arch) = @_;
  650. if (not $self->arch_is_concerned($host_arch)) {
  651. $self->reset();
  652. } else {
  653. $self->{arches} = undef;
  654. }
  655. }
  656. sub has_arch_restriction {
  657. my ($self) = @_;
  658. if (defined $self->{arches}) {
  659. return $self->{package};
  660. } else {
  661. return ();
  662. }
  663. }
  664. sub profile_is_concerned {
  665. my ($self, $build_profiles) = @_;
  666. return 0 if not defined $self->{package}; # Empty dep
  667. return 1 if not defined $self->{restrictions}; # Dep without restrictions
  668. my $seen_profile = 0;
  669. foreach my $restriction (@{$self->{restrictions}}) {
  670. # Determine if this restriction is negated, and within the "profile"
  671. # namespace, otherwise it does not concern this check.
  672. next if $restriction !~ m/^(!)?profile\.(.*)/;
  673. my $negated = defined $1 && $1 eq '!';
  674. my $profile = $2;
  675. # Determine if the restriction matches any of the specified profiles.
  676. my $found = any { $_ eq $profile } @{$build_profiles};
  677. if ($negated) {
  678. if ($found) {
  679. $seen_profile = 0;
  680. last;
  681. } else {
  682. # "!profile.this" includes by default all other profiles
  683. # unless they also appear in a "!profile.other".
  684. $seen_profile = 1;
  685. }
  686. } elsif ($found) {
  687. $seen_profile = 1;
  688. last;
  689. }
  690. }
  691. return $seen_profile;
  692. }
  693. sub reduce_profiles {
  694. my ($self, $build_profiles) = @_;
  695. if (not $self->profile_is_concerned($build_profiles)) {
  696. $self->reset();
  697. } else {
  698. $self->{restrictions} = undef;
  699. }
  700. }
  701. sub get_evaluation {
  702. my ($self, $facts) = @_;
  703. return if not defined $self->{package};
  704. return $facts->_evaluate_simple_dep($self);
  705. }
  706. sub simplify_deps {
  707. my ($self, $facts) = @_;
  708. my $eval = $self->get_evaluation($facts);
  709. $self->reset() if defined $eval and $eval == 1;
  710. }
  711. sub is_empty {
  712. my $self = shift;
  713. return not defined $self->{package};
  714. }
  715. sub merge_union {
  716. my ($self, $o) = @_;
  717. return 0 if not $o->isa('Dpkg::Deps::Simple');
  718. return 0 if $self->is_empty() or $o->is_empty();
  719. return 0 if $self->{package} ne $o->{package};
  720. return 0 if defined $self->{arches} or defined $o->{arches};
  721. if (not defined $o->{relation} and defined $self->{relation}) {
  722. # Union is the non-versioned dependency
  723. $self->{relation} = undef;
  724. $self->{version} = undef;
  725. return 1;
  726. }
  727. my $implication = $self->implies($o);
  728. my $rev_implication = $o->implies($self);
  729. if (defined($implication)) {
  730. if ($implication) {
  731. $self->{relation} = $o->{relation};
  732. $self->{version} = $o->{version};
  733. return 1;
  734. } else {
  735. return 0;
  736. }
  737. }
  738. if (defined($rev_implication)) {
  739. if ($rev_implication) {
  740. # Already merged...
  741. return 1;
  742. } else {
  743. return 0;
  744. }
  745. }
  746. return 0;
  747. }
  748. package Dpkg::Deps::Multiple;
  749. =head2 Dpkg::Deps::Multiple
  750. This is the base class for Dpkg::Deps::{AND,OR,Union}. It implements
  751. the following methods:
  752. =over 4
  753. =item $mul->add($dep)
  754. Adds a new dependency object at the end of the list.
  755. =back
  756. =cut
  757. use strict;
  758. use warnings;
  759. use Carp;
  760. use Dpkg::ErrorHandling;
  761. use parent qw(Dpkg::Interface::Storable);
  762. sub new {
  763. my $this = shift;
  764. my $class = ref($this) || $this;
  765. my $self = { list => [ @_ ] };
  766. bless $self, $class;
  767. return $self;
  768. }
  769. sub reset {
  770. my ($self) = @_;
  771. $self->{list} = [];
  772. }
  773. sub add {
  774. my $self = shift;
  775. push @{$self->{list}}, @_;
  776. }
  777. sub get_deps {
  778. my $self = shift;
  779. return grep { not $_->is_empty() } @{$self->{list}};
  780. }
  781. sub sort {
  782. my $self = shift;
  783. my @res = ();
  784. @res = sort { Dpkg::Deps::deps_compare($a, $b) } @{$self->{list}};
  785. $self->{list} = [ @res ];
  786. }
  787. sub arch_is_concerned {
  788. my ($self, $host_arch) = @_;
  789. my $res = 0;
  790. foreach my $dep (@{$self->{list}}) {
  791. $res = 1 if $dep->arch_is_concerned($host_arch);
  792. }
  793. return $res;
  794. }
  795. sub reduce_arch {
  796. my ($self, $host_arch) = @_;
  797. my @new;
  798. foreach my $dep (@{$self->{list}}) {
  799. $dep->reduce_arch($host_arch);
  800. push @new, $dep if $dep->arch_is_concerned($host_arch);
  801. }
  802. $self->{list} = [ @new ];
  803. }
  804. sub has_arch_restriction {
  805. my ($self) = @_;
  806. my @res;
  807. foreach my $dep (@{$self->{list}}) {
  808. push @res, $dep->has_arch_restriction();
  809. }
  810. return @res;
  811. }
  812. sub is_empty {
  813. my $self = shift;
  814. return scalar @{$self->{list}} == 0;
  815. }
  816. sub merge_union {
  817. croak 'method merge_union() is only valid for Dpkg::Deps::Simple';
  818. }
  819. package Dpkg::Deps::AND;
  820. =head2 Dpkg::Deps::AND
  821. This object represents a list of dependencies who must be met at the same
  822. time.
  823. =over 4
  824. =item $and->output([$fh])
  825. The output method uses ", " to join the list of sub-dependencies.
  826. =back
  827. =cut
  828. use strict;
  829. use warnings;
  830. use parent -norequire, qw(Dpkg::Deps::Multiple);
  831. sub output {
  832. my ($self, $fh) = @_;
  833. my $res = join(', ', map { $_->output() } grep { not $_->is_empty() } $self->get_deps());
  834. if (defined($fh)) {
  835. print { $fh } $res;
  836. }
  837. return $res;
  838. }
  839. sub implies {
  840. my ($self, $o) = @_;
  841. # If any individual member can imply $o or NOT $o, we're fine
  842. foreach my $dep ($self->get_deps()) {
  843. my $implication = $dep->implies($o);
  844. return 1 if defined($implication) && $implication == 1;
  845. return 0 if defined($implication) && $implication == 0;
  846. }
  847. # If o is an AND, we might have an implication, if we find an
  848. # implication within us for each predicate in o
  849. if ($o->isa('Dpkg::Deps::AND')) {
  850. my $subset = 1;
  851. foreach my $odep ($o->get_deps()) {
  852. my $found = 0;
  853. foreach my $dep ($self->get_deps()) {
  854. $found = 1 if $dep->implies($odep);
  855. }
  856. $subset = 0 if not $found;
  857. }
  858. return 1 if $subset;
  859. }
  860. return;
  861. }
  862. sub get_evaluation {
  863. my ($self, $facts) = @_;
  864. # Return 1 only if all members evaluates to true
  865. # Return 0 if at least one member evaluates to false
  866. # Return undef otherwise
  867. my $result = 1;
  868. foreach my $dep ($self->get_deps()) {
  869. my $eval = $dep->get_evaluation($facts);
  870. if (not defined $eval) {
  871. $result = undef;
  872. } elsif ($eval == 0) {
  873. $result = 0;
  874. last;
  875. } elsif ($eval == 1) {
  876. # Still possible
  877. }
  878. }
  879. return $result;
  880. }
  881. sub simplify_deps {
  882. my ($self, $facts, @knowndeps) = @_;
  883. my @new;
  884. WHILELOOP:
  885. while (@{$self->{list}}) {
  886. my $dep = shift @{$self->{list}};
  887. my $eval = $dep->get_evaluation($facts);
  888. next if defined($eval) and $eval == 1;
  889. foreach my $odep (@knowndeps, @new) {
  890. next WHILELOOP if $odep->implies($dep);
  891. }
  892. # When a dependency is implied by another dependency that
  893. # follows, then invert them
  894. # "a | b, c, a" becomes "a, c" and not "c, a"
  895. my $i = 0;
  896. foreach my $odep (@{$self->{list}}) {
  897. if (defined $odep and $odep->implies($dep)) {
  898. splice @{$self->{list}}, $i, 1;
  899. unshift @{$self->{list}}, $odep;
  900. next WHILELOOP;
  901. }
  902. $i++;
  903. }
  904. push @new, $dep;
  905. }
  906. $self->{list} = [ @new ];
  907. }
  908. package Dpkg::Deps::OR;
  909. =head2 Dpkg::Deps::OR
  910. This object represents a list of dependencies of which only one must be met
  911. for the dependency to be true.
  912. =over 4
  913. =item $or->output([$fh])
  914. The output method uses " | " to join the list of sub-dependencies.
  915. =back
  916. =cut
  917. use strict;
  918. use warnings;
  919. use parent -norequire, qw(Dpkg::Deps::Multiple);
  920. sub output {
  921. my ($self, $fh) = @_;
  922. my $res = join(' | ', map { $_->output() } grep { not $_->is_empty() } $self->get_deps());
  923. if (defined($fh)) {
  924. print { $fh } $res;
  925. }
  926. return $res;
  927. }
  928. sub implies {
  929. my ($self, $o) = @_;
  930. # Special case for AND with a single member, replace it by its member
  931. if ($o->isa('Dpkg::Deps::AND')) {
  932. my @subdeps = $o->get_deps();
  933. if (scalar(@subdeps) == 1) {
  934. $o = $subdeps[0];
  935. }
  936. }
  937. # In general, an OR dependency can't imply anything except if each
  938. # of its member implies a member in the other OR dependency
  939. if ($o->isa('Dpkg::Deps::OR')) {
  940. my $subset = 1;
  941. foreach my $dep ($self->get_deps()) {
  942. my $found = 0;
  943. foreach my $odep ($o->get_deps()) {
  944. $found = 1 if $dep->implies($odep);
  945. }
  946. $subset = 0 if not $found;
  947. }
  948. return 1 if $subset;
  949. }
  950. return;
  951. }
  952. sub get_evaluation {
  953. my ($self, $facts) = @_;
  954. # Returns false if all members evaluates to 0
  955. # Returns true if at least one member evaluates to true
  956. # Returns undef otherwise
  957. my $result = 0;
  958. foreach my $dep ($self->get_deps()) {
  959. my $eval = $dep->get_evaluation($facts);
  960. if (not defined $eval) {
  961. $result = undef;
  962. } elsif ($eval == 1) {
  963. $result = 1;
  964. last;
  965. } elsif ($eval == 0) {
  966. # Still possible to have a false evaluation
  967. }
  968. }
  969. return $result;
  970. }
  971. sub simplify_deps {
  972. my ($self, $facts) = @_;
  973. my @new;
  974. WHILELOOP:
  975. while (@{$self->{list}}) {
  976. my $dep = shift @{$self->{list}};
  977. my $eval = $dep->get_evaluation($facts);
  978. if (defined($eval) and $eval == 1) {
  979. $self->{list} = [];
  980. return;
  981. }
  982. foreach my $odep (@new, @{$self->{list}}) {
  983. next WHILELOOP if $odep->implies($dep);
  984. }
  985. push @new, $dep;
  986. }
  987. $self->{list} = [ @new ];
  988. }
  989. package Dpkg::Deps::Union;
  990. =head2 Dpkg::Deps::Union
  991. This object represents a list of relationships.
  992. =over 4
  993. =item $union->output([$fh])
  994. The output method uses ", " to join the list of relationships.
  995. =item $union->implies($other_dep)
  996. =item $union->get_evaluation($other_dep)
  997. Those methods are not meaningful for this object and always return undef.
  998. =item $union->simplify_deps($facts)
  999. The simplication is done to generate an union of all the relationships.
  1000. It uses $simple_dep->merge_union($other_dep) to get its job done.
  1001. =back
  1002. =cut
  1003. use strict;
  1004. use warnings;
  1005. use parent -norequire, qw(Dpkg::Deps::Multiple);
  1006. sub output {
  1007. my ($self, $fh) = @_;
  1008. my $res = join(', ', map { $_->output() } grep { not $_->is_empty() } $self->get_deps());
  1009. if (defined($fh)) {
  1010. print { $fh } $res;
  1011. }
  1012. return $res;
  1013. }
  1014. sub implies {
  1015. # Implication test are not useful on Union
  1016. return;
  1017. }
  1018. sub get_evaluation {
  1019. # Evaluation are not useful on Union
  1020. return;
  1021. }
  1022. sub simplify_deps {
  1023. my ($self, $facts) = @_;
  1024. my @new;
  1025. WHILELOOP:
  1026. while (@{$self->{list}}) {
  1027. my $odep = shift @{$self->{list}};
  1028. foreach my $dep (@new) {
  1029. next WHILELOOP if $dep->merge_union($odep);
  1030. }
  1031. push @new, $odep;
  1032. }
  1033. $self->{list} = [ @new ];
  1034. }
  1035. package Dpkg::Deps::KnownFacts;
  1036. =head2 Dpkg::Deps::KnownFacts
  1037. This object represents a list of installed packages and a list of virtual
  1038. packages provided (by the set of installed packages).
  1039. =over 4
  1040. =item my $facts = Dpkg::Deps::KnownFacts->new();
  1041. Creates a new object.
  1042. =cut
  1043. use strict;
  1044. use warnings;
  1045. use Dpkg::Version;
  1046. sub new {
  1047. my $this = shift;
  1048. my $class = ref($this) || $this;
  1049. my $self = {
  1050. pkg => {},
  1051. virtualpkg => {},
  1052. };
  1053. bless $self, $class;
  1054. return $self;
  1055. }
  1056. =item $facts->add_installed_package($package, $version, $arch, $multiarch)
  1057. Records that the given version of the package is installed. If
  1058. $version/$arch is undefined we know that the package is installed but we
  1059. don't know which version/architecture it is. $multiarch is the Multi-Arch
  1060. field of the package. If $multiarch is undef, it will be equivalent to
  1061. "Multi-Arch: no".
  1062. Note that $multiarch is only used if $arch is provided.
  1063. =cut
  1064. sub add_installed_package {
  1065. my ($self, $pkg, $ver, $arch, $multiarch) = @_;
  1066. my $p = {
  1067. package => $pkg,
  1068. version => $ver,
  1069. architecture => $arch,
  1070. multiarch => $multiarch || 'no',
  1071. };
  1072. $self->{pkg}{"$pkg:$arch"} = $p if defined $arch;
  1073. push @{$self->{pkg}{$pkg}}, $p;
  1074. }
  1075. =item $facts->add_provided_package($virtual, $relation, $version, $by)
  1076. Records that the "$by" package provides the $virtual package. $relation
  1077. and $version correspond to the associated relation given in the Provides
  1078. field. This might be used in the future for versioned provides.
  1079. =cut
  1080. sub add_provided_package {
  1081. my ($self, $pkg, $rel, $ver, $by) = @_;
  1082. if (not exists $self->{virtualpkg}{$pkg}) {
  1083. $self->{virtualpkg}{$pkg} = [];
  1084. }
  1085. push @{$self->{virtualpkg}{$pkg}}, [ $by, $rel, $ver ];
  1086. }
  1087. =item my ($check, $param) = $facts->check_package($package)
  1088. $check is one when the package is found. For a real package, $param
  1089. contains the version. For a virtual package, $param contains an array
  1090. reference containing the list of packages that provide it (each package is
  1091. listed as [ $provider, $relation, $version ]).
  1092. This function is obsolete and should not be used. Dpkg::Deps::KnownFacts
  1093. is only meant to be filled with data and then passed to Dpkg::Deps
  1094. methods where appropriate, but it should not be directly queried.
  1095. =back
  1096. =cut
  1097. sub check_package {
  1098. my ($self, $pkg) = @_;
  1099. if (exists $self->{pkg}{$pkg}) {
  1100. return (1, $self->{pkg}{$pkg}[0]{version});
  1101. }
  1102. if (exists $self->{virtualpkg}{$pkg}) {
  1103. return (1, $self->{virtualpkg}{$pkg});
  1104. }
  1105. return (0, undef);
  1106. }
  1107. ## The functions below are private to Dpkg::Deps
  1108. sub _find_package {
  1109. my ($self, $dep, $lackinfos) = @_;
  1110. my ($pkg, $archqual) = ($dep->{package}, $dep->{archqual});
  1111. return if not exists $self->{pkg}{$pkg};
  1112. my $host_arch = $dep->{host_arch};
  1113. my $build_arch = $dep->{build_arch};
  1114. foreach my $p (@{$self->{pkg}{$pkg}}) {
  1115. my $a = $p->{architecture};
  1116. my $ma = $p->{multiarch};
  1117. if (not defined $a) {
  1118. $$lackinfos = 1;
  1119. next;
  1120. }
  1121. if (not defined $archqual) {
  1122. return $p if $ma eq 'foreign';
  1123. return $p if $a eq $host_arch or $a eq 'all';
  1124. } elsif ($archqual eq 'any') {
  1125. return $p if $ma eq 'allowed';
  1126. } elsif ($archqual eq 'native') {
  1127. return $p if $a eq $build_arch and $ma ne 'foreign';
  1128. } else {
  1129. return $p if $a eq $archqual;
  1130. }
  1131. }
  1132. return;
  1133. }
  1134. sub _find_virtual_packages {
  1135. my ($self, $pkg) = @_;
  1136. return () if not exists $self->{virtualpkg}{$pkg};
  1137. return @{$self->{virtualpkg}{$pkg}};
  1138. }
  1139. sub _evaluate_simple_dep {
  1140. my ($self, $dep) = @_;
  1141. my ($lackinfos, $pkg) = (0, $dep->{package});
  1142. my $p = $self->_find_package($dep, \$lackinfos);
  1143. if ($p) {
  1144. if (defined $dep->{relation}) {
  1145. if (defined $p->{version}) {
  1146. return 1 if version_compare_relation($p->{version},
  1147. $dep->{relation}, $dep->{version});
  1148. } else {
  1149. $lackinfos = 1;
  1150. }
  1151. } else {
  1152. return 1;
  1153. }
  1154. }
  1155. foreach my $virtpkg ($self->_find_virtual_packages($pkg)) {
  1156. # XXX: Adapt when versioned provides are allowed
  1157. next if defined $virtpkg->[1];
  1158. next if defined $dep->{relation}; # Provides don't satisfy versioned deps
  1159. return 1;
  1160. }
  1161. return if $lackinfos;
  1162. return 0;
  1163. }
  1164. =head1 CHANGES
  1165. =head2 Version 1.02
  1166. =over
  1167. =item * Add new Dpkg::deps_concat() function.
  1168. =back
  1169. =head2 Version 1.01
  1170. =over
  1171. =item * Add new $dep->reset() method that all dependency objects support.
  1172. =item * Dpkg::Deps::Simple now recognizes the arch qualifier "any" and
  1173. stores it in the "archqual" property when present.
  1174. =item * Dpkg::Deps::KnownFacts->add_installed_package() now accepts 2
  1175. supplementary parameters ($arch and $multiarch).
  1176. =item * Dpkg::Deps::KnownFacts->check_package() is obsolete, it should
  1177. not have been part of the public API.
  1178. =back
  1179. =cut
  1180. 1;