openpkg-build.pl 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. ##
  2. ## openpkg-build.pl -- create build scripts from package index
  3. ##
  4. ## Copyright (c) 2000-2002 Cable & Wireless Deutschland GmbH
  5. ## Copyright (c) 2000-2002 The OpenPKG Project <http://www.openpkg.org/>
  6. ## Copyright (c) 2000-2002 Ralf S. Engelschall <rse@engelschall.com>
  7. ##
  8. ## Permission to use, copy, modify, and distribute this software for
  9. ## any purpose with or without fee is hereby granted, provided that
  10. ## the above copyright notice and this permission notice appear in all
  11. ## copies.
  12. ##
  13. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  14. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  17. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  20. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  22. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  23. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. ## SUCH DAMAGE.
  25. ##
  26. require 5;
  27. $|=1; # autoflush
  28. use strict;
  29. use vars qw/$opt_R $opt_r $opt_f $opt_u $opt_U $opt_a $opt_A $opt_z $opt_Z $opt_P $opt_N $opt_E $opt_i $opt_D $opt_p $opt_q $opt_s $opt_S/;
  30. getopts('R:r:f:uUaAzZP:N:E:iD:p:qsS');
  31. ##########################################################################
  32. sub getopts ($) {
  33. my($opts) = @_;
  34. my(%optf) = map { /(\w)/; $1 => $_ } $opts =~ /(\w:|\w)/g;
  35. my(%opts,@argv,$optarg);
  36. foreach (@ARGV) {
  37. if (@argv) {
  38. push @argv, $_;
  39. } elsif (defined $optarg) {
  40. if (exists $opts{$optarg}) {
  41. $opts{$optarg} .= " $_";
  42. } else {
  43. $opts{$optarg} = $_;
  44. }
  45. $optarg = undef;
  46. } elsif (!/^[-]/) {
  47. push @argv, $_;
  48. } else {
  49. while (/^\-(\w)(.*)/) {
  50. if (exists $optf{$1}) {
  51. if (length($optf{$1}) > 1) {
  52. if ($2 ne '') {
  53. if (exists $opts{$1}) {
  54. $opts{$1} .= " $2";
  55. } else {
  56. $opts{$1} = $2;
  57. }
  58. } else {
  59. $optarg = $1;
  60. }
  61. last;
  62. } else {
  63. $opts{$1} = 1;
  64. }
  65. } else {
  66. warn "warning: unknown option $_\n";
  67. }
  68. $_ = "-$2";
  69. }
  70. }
  71. }
  72. if (defined $optarg) {
  73. warn "warning: option $optarg requires an argument\n";
  74. }
  75. foreach (keys %opts) {
  76. eval '$opt_'.$_.' = "'.quotemeta($opts{$_}).'";';
  77. }
  78. @ARGV = @argv;
  79. }
  80. my(%env) = ( '' => { } );
  81. if (open(FH, "< $ENV{'HOME'}/.openpkg/build")) {
  82. my($env) = $env{''};
  83. while (<FH>) {
  84. if (/^\s*\[([^\]]*)\]/) {
  85. $env{$1} = { } unless $env{$1};
  86. $env = $env{$1};
  87. } elsif (my($opt,$val) = /^\-([RfruUaAzPN])\s*(.*?)\s*$/) {
  88. $val = 1 unless defined $val;
  89. $env->{$opt} = $val;
  90. }
  91. }
  92. close(FH);
  93. }
  94. die "openpkg:build:USAGE: $0 [-R rpm] [-r repository] [-f index.rdf] [-uUzZiqS] [-P priv-cmd] [-N non-priv-cmd] [-p platform] [-Dwith ...] [-Ename ...] ( [-aA] | patternlist )\n"
  95. unless $#ARGV >= 0 || ($#ARGV == -1 && ($opt_a || $opt_A));
  96. ##########################################################################
  97. sub conditional ($$) {
  98. my($cond,$with) = @_;
  99. my(@s,$res);
  100. return 1 if $cond eq '';
  101. foreach (split(/\s+/,$cond)) {
  102. if ($_ eq '+') {
  103. die "FATAL: stack underflow in: $cond\n" if scalar(@s)<2;
  104. my($a) = pop @s;
  105. my($b) = pop @s;
  106. push @s, $a && $b;
  107. } elsif ($_ eq '|') {
  108. die "FATAL: stack underflow in: $cond\n" if scalar(@s)<2;
  109. my($a) = pop @s;
  110. my($b) = pop @s;
  111. push @s, $a && $b;
  112. } elsif ($_ eq '!') {
  113. die "FATAL: stack underflow in: $cond\n" if scalar(@s)<1;
  114. my($a) = pop @s;
  115. push @s, !$a;
  116. } else {
  117. push @s, $with->{$_} eq 'yes';
  118. }
  119. }
  120. die "FATAL: stack underflow in: $cond\n" if scalar(@s)<1;
  121. $res = pop @s;
  122. die "FATAL: stack not empty in: $cond\n" if scalar(@s)>0;
  123. return $res;
  124. }
  125. ##########################################################################
  126. my($RPM,$RPM_PRIV,$RPM_NPRIV,$CURL,$PROG);
  127. $RPM = $opt_R || $env{''}->{opt}->{'R'} || '@l_prefix@/bin/rpm';
  128. $RPM = (`which $RPM` =~ m{^(/.*)})[0];
  129. die "FATAL: cannot locate rpm in path\n" unless $RPM =~ m{^/};
  130. # augment command line parameters
  131. foreach my $env (sort { $a cmp $b } grep { $RPM =~ /^\Q$_\E/ } keys %env) {
  132. while (my($opt,$val) = each %{$env{$env}}) {
  133. eval "\$opt_$opt = '$val' unless defined \$opt_$opt;";
  134. }
  135. }
  136. $RPM_PRIV = ($opt_P ? $opt_P." ".$RPM : $RPM);
  137. $RPM_NPRIV = ($opt_N ? $opt_N." ".$RPM : $RPM);
  138. $CURL = $RPM;
  139. $CURL =~ s/\/bin\/rpm$/\/lib\/openpkg\/curl/
  140. or die "FATAL: cannot deduce curl path from $RPM\n";
  141. ($PROG) = $0 =~ /(?:.*\/)?(.*)/;
  142. sub version_cmp ($$) {
  143. my($a,$b) = @_;
  144. my(@a,@b,$c);
  145. my($ax,$bx);
  146. @a = split(/\./, $a);
  147. @b = split(/\./, $b);
  148. while (@a && @b) {
  149. if ($a[0] =~ /^\d+$/ && $b[0] =~ /^\d+$/) {
  150. $c = $a[0] <=> $b[0];
  151. } elsif ((($a,$ax) = $a[0] =~ /^(\d+)(.*)$/) &&
  152. (($b,$bx) = $b[0] =~ /^(\d+)(.*)$/)) {
  153. $c = $a <=> $b;
  154. $c = $ax cmp $bx unless $c;
  155. } else {
  156. $c = $a[0] cmp $b[0];
  157. }
  158. return $c if $c;
  159. shift @a;
  160. shift @b;
  161. }
  162. $c = scalar(@a) <=> scalar(@b);
  163. return $c;
  164. }
  165. sub release_cmp ($$) {
  166. my($a,$b) = @_;
  167. return $a cmp $b;
  168. }
  169. sub vcmp ($$) {
  170. my($a,$b) = @_;
  171. my($av,$ar) = $a =~ /^(.*?)(?:\-([\d\.]+))?$/;
  172. my($bv,$br) = $b =~ /^(.*?)(?:\-([\d\.]+))?$/;
  173. my($c);
  174. if ((defined $ar) && (defined $br)) {
  175. $c = release_cmp($ar,$br);
  176. return $c if $c;
  177. }
  178. if ((defined $av) && (defined $bv)) {
  179. $c = version_cmp($av,$bv);
  180. return $c if $c;
  181. }
  182. return 0;
  183. }
  184. sub vs ($) {
  185. my($t) = @_;
  186. return "$t->{version}-$t->{release}";
  187. }
  188. sub vsn ($) {
  189. my($t) = @_;
  190. return "$t->{name}-$t->{version}-$t->{release}";
  191. }
  192. ##########################################################################
  193. sub get_config ()
  194. {
  195. my($c,@q,@g);
  196. $c = `$RPM_NPRIV --eval '%{_rpmdir} %{_rpmfilename} %{_target_os} %{_target_cpu} %{_target_platform} %{_prefix}'`;
  197. chomp($c);
  198. (@q) = split(/\s+/,$c);
  199. $q[1] =~ s/%{OS}/$q[2]/;
  200. $q[1] =~ s/%{ARCH}/$q[3]/;
  201. $c = `$RPM_NPRIV --showrc`;
  202. @g = $c =~ /\%\{l_tool_locate\s+([^\s\}]+)/g;
  203. return {
  204. rpmdir => $q[0],
  205. template => $q[1],
  206. platform => $q[4],
  207. prefix => $q[5],
  208. optreg => '(?:'.join('|', map { "\Qwith_$_\E" } @g).')'
  209. };
  210. }
  211. sub get_release () {
  212. my($rel,$url);
  213. ($rel) =`$RPM_NPRIV -qi openpkg` =~ /Version:\s*(\S+)/m;
  214. if ($rel =~ /^\d+$/) {
  215. print "# $PROG current($rel)\n";
  216. print "# using '$RPM_NPRIV' (build) and '$RPM_PRIV' (install)\n";
  217. $url = "ftp://ftp.openpkg.org/current/";
  218. } elsif ($rel =~ /^(\d+\.\d+)/) {
  219. $rel = $1;
  220. print "# $PROG release($rel)\n";
  221. $url = "ftp://ftp.openpkg.org/release/$rel/";
  222. } else {
  223. die "FATAL: don't know how to handle this release\n";
  224. }
  225. return $url;
  226. }
  227. sub get_installed () {
  228. my(%map);
  229. my(@l) = `$RPM_NPRIV --provides -qa`;
  230. foreach (@l) {
  231. /^(\S+)\s*(?:=\s*([^\s\-]+)-([^\s\+]+)(\+PROXY)?)?$/;
  232. push(@{$map{$1}->{"$2-$3"}}, {
  233. name => $1,
  234. version => (defined $2 ? $2 : '*'),
  235. release => (defined $3 ? $3 : '*'),
  236. PROXY => $4
  237. });
  238. }
  239. return \%map;
  240. }
  241. sub revdep ($$$) {
  242. my($rev,$t,$name) = @_;
  243. return 1 if $name eq $t->{name};
  244. foreach (@{$rev->{$_}}) {
  245. return 1 if revdep($rev,$t,$_->{name});
  246. }
  247. return -1;
  248. }
  249. sub get_revdep ($) {
  250. my($env) = @_;
  251. my($i) = $env->{'installed'};
  252. my($r) = $env->{'repository'};
  253. my($pkg, %rev);
  254. my(@vers,$t,@names);
  255. print "# computing reverse dependencies\n";
  256. foreach $pkg (keys %$i) {
  257. unless ($r->{$pkg}) {
  258. print "# ATTENTION: $pkg has no upgrade path\n";
  259. next;
  260. }
  261. @vers = get_versions($r->{$pkg}, sub { 1; });
  262. foreach (@vers) {
  263. foreach $t (@{$r->{$pkg}->{$_}}) {
  264. next unless $i->{$t->{name}};
  265. next unless $t->{depends};
  266. @names = grep { $_ ne '' }
  267. map { /^(\S+)/ }
  268. @{$t->{depends}};
  269. next unless @names;
  270. push @{$rev{$_}}, $t foreach @names;
  271. }
  272. }
  273. }
  274. foreach $pkg (keys %rev) {
  275. $rev{$pkg} = [
  276. sort {
  277. revdep(\%rev, $b, $a->{name});
  278. } @{$rev{$pkg}}
  279. ];
  280. }
  281. return \%rev;
  282. }
  283. sub parse_options ($) {
  284. my($l) = @_;
  285. $l = join("\n",@$l) if ref $l;
  286. return unless $l =~ s/.*Options://;
  287. my(%with) = $l =~ /--define\s*'(\S+)\s+(\S+?)'/g;
  288. return \%with;
  289. }
  290. sub override_options ($$$) {
  291. my($old, $new, $reg) = @_;
  292. while (my ($k,$v) = each %$new) {
  293. $old->{$k} = $v if exists $old->{$k} || $k =~ /^$reg$/;
  294. }
  295. }
  296. sub get_with ($;$) {
  297. my($t,$fn) = @_;
  298. my(@l,%with);
  299. unless ($t->{OPTIONS}) {
  300. if (defined $fn) {
  301. @l = `$RPM_NPRIV -qi -p $fn`;
  302. } else {
  303. @l = `$RPM_NPRIV -qi $t->{name}`;
  304. }
  305. $t->{OPTIONS} = parse_options(\@l);
  306. }
  307. return $t->{OPTIONS};
  308. }
  309. sub relurl ($$$) {
  310. my($url,$fn,$suburl) = @_;
  311. my($subfn,$submap);
  312. unless ($suburl =~ /^\w+:\/\// || $suburl =~ /^\//) {
  313. if (defined $fn) {
  314. $subfn = $fn;
  315. $subfn =~ s/\/[^\/]*$//;
  316. $subfn .= '/' unless $subfn =~ /\/$/;
  317. $subfn .= $suburl;
  318. $suburl = $subfn;
  319. } else {
  320. $subfn = $url;
  321. $subfn =~ s/\/[^\/]*$//;
  322. $subfn .= '/' unless $subfn =~ /\/$/;
  323. $suburl = "$subfn$suburl";
  324. $subfn = undef;
  325. }
  326. }
  327. return ($suburl, $subfn);
  328. }
  329. sub xel($) {
  330. my($a) = @_;
  331. my($l) = $a->[0];
  332. return '' if ref $l;
  333. return $l;
  334. }
  335. sub get_index ($$$) {
  336. my($url,$fn,$with) = @_;
  337. my($ua,$req,$res,$rdf);
  338. my($bzip2,$path);
  339. my(%map,@include);
  340. my($fetch);
  341. $fetch = defined $fn ? $fn : $url;
  342. $bzip2 = $RPM;
  343. $bzip2 =~ s/bin\/rpm$/lib\/openpkg\/bzip2/
  344. or die "FATAL: cannot deduce bzip2 path from $RPM\n";
  345. $fetch !~ /\.bz2$/ || -x $bzip2
  346. or die "FATAL: $bzip2 not found\n";
  347. if ($fetch =~ /^\w+:/) { # looks like URL scheme
  348. print "# curling index $fetch\n";
  349. if ($fetch =~ /\.bz2$/) {
  350. $path = "$CURL -q -s -o - \"$fetch\" | $bzip2 -dc |";
  351. } else {
  352. $path = "$CURL -q -s -o - \"$fetch\" |";
  353. }
  354. } else {
  355. print "# reading index file $fn\n";
  356. if ($fetch =~ /\.bz2$/) {
  357. $path = "$bzip2 -dc $fetch |";
  358. } else {
  359. $path = "< $fetch";
  360. }
  361. }
  362. open(RFH, $path) or
  363. die "FATAL: cannot open '$fetch' ($!)\n";
  364. eval {
  365. require XML::Simple;
  366. };
  367. if ($@) {
  368. print "# using simple text parser\n";
  369. my($section);
  370. my($name,$version);
  371. my($href,$release,$desc);
  372. my(@prereq,@bprereq);
  373. my(@provides,@conflicts);
  374. my($platform,$prefix);
  375. my($rec);
  376. my($tag,$cond,$body);
  377. my($useit);
  378. while (<RFH>) {
  379. s/&gt;/>/g;
  380. s/&lt;/</g;
  381. if (!(defined $href) && /<rdf:Description.*?href="([^"]*)"/) {
  382. $href = $1;
  383. $section = undef;
  384. $name = undef;
  385. $release = undef;
  386. $desc = '';
  387. $platform = undef;
  388. $prefix = undef;
  389. @prereq = ();
  390. @bprereq = ();
  391. @provides = ();
  392. @conflicts = ();
  393. }
  394. if (!(defined $href) && /<Repository.*?href="([^"]*)"/) {
  395. push(@include, $1);
  396. next;
  397. }
  398. next unless defined $href;
  399. ($tag,$cond,$body) = /<(\/?[\w:]+)\s*(?:cond="([^"]+)")?>([^<]*)/;
  400. $useit = conditional($cond,$with);
  401. if ($tag eq 'Description') {
  402. $section = 'description';
  403. } elsif ($tag eq '/Description') {
  404. $section = undef;
  405. } elsif ($section eq 'description') {
  406. $desc .= $_;
  407. } elsif ($tag eq 'PreReq') {
  408. $section = 'prereq' if $useit;
  409. } elsif ($tag eq '/PreReq') {
  410. $section = undef;
  411. } elsif ($tag eq 'BuildPreReq') {
  412. $section = 'bprereq' if $useit;
  413. } elsif ($tag eq '/BuildPreReq') {
  414. $section = undef;
  415. } elsif ($tag eq 'Provides') {
  416. $section = 'provides' if $useit;
  417. } elsif ($tag eq '/Provides') {
  418. $section = undef;
  419. } elsif ($tag eq 'Conflicts') {
  420. $section = 'conflicts' if $useit;
  421. } elsif ($tag eq '/Conflicts') {
  422. $section = undef;
  423. } elsif ($tag eq 'Name') {
  424. $name = $body;
  425. } elsif ($tag eq 'Version') {
  426. $version = $body;
  427. } elsif ($tag eq 'Release') {
  428. $release = $body;
  429. } elsif ($tag eq 'Platform') {
  430. $platform = $body;
  431. } elsif ($tag eq 'Prefixes') {
  432. $prefix = $body;
  433. } elsif ($tag eq 'rdf:li') {
  434. if ($section eq 'prereq') {
  435. push(@prereq, $body);
  436. } elsif ($section eq 'bprereq') {
  437. push(@bprereq, $body);
  438. } elsif ($section eq 'provides') {
  439. push(@provides, $body);
  440. } elsif ($section eq 'conflicts') {
  441. push(@conflicts, $body);
  442. }
  443. } elsif ($tag eq '/rdf:Description') {
  444. if (defined $href &&
  445. defined $name &&
  446. defined $version &&
  447. defined $release) {
  448. @provides = map {
  449. /(\S+)\s*(?:=\s*(\S+?)\-(\S+))?$/;
  450. {
  451. name => $1,
  452. version => $2,
  453. release => $3
  454. }
  455. } @provides;
  456. unless (grep($_->{name} eq $name, @provides)) {
  457. push(@provides, {
  458. name => $name,
  459. version => $version,
  460. release => $release
  461. });
  462. }
  463. $rec = {
  464. href => (relurl($url, undef, $href))[0],
  465. name => $name,
  466. version => $version,
  467. release => $release,
  468. depends => [ @bprereq ],
  469. keeps => [ @prereq ],
  470. conflicts => [ @conflicts ],
  471. desc => $desc,
  472. platform => $platform,
  473. prefix => $prefix
  474. };
  475. $rec->{OPTIONS} = parse_options($rec->{desc});
  476. foreach (@provides) {
  477. push(@{$map{$_->{name}}->{vs($_)}}, $rec);
  478. }
  479. }
  480. $href = undef;
  481. }
  482. }
  483. } else {
  484. print "# using XML parser\n";
  485. my($xml) = XML::Simple::XMLin(\*RFH, forcearray => 1);
  486. my($desc) = $xml->{'Repository'}->[0]->{'rdf:Description'};
  487. my($sub) = $xml->{'Repository'}->[0]->{'Repository'};
  488. my($provides,@provides,$rec);
  489. my($href,$name,$version,$release);
  490. foreach (@$desc) {
  491. $href = $_->{'href'};
  492. $name = xel($_->{'Name'});
  493. $version = xel($_->{'Version'});
  494. $release = xel($_->{'Release'});
  495. next unless defined $href &&
  496. defined $name &&
  497. defined $version &&
  498. defined $release;
  499. $provides = $_->{'Provides'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'};
  500. @provides = map {
  501. /(\S+)\s*(?:=\s*(\S+?)\-(\S+))?$/;
  502. {
  503. name => $1,
  504. version => $2,
  505. release => $3
  506. }
  507. } @$provides;
  508. unless (grep($_->{name} eq $name, @provides)) {
  509. push(@provides, {
  510. name => $name,
  511. version => $version,
  512. release => $release
  513. });
  514. }
  515. $rec = {
  516. href => (relurl($url, undef, $href))[0],
  517. name => $name,
  518. version => $version,
  519. release => $release,
  520. platform => xel($_->{'Platform'}),
  521. prefix => xel($_->{'Prefixes'}),
  522. depends =>
  523. ( $_->{'BuildPreReq'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}
  524. || [] ),
  525. keeps =>
  526. ( $_->{'PreReq'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}
  527. || [] ),
  528. conflicts =>
  529. ( $_->{'Conflicts'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}
  530. || [] ),
  531. desc => xel($_->{'Description'})
  532. };
  533. $rec->{OPTIONS} = parse_options($rec->{desc});
  534. foreach (@provides) {
  535. push(@{$map{$_->{name}}->{vs($_)}}, $rec);
  536. }
  537. }
  538. if ($sub) {
  539. @include = map { $_->{href} } @$sub;
  540. }
  541. }
  542. close(RFH)
  543. or die "FATAL: an I/O error occured\n";
  544. #
  545. # cannot do real recursions on file handles, so we simply append
  546. # all sub-RDFs, the result is flattend into a big hash anyway
  547. #
  548. foreach (@include) {
  549. my($submap);
  550. my($suburl,$subfn) = relurl($url,$fn,$_);
  551. $submap = get_index($suburl,$subfn,$with);
  552. while (my($name,$vmap) = each %$submap) {
  553. while (my($vs,$recs) = each %$vmap) {
  554. push @{$map{$name}->{$vs}}, @$recs;
  555. }
  556. }
  557. }
  558. return \%map;
  559. }
  560. #
  561. # grep all versions of a name that
  562. # satisfy a condition
  563. #
  564. sub get_versions ($$) {
  565. my($relmap, $cond) = @_;
  566. return grep { $cond->($_); }
  567. sort { vcmp($a,$b); } keys %$relmap;
  568. }
  569. #
  570. # there can be multiple sources for a target release
  571. #
  572. sub chose_source ($$@) {
  573. my($env, $name, $vmap, @vers) = @_;
  574. my(@recs,@nrecs,$rec);
  575. return unless @vers;
  576. @recs = grep {
  577. $env->{sourceonly} ? (
  578. !(defined $_->{'platform'})
  579. ) : (
  580. !(defined $_->{'platform'}) || (
  581. defined $_->{'prefix'} &&
  582. $_->{'platform'} eq $env->{config}->{platform} &&
  583. $_->{'prefix'} eq $env->{config}->{prefix}
  584. )
  585. )
  586. } map { @{$vmap->{$_}} } @vers;
  587. return unless @recs;
  588. if (scalar(@recs) > 1) {
  589. @nrecs = grep {
  590. $env->{built}->{$_->{name}} ||
  591. $env->{installed}->{$_->{name}}
  592. } @recs;
  593. @recs = @nrecs if @nrecs;
  594. }
  595. if (scalar(@recs) > 1 && !$env->{sourceonly}) {
  596. @nrecs = grep {
  597. defined $_->{'platform'}
  598. } @recs;
  599. @recs = @nrecs if @nrecs;
  600. }
  601. if (scalar(@recs) > 1) {
  602. print "# ambigous sources for $name\n";
  603. my($i) = 0;
  604. foreach (@recs) {
  605. print "# $i: ".vsn($_)." = $_->{href}\n";
  606. $i++;
  607. }
  608. return;
  609. } else {
  610. if ($env->{upgrade}) {
  611. $rec = $recs[-1];
  612. } else {
  613. $rec = $recs[0];
  614. }
  615. }
  616. print "# source for $name is ".vsn($rec)."\n";
  617. return $rec;
  618. }
  619. #
  620. # see wether target is in map
  621. #
  622. sub target_exists ($$) {
  623. my($target, $map) = @_;
  624. my($vmap) = $map->{$target->{name}};
  625. return unless $vmap;
  626. return !defined $target->{version} ||
  627. defined $vmap->{vs($target)};
  628. }
  629. #
  630. # find target in map
  631. #
  632. sub find_target ($$) {
  633. my($name, $map) = @_;
  634. my($vmap) = $map->{$name};
  635. my(@vs);
  636. return unless $vmap;
  637. @vs = sort { vcmp($b,$a) } keys %$vmap;
  638. return $vmap->{$vs[0]}->[-1];
  639. }
  640. #
  641. # see wether target has conflicts in map
  642. #
  643. sub target_conflicts ($$) {
  644. my($target, $map) = @_;
  645. my($t);
  646. foreach (@{$target->{conflicts}}) {
  647. $t = find_target($_, $map);
  648. return $t if $t;
  649. }
  650. return;
  651. }
  652. #
  653. # retrieve build dependencies for target in map
  654. #
  655. sub target_depends ($$) {
  656. my($target, $map) = @_;
  657. my($vmap,$vers);
  658. die "FATAL: ",vsn($target)," not in depend map\n"
  659. unless
  660. ( $vmap = $map->{$target->{name}} ) &&
  661. ( defined $target->{version} ) &&
  662. ( $vers = $vmap->{vs($target)} ) &&
  663. @$vers;
  664. return $vers->[0]->{depends};
  665. }
  666. #
  667. # retrieve runtime dependencies for target in map
  668. #
  669. sub target_keeps ($$) {
  670. my($target, $map) = @_;
  671. my($vmap,$vers);
  672. die "FATAL: ",vsn($target)," not in keep map\n"
  673. unless
  674. ( $vmap = $map->{$target->{name}} ) &&
  675. ( defined $target->{version} ) &&
  676. ( $vers = $vmap->{vs($target)} ) &&
  677. @$vers;
  678. return $vers->[0]->{keeps};
  679. }
  680. #
  681. # test wether target could be upgraded
  682. #
  683. sub target_newer ($$) {
  684. my($target, $map) = @_;
  685. my($vs) = vs($target);
  686. my($vmap) = $map->{$target->{name}};
  687. return 1 unless $vmap;
  688. return !grep { vcmp($vs, $_) <= 0; } keys %$vmap;
  689. }
  690. #
  691. # check wether installed package matches
  692. # build options
  693. #
  694. sub target_suitable ($$) {
  695. my($target, $with) = @_;
  696. my($iwith);
  697. my($k,$v);
  698. $iwith = $target->{OPTIONS};
  699. while (($k,$v) = each %$with) {
  700. if (exists $iwith->{$k}) {
  701. return 0 if $iwith->{$k} ne $with->{$k};
  702. }
  703. }
  704. return 1;
  705. }
  706. #
  707. # record target status
  708. #
  709. sub target_setstatus ($$$) {
  710. my($target, $status, $pri) = @_;
  711. if ($pri > $target->{STATUSPRI}) {
  712. $target->{STATUSPRI} = $pri;
  713. $target->{STATUS} = $status;
  714. }
  715. }
  716. #
  717. # report options that are not used for
  718. #
  719. sub warn_about_options ($$$) {
  720. my($target, $with, $c) = @_;
  721. my($iwith) = $target->{OPTIONS};
  722. my($k,$v);
  723. return unless defined $iwith;
  724. while (($k,$v) = each %$with) {
  725. if (!exists $iwith->{$k} && $k !~ $c->{optreg}) {
  726. print "# ATTENTION: $target->{name} ignores option '$k'\n";
  727. }
  728. }
  729. }
  730. #
  731. # locate target for a dependency
  732. #
  733. sub dep2target ($$) {
  734. my($dep, $env) = @_;
  735. my($name,@vers);
  736. my($i,$r,$b,$cond,$version);
  737. my($t);
  738. $dep =~ s/(\S+)\s*//;
  739. $name = $1;
  740. $i = $env->{installed}->{$name};
  741. $r = $env->{repository}->{$name};
  742. $b = $env->{built}->{$name};
  743. return unless $i || $r || $b;
  744. if ($dep =~ /^>=\s*(\S+)$/) {
  745. $version = $1;
  746. $cond = sub { vcmp($_[0],$version) >= 0; };
  747. } elsif ($dep =~ /^=\s*(\S+)$/) {
  748. $version = $1;
  749. $cond = sub { vcmp($_[0],$version) == 0; };
  750. } elsif ($dep =~ /^\s*$/) {
  751. $cond = sub { 1; };
  752. } else {
  753. print "# don't know how to handle PreReq: $name $dep\n";
  754. return;
  755. }
  756. if ($i && (@vers = get_versions($i, $cond))) {
  757. foreach (@vers) {
  758. $t = $i->{$_}->[0];
  759. if (get_with($t), target_suitable($t, $env->{with})) {
  760. if (!$env->{upgrade}) {
  761. return ($t, 1);
  762. }
  763. }
  764. }
  765. }
  766. if ($b && (@vers = get_versions($b, $cond))) {
  767. return ($b->{$vers[0]}->[0], 1);
  768. }
  769. return (chose_source($env, $name, $r, get_versions($r, $cond)), 0);
  770. }
  771. sub make_dep ($$$$$$) {
  772. my($target,$depth,$env,$list,$blist,$clist) = @_;
  773. my($d,$k,%d,%k,$t,$old);
  774. my(@deps,$conflict);
  775. if (target_exists($target, $env->{built})) {
  776. print "# $target->{name} is already in list\n";
  777. return;
  778. }
  779. if ($t = target_conflicts($target, $env->{installed})) {
  780. target_setstatus($target,'CONFLICT',4);
  781. push(@$clist,$target);
  782. print "# $target->{name} conflicts with ",vsn($t),"\n";
  783. return;
  784. }
  785. if ($t = target_conflicts($target, $env->{built})) {
  786. target_setstatus($target,'CONFLICT',4);
  787. push(@$clist,$target);
  788. print "# $target->{name} conflicts with ",vsn($t),"\n";
  789. return;
  790. }
  791. #
  792. # see if a target is already installed and requires a rebuild
  793. #
  794. if ($t = find_target($target->{name}, $env->{installed})) {
  795. if (exists $env->{exclude}->{$target->{name}}) {
  796. print "# excluding $target->{name} (no upgrade allowed)\n";
  797. return;
  798. }
  799. get_with($t);
  800. if ($target->{REBUILD}) {
  801. target_setstatus($target,'DEPEND',1);
  802. print "# rebuilding $target->{name} (dependency)\n";
  803. } elsif ($env->{zero}) {
  804. target_setstatus($target,'ZERO',1);
  805. print "# rebuilding $target->{name} (zero)\n";
  806. } elsif (target_newer($target, $env->{installed})) {
  807. target_setstatus($target,'UPGRADE',3);
  808. print "# rebuilding $target->{name} (upgrade)\n";
  809. } elsif (!target_suitable($t, $env->{with})) {
  810. target_setstatus($target,'MISMATCH',2);
  811. print "# rebuilding $target->{name} (parameter mismatch)\n";
  812. } else {
  813. print "# $target->{name} is already installed\n";
  814. return;
  815. }
  816. # use options from installed base
  817. override_options($target->{OPTIONS}, $t->{OPTIONS},
  818. $env->{config}->{optreg});
  819. # remember this is a rebuild for a proxy package
  820. $target->{PROXY} = $t->{PROXY};
  821. $target->{REBUILD} = 1;
  822. } else {
  823. target_setstatus($target,'ADD',3);
  824. }
  825. if (exists $env->{exclude}->{$target->{name}}) {
  826. die "FATAL: target ".vsn($target)." is forbidden\n";
  827. }
  828. # mark this as a target before reverse dependencies trigger
  829. # it again
  830. push(@{$env->{built}->{$target->{name}}->{vs($target)}}, $target);
  831. $d = target_depends($target, $env->{repository});
  832. $k = target_keeps($target, $env->{repository});
  833. #
  834. # recurse over dependencies
  835. #
  836. if (@$d || @$k) {
  837. %d = map { $_ => 1 } @$d, @$k;
  838. %k = map { $_ => 1 } @$k;
  839. @deps = ();
  840. $conflict = 0;
  841. foreach (keys %d) {
  842. # old index misses a OpenPKG provider in the index... skip it
  843. next if $_ eq 'OpenPKG';
  844. ($t,$old) = dep2target($_, $env);
  845. if ($t) {
  846. if ($old) {
  847. print "# $target->{name} uses ".vsn($t)." for $_\n";
  848. next;
  849. }
  850. # record which targets to keep in blist
  851. if ($k{$_}) {
  852. push @$blist,$t;
  853. print "# $target->{name} installs ".vsn($t)." for $_\n";
  854. } else {
  855. print "# $target->{name} requires ".vsn($t)." for $_\n";
  856. }
  857. push @deps, $t;
  858. } else {
  859. print "# $target->{name} searches for a frood called '$_'\n";
  860. push(@{$env->{fatal}},vsn($target));
  861. target_setstatus($target,'UNDEF',4);
  862. push @$clist, $target;
  863. $conflict = 1;
  864. }
  865. }
  866. unless ($conflict) {
  867. foreach $t (@deps) {
  868. make_dep($t,$depth+1,$env,$list,$blist,$clist);
  869. }
  870. }
  871. }
  872. print "# adding ".vsn($target)." to list\n";
  873. push(@$list, $target);
  874. return if $conflict;
  875. if (!$env->{quick} &&
  876. $target->{name} ne 'openpkg' &&
  877. $target->{REBUILD}) {
  878. unless ($env->{revdep}) {
  879. $env->{revdep} = get_revdep($env);
  880. }
  881. foreach $t (@{$env->{revdep}->{$target->{name}}}) {
  882. # this is a rebuild, triggering further revdeps
  883. $t->{REBUILD} = 1;
  884. # this is a rebuild, keep this installed
  885. push(@$blist, $t);
  886. print "# rebuilding revdep ".vsn($t)."\n";
  887. make_dep($t,$depth+1,$env,$list,$blist,$clist);
  888. }
  889. }
  890. }
  891. sub remove_list ($$$) {
  892. my($targets, $keeps, $installed) = @_;
  893. my(%keep);
  894. %keep = map { $_ => 1 } @$keeps;
  895. return [ grep {
  896. !$keep{$_} && !$installed->{$_->{name}}->{vs($_)};
  897. } @$targets
  898. ];
  899. }
  900. sub build_list ($$) {
  901. my($pattern, $env) = @_;
  902. my(@goals,@targets,@keeps,@conflicts,$bonly,$t);
  903. my($name,$r,$i,@vers);
  904. my(@todo);
  905. if (defined $pattern) {
  906. @todo = ();
  907. foreach (split(/\s+/,$pattern)) {
  908. next unless /\S/;
  909. if (s/\*+$//) {
  910. push @todo, '^'.quotemeta($_).'';
  911. } else {
  912. push @todo, '^'.quotemeta($_).'$';
  913. }
  914. }
  915. $pattern = join('|',@todo);
  916. @todo = grep(/$pattern/, keys %{$env->{repository}});
  917. } else {
  918. @todo = grep {
  919. my($n) = $_;
  920. (ref $env->{installed}->{$n}) &&
  921. grep { $_ ne '-' } keys %{$env->{installed}->{$n}}
  922. } keys %{$env->{repository}};
  923. }
  924. #
  925. # chose sources for goals from repository
  926. #
  927. foreach $name (@todo) {
  928. $t = undef;
  929. #
  930. # keeping installed packages for goals is ugly
  931. # -> we currently do not support installed source RPMs
  932. # -> source RPMs might already have expired from repository
  933. #
  934. # consequence:
  935. # -> goals are always upgraded to repository versions
  936. #
  937. #unless ($env->{upgrade}) {
  938. # $i = $env->{installed}->{$name};
  939. # if (@vers = get_versions($i, sub { 1; })) {
  940. # $t = chose_source($env, $name, $i, @vers);
  941. # }
  942. #}
  943. unless ($t) {
  944. $r = $env->{repository}->{$name};
  945. if (@vers = get_versions($r, sub { 1; })) {
  946. $t = chose_source($env, $name, $r, @vers);
  947. }
  948. }
  949. if ($t) {
  950. warn_about_options($t, $env->{with}, $env->{config});
  951. push(@goals, $t);
  952. } else {
  953. if ($env->{status}) {
  954. print "# dropping goal '$name'\n";
  955. } else {
  956. die "FATAL: cannot find source for '$name'\n";
  957. }
  958. }
  959. }
  960. return unless @goals;
  961. @targets = ();
  962. @keeps = @goals;
  963. foreach $t (@goals) {
  964. print "# recursing over dependencies for ".vsn($t)."\n";
  965. make_dep($t,0,$env,\@targets,\@keeps,\@conflicts);
  966. }
  967. $bonly = remove_list(\@targets, \@keeps, $env->{installed});
  968. return (\@targets, $bonly, \@conflicts);
  969. }
  970. #######################################################################
  971. sub target2rpm ($$) {
  972. my($target,$c) = @_;
  973. my($tmpl) = $c->{template};
  974. my($popt) = $target->{PROXY} ? '+PROXY' : '';
  975. $tmpl =~ s/%{NAME}/$target->{name}/;
  976. $tmpl =~ s/%{VERSION}/$target->{version}/;
  977. $tmpl =~ s/%{RELEASE}/$target->{release}$popt/;
  978. return $c->{rpmdir}.'/'.$tmpl;
  979. }
  980. #######################################################################
  981. sub binary_target ($$) {
  982. my($t, $fn) = @_;
  983. my(%target) = %$t;
  984. get_with(\%target, $fn);
  985. return \%target;
  986. }
  987. sub find_proxy ($$) {
  988. my($t,$bpkg) = @_;
  989. my(@l) = `$RPM_NPRIV -ql $t->{name}`;
  990. my($link) = (grep { $_ =~ /\/\.prefix-$t->{name}$/ } @l)[0];
  991. return unless defined $link;
  992. chomp $link;
  993. my($prefix) = readlink($link);
  994. return unless defined $prefix;
  995. $bpkg =~ s/.*\///;
  996. $bpkg =~ s/(\.[^-]+-[^-]+)+PROXY-[^-]+\.rpm$/$1-*.rpm/;
  997. return (glob("$prefix/RPM/PKG/$bpkg"))[0];
  998. }
  999. sub make_defines ($$$) {
  1000. my($old, $new, $c) = @_;
  1001. my($with);
  1002. #
  1003. # override old parameters with new parameters
  1004. # drop new parameters that do not exist in old set
  1005. #
  1006. # if there is no old set at all (which happens if there
  1007. # is no template and no installed package), just use the
  1008. # new parameters and assume these are useful.
  1009. #
  1010. if ($old) {
  1011. $old = { %$old };
  1012. override_options($old, $new, $c->{optreg});
  1013. } else {
  1014. $old = $new;
  1015. }
  1016. #
  1017. # convert parameters to --define command line options
  1018. # skip parameter templates from index
  1019. #
  1020. $with = join(' ',map { "--define '$_ $old->{$_}'" }
  1021. grep { $old->{$_} !~ /^%/ } keys %$old);
  1022. $with = ' '.$with if $with ne '';
  1023. return $with;
  1024. }
  1025. sub print_list1 ($$$@$) {
  1026. my($list,$c,$uncond,$with,$ignore) = @_;
  1027. my($spkg,$bpkg,$ppkg);
  1028. my($opt);
  1029. my($cmd1, $cmd2, $mark);
  1030. $mark = '::::';
  1031. foreach (@$list) {
  1032. $spkg = $_->{href};
  1033. $bpkg = target2rpm($_, $c);
  1034. #
  1035. # rebuild binary package IF
  1036. #
  1037. # 'unconditional' option
  1038. # OR there is no binary package
  1039. # OR dependency check found that installed package is not suitable
  1040. # OR existing binary package doesn't satisfy wanted options
  1041. #
  1042. $cmd1 = undef;
  1043. if ($uncond || !-f $bpkg || $_->{REBUILD} ||
  1044. !target_suitable(binary_target($_, $bpkg),$with)) {
  1045. $opt = make_defines($_->{OPTIONS}, $with, $c);
  1046. #
  1047. # proxy packages are rebuilt from their maste
  1048. # hierachy
  1049. #
  1050. # someone preferred a binary from the repository
  1051. # just copy it to the local store
  1052. #
  1053. if ($_->{PROXY}) {
  1054. $ppkg = find_proxy($_,$bpkg) or
  1055. die "FATAL: proxy package ",vsn($_)," does not exist\n";
  1056. #
  1057. # rpm doesn't support additional parameters to the
  1058. # mkproxy script
  1059. # $cmd1 = "$RPM_NPRIV$opt --makeproxy $ppkg -- -o $bpkg";
  1060. #
  1061. $cmd1 = "( cd $c->{rpmdir} && $RPM_NPRIV$opt --makeproxy $ppkg )";
  1062. } elsif (defined $_->{platform}) {
  1063. $cmd1 = "$CURL -q -s -o $bpkg $spkg";
  1064. } else {
  1065. $cmd1 = "$RPM_NPRIV$opt --rebuild $spkg";
  1066. }
  1067. }
  1068. #
  1069. # if package exist force rpm to copy over new files
  1070. # better than erasing everything and losing configuration
  1071. # files
  1072. #
  1073. $opt = $_->{REBUILD} ? ' --force' : '';
  1074. $cmd2 = "$RPM_PRIV$opt -Uvh $bpkg";
  1075. if ($ignore) {
  1076. $cmd2 = "$cmd1 && \\\n$cmd2" if defined $cmd1;
  1077. } else {
  1078. if (defined $cmd1) {
  1079. $cmd2 = "$cmd1 || exit \$?\n$cmd2 || exit \$?"
  1080. } else {
  1081. $cmd2 = "$cmd2 || exit \$?";
  1082. }
  1083. }
  1084. print "echo $mark $spkg $mark\n$cmd2\necho $mark $spkg = \$? $mark\n";
  1085. }
  1086. }
  1087. sub print_list2 ($$) {
  1088. my($list,$c) = @_;
  1089. my($pkg);
  1090. foreach (@$list) {
  1091. $pkg = "$_->{name}-$_->{version}-$_->{release}";
  1092. print "$RPM_PRIV -e $pkg\n";
  1093. }
  1094. }
  1095. sub print_status ($$$$$) {
  1096. my($installed,$repository,$list,$bonly,$clist) = @_;
  1097. my(%bonly) = map { $_ => 1 } @$bonly;
  1098. my(%map,$n,@names,$t);
  1099. my($old,$tag,$new);
  1100. foreach (@$list, @$clist) {
  1101. $map{$_->{name}} = {
  1102. rel => "$_->{version}-$_->{release}",
  1103. status => $_->{STATUS}
  1104. };
  1105. }
  1106. foreach (@$bonly) {
  1107. $map{$_->{name}} = {
  1108. rel => "$_->{version}-$_->{release}",
  1109. status => 'TEMP'
  1110. };
  1111. }
  1112. @names = keys %map;
  1113. foreach $n (keys %$installed) {
  1114. next if exists $map{$n};
  1115. next unless grep { $_ ne '-' } keys %{$installed->{$n}};
  1116. $map{$n}->{'status'} = 'OK';
  1117. push @names,$n;
  1118. }
  1119. foreach $n (keys %$repository) {
  1120. next if exists $map{$n};
  1121. next unless grep { $_ ne '-' } keys %{$repository->{$n}};
  1122. $t = find_target($n, $repository);
  1123. $map{$n}->{'status'} = 'NEW';
  1124. $map{$n}->{'rel'} = vs($t);
  1125. push @names,$n;
  1126. }
  1127. foreach $n (sort @names) {
  1128. $old = join ',',
  1129. map { "$n-$_" }
  1130. sort
  1131. grep { $_ ne '-' }
  1132. keys %{$installed->{$n}};
  1133. $old = $n if $old eq '';
  1134. $tag = $map{$n}->{status};
  1135. $new = defined $map{$n}->{rel} ? " $n-$map{$n}->{rel}" : '';
  1136. printf "%-35s %-8s%s\n", $old, $tag, $new;
  1137. }
  1138. }
  1139. #######################################################################
  1140. my($config,$url,$repository,$installed,$env,$list,$bonly,$clist);
  1141. my($pattern,%with,%exclude);
  1142. if ($opt_a) {
  1143. $pattern = undef;
  1144. } else {
  1145. $pattern = join(' ', @ARGV);
  1146. }
  1147. if ($opt_A) {
  1148. $pattern = '*';
  1149. }
  1150. %with = map {
  1151. /([^\s=]+)(?:\=(\S+))?/
  1152. ? ($1 => (defined $2 ? $2 : 'yes'))
  1153. : ()
  1154. } split(/\s+/, $opt_D);
  1155. %exclude = map { $_ => 1 } split(/\s+/, $opt_E);
  1156. $config = get_config();
  1157. if (defined $opt_p) {
  1158. $config->{platform} = $opt_p;
  1159. }
  1160. if (defined $opt_r) {
  1161. $url = $opt_r;
  1162. $url .= '/' unless $url =~ /\/$/;
  1163. } else {
  1164. $url = get_release();
  1165. }
  1166. #
  1167. # if we read the index from a file we can no longer deduce
  1168. # repository paths from index paths. For now lets assume
  1169. # that everything is below SRC/ to be compatible with
  1170. # existing file indexes.
  1171. #
  1172. if (defined $opt_f && !defined $opt_r) {
  1173. $url .= 'SRC/';
  1174. }
  1175. $installed = $opt_Z ? {} : get_installed();
  1176. $repository = get_index($url.'00INDEX.rdf',$opt_f,\%with);
  1177. $env = {
  1178. config => $config,
  1179. installed => $installed,
  1180. repository => $repository,
  1181. built => {},
  1182. revdep => undef,
  1183. with => \%with,
  1184. exclude => \%exclude,
  1185. upgrade => ($opt_a || $opt_U),
  1186. zero => ($opt_z || $opt_Z),
  1187. quick => $opt_q,
  1188. status => ($opt_s || $opt_S),
  1189. fatal => [],
  1190. sourceonly => ($opt_u ||
  1191. $opt_U ||
  1192. $opt_z ||
  1193. $opt_Z ||
  1194. scalar(%with) > 0 )
  1195. };
  1196. ($list,$bonly,$clist) = build_list($pattern, $env);
  1197. die "FATAL: cannot find package\n" unless defined $list;
  1198. if ($opt_S) {
  1199. print_status($installed,$repository,$list,$bonly,$clist);
  1200. } elsif ($opt_s) {
  1201. print_status($installed,{},$list,$bonly,$clist);
  1202. } else {
  1203. if (@{$env->{fatal}}) {
  1204. die "FATAL errors occured while building:\n",
  1205. join ',',
  1206. @{$env->{fatal}},
  1207. "\n";
  1208. }
  1209. print_list1($list,$config,$opt_a || $opt_u || $opt_U,\%with,$opt_i);
  1210. print_list2($bonly,$config);
  1211. }