PortInfo.pm 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. # ex:ts=8 sw=4:
  2. # $OpenBSD: PortInfo.pm,v 1.36 2015/06/23 08:51:53 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. package AddInfo;
  20. sub add
  21. {
  22. my ($class, $var, $o, $value, $parent) = @_;
  23. return if $value =~ m/^[\s\-]*$/;
  24. $o->{$var} = $class->new($value, $o, $parent);
  25. }
  26. sub new
  27. {
  28. my ($class, $value) = @_;
  29. bless \$value, $class;
  30. }
  31. sub string
  32. {
  33. my $self = shift;
  34. return $$self;
  35. }
  36. sub quickie
  37. {
  38. return 0;
  39. }
  40. package AddIgnore;
  41. our @ISA = qw(AddInfo);
  42. sub string
  43. {
  44. my $self = shift;
  45. my $msg = $$self;
  46. $msg =~ s/\\//g;
  47. $msg =~ s/\"\s+\"/\; /g;
  48. return $msg;
  49. }
  50. package AddYesNo;
  51. our @ISA = qw(AddInfo);
  52. sub add
  53. {
  54. my ($class, $var, $o, $value, $parent) = @_;
  55. return if $value =~ m/^no$/i;
  56. $o->{$var} = $class->new($value, $o, $parent);
  57. }
  58. sub new
  59. {
  60. my ($class, $value) = @_;
  61. my $a = 1;
  62. bless \$a, $class;
  63. }
  64. # micro-optimisation: to save space and time, we only create value if
  65. # PERMIT_DISTFILES* is != yes.
  66. package AddNegative;
  67. our @ISA = qw(AddInfo);
  68. sub add
  69. {
  70. my ($class, $var, $o, $value, $parent) = @_;
  71. return if $value =~ m/^yes$/i;
  72. $o->{$var} = $class->new($value, $o, $parent);
  73. }
  74. sub new
  75. {
  76. my ($class, $value) = @_;
  77. my $a = 0;
  78. bless \$a, $class;
  79. }
  80. package AddInfoShow;
  81. our @ISA = qw(AddInfo);
  82. sub quickie
  83. {
  84. return 1;
  85. }
  86. package AddList;
  87. our @ISA = qw(AddInfo);
  88. sub make_list
  89. {
  90. my ($class, $value) = @_;
  91. $value =~ s/^\s+//;
  92. $value =~ s/\s+$//;
  93. return split(/\s+/, $value);
  94. }
  95. sub new
  96. {
  97. my ($class, $value) = @_;
  98. my %values = map {($_, 1)} $class->make_list($value);
  99. bless \%values, $class;
  100. }
  101. sub string
  102. {
  103. my $self = shift;
  104. return join(', ', keys %$self);
  105. }
  106. package AddPropertyList;
  107. our @ISA = (qw(AddList));
  108. sub new
  109. {
  110. my ($class, $value) = @_;
  111. my %h = ();
  112. for my $v ($class->make_list($value)) {
  113. if ($v =~ /^(tag)\:(.*)$/) {
  114. $h{$1} = $2;
  115. } else {
  116. $h{$v} = 1;
  117. }
  118. }
  119. bless \%h, $class;
  120. }
  121. sub string
  122. {
  123. my $self = shift;
  124. my @l = ();
  125. while (my ($k, $v) = each %$self) {
  126. if ($v eq '1') {
  127. push(@l, $k);
  128. } else {
  129. push(@l, "$k->$v");
  130. }
  131. }
  132. return join(',', @l);
  133. }
  134. package AddOrderedList;
  135. our @ISA = qw(AddList);
  136. sub new
  137. {
  138. my ($class, $value) = @_;
  139. bless [$class->make_list($value)], $class;
  140. }
  141. sub string
  142. {
  143. my $self = shift;
  144. return join(' ', @$self);
  145. }
  146. package FetchManually;
  147. our @ISA = qw(AddOrderedList);
  148. sub add
  149. {
  150. my ($class, $var, $o, $value, $parent) = @_;
  151. return if $value =~ /^\s*no\s*$/i;
  152. $class->SUPER::add($var, $o, $value, $parent);
  153. }
  154. sub make_list
  155. {
  156. my ($class, $value) = @_;
  157. $value =~ s/^\s*\"//;
  158. $value =~ s/\"\s*$//;
  159. return split(/\"\s*\"/, $value);
  160. }
  161. sub string
  162. {
  163. my $self = shift;
  164. return join("\n", @$self);
  165. }
  166. package AddDepends;
  167. our @ISA = qw(AddList);
  168. sub extra
  169. {
  170. return 'EXTRA';
  171. }
  172. sub new
  173. {
  174. my ($class, $value, $self, $parent) = @_;
  175. my $r = {};
  176. for my $d ($class->make_list($value)) {
  177. my $copy = $d;
  178. next if $d =~ m/^$/;
  179. $d =~ s/^\:+//;
  180. $d =~ s/^[^\/]*\://;
  181. if ($d =~ s/\:(?:patch|build|configure)$//) {
  182. Extra->add($class->extra, $self, $d);
  183. } else {
  184. $d =~ s/\:$//;
  185. if ($d =~ m/[:<>=]/) {
  186. DPB::Util->die("Error: invalid *DEPENDS $copy");
  187. } else {
  188. my $info = DPB::PkgPath->new($d);
  189. $info->{parent} //= $parent;
  190. $r->{$info} = $info;
  191. }
  192. }
  193. }
  194. bless $r, $class;
  195. }
  196. sub string
  197. {
  198. my $self = shift;
  199. return '['.join(';', map {$_->logname} (values %$self)).']';
  200. }
  201. sub quickie
  202. {
  203. return 1;
  204. }
  205. package AddTestDepends;
  206. our @ISA = qw(AddDepends);
  207. sub extra
  208. {
  209. return 'EXTRA2';
  210. }
  211. package Extra;
  212. our @ISA = qw(AddDepends);
  213. sub add
  214. {
  215. my ($class, $key, $self, $value, $parent) = @_;
  216. $self->{$key} //= bless {}, $class;
  217. my $path = DPB::PkgPath->new($value);
  218. $path->{parent} //= $parent;
  219. $self->{$key}{$path} = $path;
  220. return $self;
  221. }
  222. package DPB::PortInfo;
  223. my %adder = (
  224. # actual info from dump-vars
  225. FULLPKGNAME => "AddInfoShow",
  226. RUN_DEPENDS => "AddDepends",
  227. BUILD_DEPENDS => "AddDepends",
  228. LIB_DEPENDS => "AddDepends",
  229. SUBPACKAGE => "AddInfo",
  230. BUILD_PACKAGES => "AddList",
  231. DPB_PROPERTIES => "AddPropertyList",
  232. IGNORE => "AddIgnore",
  233. FLAVOR => "AddList",
  234. DISTFILES => 'AddList',
  235. PATCHFILES => 'AddList',
  236. SUPDISTFILES => 'AddList',
  237. DIST_SUBDIR => 'AddInfo',
  238. CHECKSUM_FILE => 'AddInfo',
  239. FETCH_MANUALLY => 'FetchManually',
  240. MISSING_FILES => 'AddList',
  241. MASTER_SITES => 'AddOrderedList',
  242. MASTER_SITES0 => 'AddOrderedList',
  243. MASTER_SITES1 => 'AddOrderedList',
  244. MASTER_SITES2 => 'AddOrderedList',
  245. MASTER_SITES3 => 'AddOrderedList',
  246. MASTER_SITES4 => 'AddOrderedList',
  247. MASTER_SITES5 => 'AddOrderedList',
  248. MASTER_SITES6 => 'AddOrderedList',
  249. MASTER_SITES7 => 'AddOrderedList',
  250. MASTER_SITES8 => 'AddOrderedList',
  251. MASTER_SITES9 => 'AddOrderedList',
  252. MULTI_PACKAGES => 'AddList',
  253. PERMIT_DISTFILES_FTP => 'AddNegative',
  254. PERMIT_DISTFILES_CDROM => 'AddNegative',
  255. # not yet used, provision for regression tests
  256. TEST_DEPENDS => "AddTestDepends",
  257. NO_TEST => "AddNegative",
  258. TEST_IS_INTERACTIVE => "AddYesNo",
  259. # extra stuff we're generating
  260. DEPENDS => "AddDepends", # all BUILD_DEPENDS/LIB_DEPENDS
  261. EXTRA => "Extra", # extract stuff and things in DEPENDS
  262. EXTRA2 => "Extra", # extract stuff and things in TEST_DEPENDS
  263. BEXTRA => "Extra", # EXTRA moved from todo to done
  264. BDEPENDS => "AddDepends",# DEPENDS moved from todo to done
  265. RDEPENDS => "AddDepends",# RUN_DEPENDS moved from todo to done
  266. DIST => "AddDepends", # all DISTFILES with all info
  267. FDEPENDS => "AddDepends",# DISTFILES too, but after DISTIGNORE,
  268. # and shrinking
  269. # DISTIGNORE should be there ?
  270. );
  271. sub wanted
  272. {
  273. my ($class, $var) = @_;
  274. return $adder{$var};
  275. }
  276. sub new
  277. {
  278. my ($class, $pkgpath) = @_;
  279. $pkgpath->{info} = bless {}, $class;
  280. }
  281. sub add
  282. {
  283. my ($self, $var, $value, $parent) = @_;
  284. $adder{$var}->add($var, $self, $value, $parent);
  285. }
  286. sub dump
  287. {
  288. my ($self, $fh) = @_;
  289. for my $k (sort keys %adder) {
  290. print $fh "\t $k = ", $self->{$k}->string, "\n"
  291. if defined $self->{$k};
  292. }
  293. }
  294. my $string = "ignored already";
  295. my $s2 = "stub_name";
  296. my $stub_name = bless(\$s2, "AddInfoShow");
  297. my $stub_info = bless { IGNORE => bless(\$string, "AddIgnore"),
  298. FULLPKGNAME => $stub_name}, __PACKAGE__;
  299. sub stub
  300. {
  301. return $stub_info;
  302. }
  303. sub stub_name
  304. {
  305. my $self = shift;
  306. $self->{FULLPKGNAME} = $stub_name;
  307. }
  308. sub is_stub
  309. {
  310. return shift eq $stub_info;
  311. }
  312. use Data::Dumper;
  313. sub quick_dump
  314. {
  315. my ($self, $fh) = @_;
  316. for my $k (sort keys %adder) {
  317. if (defined $self->{$k} and $adder{$k}->quickie) {
  318. print $fh "\t $k = ";
  319. if (ref($self->{$k}) eq 'HASH') {
  320. print $fh "????\n";
  321. } else {
  322. print $fh $self->{$k}->string, "\n" ;
  323. }
  324. }
  325. }
  326. }
  327. sub fullpkgname
  328. {
  329. my $self = shift;
  330. return (defined $self->{FULLPKGNAME}) ?
  331. $self->{FULLPKGNAME}->string : undef;
  332. }
  333. sub has_property
  334. {
  335. my ($self, $name) = @_;
  336. return (defined $self->{DPB_PROPERTIES}) ?
  337. $self->{DPB_PROPERTIES}{$name} : undef;
  338. }
  339. sub want_tests
  340. {
  341. my ($self, $name) = @_;
  342. if (defined $self->{NO_TEST} && $self->{NO_TEST} == 0) {
  343. return 1;
  344. } else {
  345. return 0;
  346. }
  347. }
  348. sub solve_depends
  349. {
  350. my ($self, $withtest) = @_;
  351. if (!defined $self->{solved}) {
  352. my $dep = {};
  353. my @todo = (qw(DEPENDS BDEPENDS));
  354. if ($withtest) {
  355. push(@todo, qw(TDEPENDS));
  356. }
  357. for my $k (@todo) {
  358. if (exists $self->{$k}) {
  359. for my $d (values %{$self->{$k}}) {
  360. $dep->{$d->fullpkgname} = 1;
  361. }
  362. }
  363. next unless exists $self->{BEXTRA};
  364. for my $two (values %{$self->{BEXTRA}}) {
  365. next unless exists $two->{info}{$k};
  366. for my $d (values %{$two->{info}{$k}}) {
  367. $dep->{$d->fullpkgname} = 1;
  368. }
  369. }
  370. }
  371. bless $dep, 'AddList';
  372. $self->{solved} = $dep;
  373. }
  374. return $self->{solved};
  375. }
  376. 1;