PkgPath.pm 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. # ex:ts=8 sw=4:
  2. # $OpenBSD: PkgPath.pm,v 1.51 2015/07/02 08:04:22 espie Exp $
  3. #
  4. # Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
  5. #
  6. # Permission to use, copy, modify, and distribute this software for any
  7. # purpose with or without fee is hereby granted, provided that the above
  8. # copyright notice and this permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. use strict;
  18. use warnings;
  19. # Handles PkgPath;
  20. # all this code is *seriously* dependent on unique objects
  21. # everything is done to normalize PkgPaths, so that we have
  22. # one pkgpath object for each distinct flavor/subpackage combination
  23. use DPB::BasePkgPath;
  24. use DPB::Util;
  25. package DPB::PkgPath;
  26. our @ISA = qw(DPB::BasePkgPath);
  27. sub init
  28. {
  29. my $self = shift;
  30. # XXX
  31. $self->{has} = 5;
  32. }
  33. sub forcejunk
  34. {
  35. return 0;
  36. }
  37. sub path
  38. {
  39. my $self = shift;
  40. return $self;
  41. }
  42. sub clone_properties
  43. {
  44. my ($n, $o) = @_;
  45. $n->{has} //= $o->{has};
  46. $n->{info} //= $o->{info};
  47. }
  48. sub sanity_check
  49. {
  50. my ($class, $state) = @_;
  51. my $quicklog = $state->logger->append('equiv');
  52. for my $p ($class->seen) {
  53. next if defined $p->{category};
  54. next unless defined $p->{info};
  55. for my $w ($p->build_path_list) {
  56. if (!defined $w->{info}) {
  57. print $quicklog $w->fullpkgpath,
  58. " has no info(", $p->fullpkgpath, ")\n";
  59. $w->{info} = DPB::PortInfo->stub;
  60. } elsif (!defined $w->{info}{FULLPKGNAME}) {
  61. print $quicklog $w->fullpkgpath,
  62. " has no fullpkgname(",
  63. $p->fullpkgpath, ")\n";
  64. $w->{info} = DPB::PortInfo->stub;
  65. }
  66. }
  67. }
  68. }
  69. # XXX All this code knows too much about PortInfo for proper OO
  70. sub fullpkgname
  71. {
  72. my $self = shift;
  73. if (defined $self->{info} && defined $self->{info}{FULLPKGNAME}) {
  74. return ${$self->{info}{FULLPKGNAME}};
  75. } else {
  76. DPB::Util->die(
  77. $self->fullpkgpath." has no associated fullpkgname",
  78. $self->{info});
  79. }
  80. }
  81. sub has_fullpkgname
  82. {
  83. my $self = shift;
  84. return defined $self->{info} && defined $self->{info}{FULLPKGNAME};
  85. }
  86. # requires flavor as a hash
  87. sub flavor
  88. {
  89. my $self = shift;
  90. return $self->{info}{FLAVOR};
  91. }
  92. sub subpackage
  93. {
  94. my $self = shift;
  95. if (defined $self->{info} && defined $self->{info}{SUBPACKAGE}) {
  96. return ${$self->{info}{SUBPACKAGE}};
  97. } else {
  98. return undef;
  99. }
  100. }
  101. sub dump
  102. {
  103. my ($self, $fh) = @_;
  104. print $fh $self->fullpkgpath, "\n";
  105. if (defined $self->{info}) {
  106. $self->{info}->dump($fh);
  107. }
  108. }
  109. sub quick_dump
  110. {
  111. my ($self, $fh) = @_;
  112. print $fh $self->fullpkgpath, "\n";
  113. if (defined $self->{info}) {
  114. $self->{info}->quick_dump($fh);
  115. }
  116. }
  117. # interface with logger/lock engine
  118. sub logname
  119. {
  120. my $self = shift;
  121. return $self->fullpkgpath;
  122. }
  123. sub lockname
  124. {
  125. my $self = shift;
  126. return $self->pkgpath;
  127. }
  128. sub print_parent
  129. {
  130. my ($self, $fh) = @_;
  131. if (defined $self->{parent}) {
  132. print $fh "parent=", $self->{parent}->logname, "\n";
  133. }
  134. }
  135. sub unlock_conditions
  136. {
  137. my ($v, $engine) = @_;
  138. return $v->{info} && $engine->{buildable}{builder}->check($v);
  139. }
  140. sub requeue
  141. {
  142. my ($v, $engine) = @_;
  143. $engine->requeue($v);
  144. }
  145. sub simplifies_to
  146. {
  147. my ($self, $simpler, $state) = @_;
  148. $state->{affinity}->simplifies_to($self, $simpler);
  149. my $quicklog = $state->logger->append('equiv');
  150. print $quicklog $self->fullpkgpath, " -> ", $simpler->fullpkgpath, "\n";
  151. }
  152. sub equates
  153. {
  154. my ($class, $h) = @_;
  155. DPB::Job::Port->equates($h);
  156. DPB::Heuristics->equates($h);
  157. }
  158. # in the MULTI_PACKAGES case, some stuff may need to be forcibly removed
  159. sub fix_multi
  160. {
  161. my ($class, $h) = @_;
  162. my $multi;
  163. my $may_vanish;
  164. my $path;
  165. for my $v (values %$h) {
  166. $path //= $v; # one for later
  167. my $info = $v->{info};
  168. # share !
  169. if (defined $info->{BUILD_PACKAGES}) {
  170. $multi = $info->{BUILD_PACKAGES};
  171. }
  172. # and this one is special
  173. if (defined $info->{MULTI_PACKAGES}) {
  174. $may_vanish = $info->{MULTI_PACKAGES};
  175. }
  176. }
  177. # in case BUILD_PACKAGES "erases" some multi, we need to
  178. # stub out the correspond paths, so that dependent ports
  179. # will vanish
  180. if (defined $may_vanish) {
  181. for my $m (keys %$may_vanish) {
  182. # okay those are actually present
  183. next if exists $multi->{$m};
  184. # make a dummy path that will get ignored
  185. my $stem = $path->pkgpath_and_flavors;
  186. my $w = DPB::PkgPath->new("$stem,$m");
  187. if (!defined $w->{info}) {
  188. $w->{info} = DPB::PortInfo->new($w);
  189. $w->{info}->stub_name;
  190. }
  191. #delete $w->{info}->{IGNORE};
  192. if (!defined $w->{info}->{IGNORE}) {
  193. $w->{info}->add('IGNORE',
  194. "vanishes from BUILD_PACKAGES");
  195. }
  196. $h->{$w} = $w;
  197. }
  198. }
  199. if (defined $multi) {
  200. for my $v (values %$h) {
  201. $v->{info}{BUILD_PACKAGES} = $multi;
  202. }
  203. }
  204. }
  205. # we're always called from values corresponding to the same subdir.
  206. sub merge_depends
  207. {
  208. my ($class, $h) = @_;
  209. $class->fix_multi($h);
  210. my $global = bless {}, "AddDepends";
  211. my $global2 = bless {}, "AddDepends";
  212. my $global3 = bless {}, "AddDepends";
  213. my $global4 = bless {}, "AddDepends";
  214. for my $v (values %$h) {
  215. my $info = $v->{info};
  216. # let's allow doing that even for ignore'd stuff so
  217. # that dpb -F will work
  218. if (defined $info->{DIST} && !defined $info->{DISTIGNORE}) {
  219. for my $f (values %{$info->{DIST}}) {
  220. $info->{FDEPENDS}{$f} = $f;
  221. bless $info->{FDEPENDS}, "AddDepends";
  222. }
  223. }
  224. # XXX don't grab dependencies for IGNOREd stuff
  225. next if defined $info->{IGNORE};
  226. for my $k (qw(LIB_DEPENDS BUILD_DEPENDS)) {
  227. if (defined $info->{$k}) {
  228. for my $d (values %{$info->{$k}}) {
  229. # filter these out like during build
  230. # simpler to figure out logs from
  231. # depends stage that way.
  232. $d->{wantbuild} = 1;
  233. next if $d->pkgpath_and_flavors eq
  234. $v->pkgpath_and_flavors;
  235. $global->{$d} = $d;
  236. }
  237. }
  238. }
  239. for my $k (qw(LIB_DEPENDS RUN_DEPENDS)) {
  240. if (defined $info->{$k}) {
  241. for my $d (values %{$info->{$k}}) {
  242. $d->{wantbuild} = 1;
  243. $info->{RDEPENDS}{$d} = $d;
  244. bless $info->{RDEPENDS}, "AddDepends";
  245. }
  246. }
  247. }
  248. if (defined $info->{EXTRA}) {
  249. for my $d (values %{$info->{EXTRA}}) {
  250. $global3->{$d} = $d;
  251. $d->{wantinfo} = 1;
  252. }
  253. }
  254. for my $k (qw(LIB_DEPENDS BUILD_DEPENDS RUN_DEPENDS
  255. SUBPACKAGE FLAVOR EXTRA PERMIT_DISTFILES_FTP
  256. MULTI_PACKAGES PERMIT_DISTFILES_CDROM)) {
  257. delete $info->{$k};
  258. }
  259. }
  260. if (values %$global > 0) {
  261. for my $v (values %$h) {
  262. # remove stuff that depends on itself
  263. delete $global->{$v};
  264. $v->{info}{DEPENDS} = $global;
  265. $v->{info}{BDEPENDS} = $global2;
  266. }
  267. }
  268. if (values %$global3 > 0) {
  269. for my $v (values %$h) {
  270. $v->{info}{EXTRA} = $global3;
  271. $v->{info}{BEXTRA} = $global4;
  272. }
  273. }
  274. }
  275. sub build_path_list
  276. {
  277. my ($v) = @_;
  278. my @l = ($v);
  279. my $stem = $v->pkgpath_and_flavors;
  280. my $w = DPB::PkgPath->new($stem);
  281. if ($w ne $v) {
  282. push(@l, $w);
  283. }
  284. if (defined $v->{info}) {
  285. for my $m (keys %{$v->{info}{BUILD_PACKAGES}}) {
  286. next if $m eq '-';
  287. my $w = DPB::PkgPath->new("$stem,$m");
  288. if ($w ne $v) {
  289. push(@l, $w);
  290. }
  291. }
  292. }
  293. return @l;
  294. }
  295. sub break
  296. {
  297. my ($self, $why) = @_;
  298. if (defined $self->{broken}) {
  299. $self->{broken} .= " $why";
  300. } else {
  301. $self->{broken} = $why;
  302. }
  303. }
  304. 1;