openpkg-build.pl 39 KB

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