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: 21-Nov-2002 10:45:49 Branch: HEAD Handle: 2002112109454900 Modified files: openpkg-re openpkg-build Log: code cleanup Summary: Revision Changes Path 1.39 +73 -45 openpkg-re/openpkg-build ____________________________________________________________________________ Index: openpkg-re/openpkg-build ============================================================ $ cvs diff -u -r1.38 -r1.39 openpkg-build --- openpkg-re/openpkg-build 20 Nov 2002 16:38:44 -0000 1.38 +++ openpkg-re/openpkg-build 21 Nov 2002 09:45:49 -0000 1.39 @@ -322,23 +322,33 @@ return \%rev; } +sub parse_options ($) { + my($l) = @_; + $l = [ split(/\n+/, $l) ] unless ref $l; + my(%with) = map { /--define\s*'(\S+)\s+(\S+?)'/ } @$l; + return \%with; +} + +sub override_options ($$) { + my($old, $new) = @_; + while (my ($k,$v) = each %$new) { + $old->{$k} = $v if exists $old->{$k}; + } +} + sub get_with ($;$) { my($t,$fn) = @_; my(@l,%with); - if (defined $fn) { - @l = `$RPM_NPRIV -qi -p $fn`; - } else { - @l = `$RPM_NPRIV -qi $t->{name}`; - } - - if (scalar(@l) == 0 && exists $t->{desc}) { - @l = split(/\n+/, $t->{desc}); + unless ($t->{OPTIONS}) { + if (defined $fn) { + @l = `$RPM_NPRIV -qi -p $fn`; + } else { + @l = `$RPM_NPRIV -qi $t->{name}`; + } + $t->{OPTIONS} = parse_options(\@l); } - - %with = map { /--define\s*'(\S+)\s+(\S+?)'/ } @l; - - return \%with; + return $t->{OPTIONS}; } sub get_index ($$$) { @@ -479,6 +489,7 @@ href => $href, desc => $desc }; + $rec->{OPTIONS} = parse_options($rec->{desc}); foreach (@provides) { push(@{$map{$_->{name}}->{vs($_)}}, $rec); @@ -516,8 +527,9 @@ depends => $_->{'BuildPreReq'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}, keeps => $_->{'PreReq'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}, href => $_->{'href'}, - desc => $_->{'Description'}->[0] + desc => $_->{'Description'}->[0], }; + $rec->{OPTIONS} = parse_options($rec->{desc}); foreach (@provides) { push(@{$map{$_->{name}}->{vs($_)}}, $rec); @@ -600,17 +612,30 @@ } # +# find target in map +# +sub find_target ($$) { + my($name, $map) = @_; + my($vmap) = $map->{$name}; + my(@vs); + + return unless $vmap; + + @vs = sort { vcmp($b,$a) } keys %$vmap; + return $vmap->{$vs[0]}->[-1]; +} + +# # see wether target has conflicts in map # sub target_conflicts ($$) { my($target, $map) = @_; - my(@c,@vs); - @c = grep { $map->{$_} } @{$target->{conflicts}}; - return unless @c; + foreach (@{$target->{conflicts}}) { + return 1 if find_target($_, $map); + } - @vs = sort { -vcmp($a,$b) } keys %{$map->{$c[0]}}; - return $map->{$c[0]}->{$vs[0]}->[0]; + return 0; } # @@ -669,11 +694,7 @@ my($iwith); my($k,$v); - unless ($target->{OPTIONS}) { - $target->{OPTIONS} = get_with($target); - } $iwith = $target->{OPTIONS}; - while (($k,$v) = each %$with) { if (exists $iwith->{$k}) { return 0 if $iwith->{$k} ne $with->{$k}; @@ -688,14 +709,9 @@ # sub warn_about_options ($$) { my($target, $with) = @_; - my($iwith); + my($iwith) = $target->{OPTIONS}; my($k,$v); - unless ($target->{OPTIONS}) { - $target->{OPTIONS} = get_with($target); - } - $iwith = $target->{OPTIONS}; - while (($k,$v) = each %$with) { if (!exists $iwith->{$k}) { print "# ATTENTION: $target->{name} ignores option '$k'\n"; @@ -710,6 +726,7 @@ my($dep, $env) = @_; my($name,@vers); my($i,$r,$b,$cond); + my($t); $dep =~ s/(\S+)\s*//; $name = $1; @@ -732,9 +749,10 @@ if ($i && (@vers = get_versions($i, $cond))) { foreach (@vers) { - if (target_suitable($i->{$_}->[0], $env->{with})) { + $t = $i->{$_}->[0]; + if (get_with($t), target_suitable($t, $env->{with})) { if (!$env->{upgrade}) { - return ($i->{$_}->[0], 1); + return ($t, 1); } } } @@ -769,22 +787,27 @@ # # see if a target is already installed and requires a rebuild # - if ($env->{installed}->{$target->{name}}) { + $t = find_target($target->{name}, $env->{installed}); + if ($t) { if (exists $env->{exclude}->{$target->{name}}) { print "# excluding $target->{name} (no upgrade allowed)\n"; return; - } elsif ($target->{REBUILD}) { + } + get_with($t); + if ($target->{REBUILD}) { print "# rebuilding $target->{name} (dependency)\n"; } elsif ($env->{zero}) { print "# rebuilding $target->{name} (zero)\n"; } elsif ($env->{upgrade} && target_newer($target, $env->{installed})) { print "# rebuilding $target->{name} (upgrade)\n"; - } elsif (!target_suitable($target, $env->{with})) { + } elsif (!target_suitable($t, $env->{with})) { print "# rebuilding $target->{name} (parameter mismatch)\n"; } else { print "# $target->{name} is already installed\n"; return; } + # use options from installed base + override_options($target->{OPTIONS}, $t->{OPTIONS}); $target->{REBUILD} = 1; } @@ -960,32 +983,37 @@ my($t, $fn) = @_; my(%target) = %$t; - $target{OPTIONS} = get_with($t, $fn); + get_with(\%target, $fn); return \%target; } sub make_defines ($$) { my($old, $new) = @_; - my(%result); - my($k,$v); my($with); + # + # override old parameters with new parameters + # drop new parameters that do not exist in old set + # + # if there is no old set at all (which happens if there + # is no template and no installed package), just use the + # new parameters and assume these are useful. + # if ($old) { $old = { %$old }; - while (($k,$v) = each %$new) { - $old->{$k} = $v if exists $old->{$k}; - } - $old = { - map { $_ => $old->{$_} } - grep { $old->{$_} !~ /\%/ } - keys %$old - }; + override_options($old, $new); } else { $old = $new; } - $with = join(' ',map { "--define '$_ $old->{$_}'" } keys %$old); + # + # convert parameters to --define command line options + # skip parameter templates from index + # + $with = join(' ',map { "--define '$_ $old->{$_}'" } + grep { $old->{$_} !~ /^%/ } keys %$old); + $with = ' '.$with if $with ne ''; return $with; ______________________________________________________________________ The OpenPKG Project www.openpkg.org CVS Repository Commit List [EMAIL PROTECTED]