diff options
author | J Pipkin <j@dawnrazor.net> | 2013-01-03 04:18:43 -0600 |
---|---|---|
committer | J Pipkin <j@dawnrazor.net> | 2013-01-03 04:18:43 -0600 |
commit | 522ac347881d78ee9ec26a537a1c24b6805d1154 (patch) | |
tree | 7e40f8b52caeff8264ae4fc485fd45d3f9ae8368 | |
parent | 822555d7e43653eb5a9b2c122a30e33af41c844b (diff) | |
parent | 9951755ab247dccf531b6c077abb0ee6f779294a (diff) | |
download | sbotools2-522ac347881d78ee9ec26a537a1c24b6805d1154.tar.xz |
merged c32_x64_fix, fixes #25
-rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 58 | ||||
-rwxr-xr-x | sboupgrade | 7 | ||||
-rwxr-xr-x | t/test.t | 57 |
3 files changed, 106 insertions, 16 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index fe21cd7..e06f124 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -448,11 +448,45 @@ sub check_multilib() { return; } +# given a list of downloads, return just the filenames +sub get_dl_fns($) { + my $fns = shift; + my $return; + push @$return, ($_ =~ qr|/([^/]+)$|)[0] for @$fns; + return $return; +} + +# given a line that looks like it's decompressing something, try to return a +# valid filename regex +sub get_dc_regex { + my $line = shift; + # get rid of initial 'tar x'whatever stuff + $line =~ s/^.*(?<![a-z])(tar|p7zip|unzip|ar|rpm2cpio|sh)\s+[^\s]+\s+//; + # need to know preceeding character - should be safe to assume it's either + # a slash or a space + my $initial = $line =~ qr|/| ? '/' : ' '; + # get rid of initial path info + $line =~ s|^\$[^/]+/||; + # convert any instances of command substitution to [^-]+ + $line =~ s/\$\([^)]+\)/[^-]+/g; + # convert any bash variables to [^-]+ + $line =~ s/\$({|)[A-Za-z0-9_]+(}|)/[^-]+/g; + # get rid of anything excess at the end + $line =~ s/\s+.*$//; + # fix .?z* at the end + $line =~ s/\.\?z\*/\.[a-z]z.*/; + # return what's left as a regex + my $regex = qr/$initial$line/; + return $regex, $initial; +} + # make a backup of the existent SlackBuild, and rewrite the original as needed sub rewrite_slackbuild { my %args = ( + SBO => '', SLACKBUILD => '', CHANGES => {}, + C32 => 0, @_ ); $args{SLACKBUILD} or script_error 'rewrite_slackbuild requires SLACKBUILD.'; @@ -462,8 +496,28 @@ sub rewrite_slackbuild { die "Unable to backup $slackbuild to $slackbuild.orig\n"; my $libdir_regex = qr/^\s*LIBDIRSUFFIX="64"\s*$/; my $arch_regex = qr/\$VERSION-\$ARCH-\$BUILD/; + my $dc_regex = qr/(?<![a-z])(tar|p7zip|unzip|ar|rpm2cpio|sh)\s+/; # tie the slackbuild, because this is the easiest way to handle this. tie my @sb_file, 'Tie::File', $slackbuild; + # if we're dealing with a compat32, we need to change the tar line(s) so + # that the 32-bit source is untarred + if ($args{C32}) { + my $location = get_sbo_location($args{SBO}); + my %downloads = get_sbo_downloads( + LOCATION => $location, + 32 => 1, + ); + my $fns = get_dl_fns [keys %downloads]; + for my $line (@sb_file) { + if ($line =~ $dc_regex) { + my ($regex, $initial) = get_dc_regex $line; + for my $fn (@$fns) { + $fn = "$initial$fn"; + $line =~ s/$regex/$fn/ if $fn =~ $regex; + } + } + } + } for my $line (@sb_file) { # then check for and apply any other %$changes if (exists $$changes{libdirsuffix}) { @@ -599,8 +653,10 @@ sub perform_sbo { my $fn = get_tmp_extfn $tempfh; $cmd .= " | tee -a $fn"; rewrite_slackbuild( + SBO => $sbo, SLACKBUILD => "$location/$sbo.SlackBuild", CHANGES => \%changes, + C32 => $args{C32}, ); chdir $location, system $cmd; seek $exit_temp, 0, 0; @@ -793,4 +849,4 @@ sub get_readme_contents($) { my $readme = do {local $/; <$fh>}; close $fh; return $readme; -}
\ No newline at end of file +} @@ -88,6 +88,7 @@ if ($jobs) { if ($compat32) { die "compat32 only works on x86_64.\n" unless get_arch eq 'x86_64'; + die "-p|--compat32 requires -N|--installnew\n" unless $install_new; } # if we can't find SLACKBUILDS.TXT in $config{HOME}, prompt to fetch the tree @@ -114,12 +115,6 @@ for my $sbo (@$build_queue) { defined $locations{$sbo}; } -sub get_readme_path($) { - exists $_[0] or script_error 'get_readme_path requires an argument.'; - my $sbo = shift; - return $locations{$sbo} .'/README'; -} - # look for any (user|group)add commands in the README sub get_user_group($) { exists $_[0] or script_error 'get_user_group requires an argument'; @@ -204,7 +204,7 @@ is(get_distfile '5434f948fdea6406851c77bebbd0ed19'), 1, 'get_distfile is good'); unlink $distfile; -# rewrite_slackbuilds/revert_slackbuild tests +# rewrite_slackbuild/revert_slackbuild tests my $rewrite_dir = tempdir(CLEANUP => 1); copy("$sbo_home/system/ifuse/ifuse.SlackBuild", $rewrite_dir); my $slackbuild = "$rewrite_dir/ifuse.SlackBuild"; @@ -218,18 +218,22 @@ is(revert_slackbuild $slackbuild, 1, 'revert_slackbuild is good'); $changes{libdirsuffix} = ''; $changes{make} = '-j 5'; $changes{arch_out} = 'i486'; -is(rewrite_slackbuild (SLACKBUILD => $slackbuild, TEMPFN => $tempfn, - CHANGES => \%changes), 1, 'rewrite_slackbuild with all %changes good'); +is(rewrite_slackbuild (SLACKBUILD => $slackbuild, CHANGES => \%changes, + C32 => 1, SBO => 'ifuse'), 1, 'rewrite_slackbuild test w/ all %changes'); ok(-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.'); -my $expected_out = "55c55 -< LIBDIRSUFFIX=\"64\" +my $expected_out = '55c55 +< LIBDIRSUFFIX="64" +--- +> LIBDIRSUFFIX="" +67c67 +< tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2 --- -> LIBDIRSUFFIX=\"\" +> tar xvf $CWD/ifuse-1.1.1.tar.bz2 103c103 -< /sbin/makepkg -l y -c n \$OUTPUT/\$PRGNAM-\$VERSION-\$ARCH-\$BUILD\$TAG.\${PKGTYPE:-tgz} +< /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} --- -> /sbin/makepkg -l y -c n \$OUTPUT/\$PRGNAM-\$VERSION-i486-\$BUILD\$TAG.\${PKGTYPE:-tgz} -"; +> /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-i486-$BUILD$TAG.${PKGTYPE:-tgz} +'; is(diff("$slackbuild.orig", $slackbuild, {STYLE => 'OldStyle'}), $expected_out, 'all changed lines rewritten correctly'); is(revert_slackbuild $slackbuild, 1, 'revert_slackbuild is good again'); @@ -392,5 +396,40 @@ is($count, 4, 'confirm_remove good for duplicate sbo'); # test get_readme_contents ok((get_readme_contents "$sbo_home/network/nagios"), 'get_readme_contents is good'); +# test get_dl_fns +my $downloads = [ + 'http://developer.download.nvidia.com/cg/Cg_3.1/Cg-3.1_April2012_x86.tgz' +]; +my $fns = get_dl_fns $downloads; +is($$fns[0], 'Cg-3.1_April2012_x86.tgz', 'get_dl_fns test, one input'); +$downloads = [ + 'http://download.virtualbox.org/virtualbox/4.2.0/VirtualBox-4.2.0.tar.bz2', + 'http://download.virtualbox.org/virtualbox/4.2.0/VBoxGuestAdditions_4.2.0.iso', + 'http://download.virtualbox.org/virtualbox/4.2.0/UserManual.pdf', + 'http://download.virtualbox.org/virtualbox/4.2.0/SDKRef.pdf', +]; +$fns = get_dl_fns $downloads; +is($$fns[0], 'VirtualBox-4.2.0.tar.bz2', 'get_dl_fns test, multiple inputs 01'); +is($$fns[2], 'UserManual.pdf', 'get_dl_fns test, multiple inputs 02'); + +# test get_dc_regex - multiple tests for various types of input +my $line = 'tar xvf $CWD/$PRGNAM-$VERSION.tar.?z*'; +my ($regex, $initial) = get_dc_regex $line; +is($regex, '(?^u:/[^-]+-[^-]+.tar.[a-z]z.*)', 'get_dc_regex test 01.1'); +is($initial, '/', 'get_dc_regex test 01.2'); +$line = 'tar xvf $CWD/Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack'; +($regex, $initial) = get_dc_regex $line; +is($regex, '(?^u:/Oracle_VM_VirtualBox_Extension_Pack-[^-]+.vbox-extpack)', + 'get_dc_regex test 02.1'); +is($initial, '/', 'get_dc_regex test 02.2'); +$line = 'tar xvf $CWD/${PRGNAM}-source-$(echo $VERSION).tar.gz'; +($regex, $initial) = get_dc_regex $line; +is($regex, '(?^u:/[^-]+-source-[^-]+.tar.gz)', 'get_dc_regex test 03.1'); +is($initial, '/', 'get_dc_regex test 03.2'); +$line = '( tar xvf xapian-bindings-$VERSION.tar.gz'; +($regex, $initial) = get_dc_regex $line; +is($regex, '(?^u: xapian-bindings-[^-]+.tar.gz)', 'get_dc_regex test 04.1'); +is($initial, ' ', 'get_dc_regex test 04.2'); + # end of tests. done_testing(); |