OpenPKG CVS Repository http://cvs.openpkg.org/ ____________________________________________________________________________
Server: cvs.openpkg.org Name: Michael van Elst Root: /e/openpkg/cvs Email: [EMAIL PROTECTED] Module: openpkg-re Date: 12-Nov-2002 16:33:05 Branch: HEAD Handle: 2002111215330500 Modified files: openpkg-re openpkg-build Log: support option upgrades Summary: Revision Changes Path 1.5 +65 -24 openpkg-re/openpkg-build ____________________________________________________________________________ Index: openpkg-re/openpkg-build ============================================================ $ cvs diff -u -r1.4 -r1.5 openpkg-build --- openpkg-re/openpkg-build 12 Nov 2002 14:36:14 -0000 1.4 +++ openpkg-re/openpkg-build 12 Nov 2002 15:33:05 -0000 1.5 @@ -53,7 +53,6 @@ sub conditional ($$) { my($cond,$with) = @_; - my(%with) = map { $_ => 1 } @$with; my(@s,$res); return 1 if $cond eq ''; @@ -74,7 +73,7 @@ my($a) = pop @s; push @s, !$a; } else { - push @s, $with{$_} + 0; + push @s, $with->{$_} eq 'yes'; } } die "FATAL: stack underflow in: $cond\n" if scalar(@s)<1; @@ -173,6 +172,16 @@ return \%map; } +sub get_with ($) { + my($pkg) = @_; + my(@l) = `$RPM -qi $pkg`; + my(%with); + + %with = map { /--define\s*'(\S+)\s+(\S+?)'/ } @l; + + return \%with; +} + sub spawn ($@) { my($source,@argv) = @_; my($pid); @@ -206,8 +215,8 @@ return $pid; } -sub get_index ($$@) { - my($url,$fn,@with) = @_; +sub get_index ($$$) { + my($url,$fn,$with) = @_; my($ua,$req,$res,$rdf); my($pid); my(%map); @@ -284,7 +293,7 @@ ($tag,$cond,$body) = /<(\/?[\w:]+)\s*(?:cond="([^"]+)")?>([^<]*)/; next unless $tag; - $useit = conditional($cond,\@with); + $useit = conditional($cond,$with); if ($tag eq 'PreReq') { $section = 'prereq' if $useit; @@ -468,6 +477,24 @@ } # +# check wether installed package matches +# build options +# +sub target_suitable ($$) { + my($target, $with) = @_; + my($iwith) = get_with($target->{'name'}); + my($k,$v); + + while (($k,$v) = each %$with) { + if (exists $iwith->{$k}) { + return 0 if $iwith->{$k} ne $with->{$k} + } + } + + return 1; +} + +# # locate target for a dependency # sub dep2target ($$) { @@ -495,7 +522,11 @@ } if ($i && (@vers = get_versions($i, $cond))) { - return ($i->{$vers[0]}->[0], 1); + foreach (@vers) { + if (target_suitable($i->{$_}->[0], $env->{with})) { + return ($i->{$_}->[0], 1); + } + } } if ($b && (@vers = get_versions($b, $cond))) { return ($b->{$vers[0]}->[0], 1); @@ -509,14 +540,20 @@ my($target,$depth,$env,$list,$blist) = @_; my($d,$k,%d,%k,$t,$old); - if (target_exists($target, $env->{installed})) { - print "# $target->{name} is already installed\n"; - return; - } elsif (target_exists($target, $env->{built})) { + if (target_exists($target, $env->{built})) { print "# $target->{name} is already in list\n"; return; } + if (target_exists($target, $env->{installed})) { + if (target_suitable($target, $env->{with})) { + print "# $target->{name} is already installed\n"; + return; + } + print "# rebuilding $target->{name}\n"; + $target->{REBUILD} = 1; + } + $d = target_depends($target, $env->{repository}); $k = target_keeps($target, $env->{repository}); @@ -568,7 +605,7 @@ } sub build_list ($$) { - my($env, $pattern) = @_; + my($pattern, $env) = @_; my(@goals,@targets,@keeps,$bonly,$t); my($name,$r,@vers); @@ -617,19 +654,18 @@ ####################################################################### sub print_list1 ($$$$@) { - my($list,$c,$url,$uncond,@with) = @_; - my($spkg,$bpkg,$with); + my($list,$c,$url,$uncond,$with) = @_; + my($spkg,$bpkg); $url .= '/' unless $url =~ m{/$}s; - if (@with) { - $with = ' '.join(' ',map { "--define '$_ yes'" } @with); - } + $with = join(' ',map { "--define '$_ $with->{$_}'" } keys %$with); + $with = ' '.$with if $with ne ''; foreach (@$list) { $spkg = $_->{href}; $bpkg = target2rpm($_, $c); - if ($uncond || !-f $bpkg) { + if ($uncond || $_->{REBUILD} || !-f $bpkg) { print "$RPM$with --rebuild $url$spkg || exit 1\n"; } print "$RPM -Uvh $bpkg\n"; @@ -649,10 +685,14 @@ ####################################################################### my($config,$url,$repository,$installed,$list,$bonly); -my($pattern,@with); +my($pattern,%with); $pattern = shift @ARGV; -@with = map { "with_$_" } @ARGV; +%with = map { + /([^\s=]+)(?:\=(\S+))?/ + ? ($1 => (defined $2 ? $2 : 'yes')) + : () + } @ARGV; $config = get_config(); @@ -664,16 +704,17 @@ } $installed = get_installed(); -$repository = get_index($url,$opt_f,@with); +$repository = get_index($url,$opt_f,\%with); -($list,$bonly) = build_list({ +($list,$bonly) = build_list($pattern, { installed => $installed, repository => $repository, - built => {} - }, $pattern); + built => {}, + with => \%with + }); die "FATAL: cannot find package\n" unless defined $list; -print_list1($list,$config,$url,$opt_u,@with); +print_list1($list,$config,$url,$opt_u,\%with); print_list2($bonly,$config); ______________________________________________________________________ The OpenPKG Project www.openpkg.org CVS Repository Commit List [EMAIL PROTECTED]