summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Davis <jrcd83@gmail.com>2012-03-07 19:45:54 +0100
committerJustin Davis <jrcd83@gmail.com>2012-03-07 19:45:54 +0100
commit82a6d2fcba2569c1fe249283e4513ad66cc0e031 (patch)
tree85446a9ba35e45cdb5efd8b8462d0e447c083a88
parent0873b3e326586ff2b7b3b0e6cbdd85e1a31ec4ad (diff)
downloadgenpkg-82a6d2fcba2569c1fe249283e4513ad66cc0e031.tar.gz
genpkg-82a6d2fcba2569c1fe249283e4513ad66cc0e031.tar.xz
Change perl-pkgbuild to use new PKGTREE.
Updates genpkg as well. Adds func to genpkg for merging files back together from PKGTREE dir.
-rwxr-xr-xbin/genpkg65
-rwxr-xr-xbin/getpkgtree2
-rwxr-xr-xmetas/perl.d/perl-dist26
-rwxr-xr-xmetas/perl.d/perl-dist-funcs101
-rwxr-xr-xmetas/perl.d/perl-pkgbuild122
-rwxr-xr-xsetup12
6 files changed, 199 insertions, 129 deletions
diff --git a/bin/genpkg b/bin/genpkg
index 513fa9e..fcfa7cf 100755
--- a/bin/genpkg
+++ b/bin/genpkg
@@ -8,6 +8,45 @@ tweakd=~/pkg/tweaks
pkgd=~/pkg/dest
vard=~/.genpkg/var
+mergefile()
+{
+ fname="$1"
+ shift
+
+ if [ -f "$fname.$$" ]
+ then
+ echo "$prog: error: temp file already exists: $fname.$$" 1>&2
+ return 1
+ fi
+
+ while [ "$#" -gt 0 ]
+ do
+ sect="$1"
+ shift
+ getpkgtree "$fname" "$sect" >> "$fname.$$"
+
+ case "$?" in
+ 0) ;;
+ 101) echo "$prog: error: missing file in PKGTREE: $fname" 1>&2
+ return 101 ;;
+ 102) continue ;; # empty section so don't echo a newline below
+ *) echo "$prog: unknown error from getpkgtree: $?" 1>&2
+ return 1 ;;
+ esac
+
+ [ "$#" -gt 0 ] && echo >> "$fname.$$"
+ done
+
+ if du "$fname.$$" | awk '$1 == 0 { exit 1 }'
+ then
+ mv "$fname.$$" "$fname"
+ return 0
+ else
+ rm "$fname.$$"
+ return 1
+ fi
+}
+
if [ $# -lt 1 ]
then
echo "usage: $prog [package name]" 1>&2
@@ -32,27 +71,31 @@ then
exit 1
fi
-cwd=$(pwd)
-
for pkg
do
[ -d "$pkgd/$pkg" ] || mkdir "$pkgd/$pkg"
cd "$pkgd/$pkg"
+ if [ -d PKGTREE ]
+ then
+ echo "$prog: warning: removing old PKGTREE" 1>&2
+ rm -rf PKGTREE
+ fi
+ mkdir PKGTREE
+
if METABIN="$metad" PKGVAR="$vard" mkpkgmeta "$pkg"
then
echo "$pkgd/$pkg"
- echo "Generated PKGDATA and PKGTREE." 1>&2
else
- exit $?
+ exit "$?"
fi
- twk="$tweakd/$pkg"
- if [ -f "$twk" -a -r "$twk" ] && modpkgmeta
- then
- echo "Modified metapackage." 1>&2
- fi
+ #twk="$tweakd/$pkg"
+ #if [ -f "$twk" -a -r "$twk" ] && modmetapkg
+ #then
+ # echo "Modified metapackage." 1>&2
+ #fi
- mergepbfields | emitpkgtree || exit $?
+ pbfields < PKGDATA | putpkgtree PKGBUILD prefix body || exit "$?"
+ mergefile PKGBUILD prefix build check package suffix || exit "$?"
done
-
diff --git a/bin/getpkgtree b/bin/getpkgtree
index 38d4930..b8787b1 100755
--- a/bin/getpkgtree
+++ b/bin/getpkgtree
@@ -14,5 +14,5 @@ then
exit 100
fi
[ -d "PKGTREE/$1" ] || exit 101
-[ -d "PKGTREE/$1/$2" ] || exit 101
+[ -d "PKGTREE/$1/$2" ] || exit 102
find "PKGTREE/$1/$2" -maxdepth 1 -type f | sort | xargs cat
diff --git a/metas/perl.d/perl-dist b/metas/perl.d/perl-dist
index 99d187b..69f9317 100755
--- a/metas/perl.d/perl-dist
+++ b/metas/perl.d/perl-dist
@@ -4,7 +4,7 @@ use warnings 'FATAL' => 'all';
use strict;
my $PROG = 'metas/perl.d/perl-dist';
-my $FUNCPROG = 'perl-dist-funcs';
+my $PBPROG = 'perl-pkgbuild';
sub DBG {}
if(exists $ENV{'GENDBG'}){
@@ -381,12 +381,15 @@ sub printdata
return;
}
-sub printfuncs
+sub writepb
{
my($ddir) = @_;
my $dtype = (-f "$ddir/Build.PL" ? "MB" : "MM");
- exec $FUNCPROG => $dtype
- or die "$PROG: $FUNCPROG failed to execute!\n";
+ if(system $PBPROG => $dtype){
+ return $? >> 8;
+ }else{
+ return 0;
+ }
}
sub main
@@ -419,16 +422,19 @@ sub main
%$deps,
);
- print STDERR "DBG: \$dir = $dir\n";
chdir $dir or die "chdir: $!";
- close STDOUT or die "close STDOUT: $!";
+ my $ret = writepb($dir);
+ if($ret){
+ print STDERR "$PROG: failed to write PKGBUILD: error $ret\n";
+ return 1;
+ }
+
+ close STDOUT;
open STDOUT, '>', 'PKGDATA' or die "open PKGDATA: $!";
printdata(\%pbvars);
-
- close STDOUT or die "close STDOUT: $!";
- open STDOUT, '>', 'PKGFUNC', or die "open PKGFUNC: $!";
- exit printfuncs($dir);
+ close STDOUT or die "close PKGDATA: $!";
+ return 0;
}
# Create the src/ directory and tarball symlink. Then chdir into it.
diff --git a/metas/perl.d/perl-dist-funcs b/metas/perl.d/perl-dist-funcs
deleted file mode 100755
index cc9ba19..0000000
--- a/metas/perl.d/perl-dist-funcs
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/usr/bin/env perl
-
-use warnings 'FATAL' => 'all';
-use strict;
-
-my $PROG = 'perl-dist-funcs';
-
-my %BODYFOR =
- ('MM', {
- 'build' => [
- q{/usr/bin/perl Makefile.PL }
- . q{DESTDIR="$pkgdir" INSTALLDIRS=vendor},
- q{make},
- ],
- 'check' => [ q{make test} ],
- 'package' => [ q{make install} ],
- },
- 'MB', {
- 'build' => [
- q{/usr/bin/perl Build.PL }
- . q{--destdir "$pkgdir" --installdirs vendor},
- q{./Build},
- ],
- 'check' => [ q{./Build test} ],
- 'package' => [ q{./Build install} ],
- });
-
-my %FUNC;
-$FUNC{'build'}{'intro'} = <<'END_INTRO';
-cd "$_distdir"
-PERL_MM_USE_DEFAULT=1 PERL_AUTOINSTALL=--skipdeps MODULEBUILDRC=/dev/null
-export PERL_MM_USE_DEFAULT PERL_AUTOINSTALL MODULEBUILDRC
-unset PERL_MM_OPT PERL_MB_OPT PERL5LIB
-END_INTRO
-
-$FUNC{'check'}{'intro'} = <<'END_INTRO';
-cd "$_distdir"
-PERL_MM_USE_DEFAULT=1
-export PERL_MM_USE_DEFAULT
-unset PERL_MM_OPT PERL_MB_OPT PERL5LIB
-END_INTRO
-
-$FUNC{'package'}{'intro'} = <<'END_INTRO';
-cd "$_distdir"
-unset PERL_MM_OPT PERL_MB_OPT PERL5LIB
-END_INTRO
-
-$FUNC{'package'}{'end'} = <<'END_END';
-find "$pkgdir" -name .packlist -o -name perllocal.pod -delete
-END_END
-
-my $PBEND = <<'END_END';
-# Local Variables:
-# mode: shell-script
-# sh-basic-offset: 2
-# End:
-# vim:set ts=2 sw=2 et:
-END_END
-
-sub printfunc
-{
- my($name, $func) = @_;
- print "BEGNODE $name\n";
- for my $sect (qw/intro body end/){
- if(exists $func->{$sect}){
- my $txt = $func->{$sect};
- $txt .= "\n" unless($txt =~ /\n\z/);
- print "BEGNODE $sect\n", $txt, "ENDNODE $sect\n";
- }
- }
- print "ENDNODE $name\n";
- return;
-}
-
-sub printfuncs
-{
- my($btype) = @_;
- my $acts = $BODYFOR{$btype} or die "$PROG: unknown build type: $btype";
-
- print "BEGNODE PKGBUILD\n", "BEGNODE body\n";
- for my $f (keys %FUNC){
- $FUNC{$f}{'body'} = join q{}, map { "$_\n" } @{$acts->{$f}};
- printfunc($f, $FUNC{$f});
- }
- print "ENDNODE body\n";
- print "BEGNODE end\n", $PBEND, "ENDNODE end\n";
- print "ENDNODE PKGBUILD\n";
- return;
-}
-
-sub main
-{
- if(@_ == 0 || ($_[0] ne 'MM' && $_[0] ne 'MB')){
- print STDERR qq{usage: $PROG ["MM" or "MB"] > PKGFUNCS\n};
- return 1;
- }
- printfuncs(shift);
- return 0;
-}
-
-exit main(@ARGV);
diff --git a/metas/perl.d/perl-pkgbuild b/metas/perl.d/perl-pkgbuild
new file mode 100755
index 0000000..667ec3d
--- /dev/null
+++ b/metas/perl.d/perl-pkgbuild
@@ -0,0 +1,122 @@
+#!/usr/bin/env perl
+
+use warnings 'FATAL' => 'all';
+use strict;
+
+my $PROG = 'perl-pkgbuild';
+
+sub putpkgbuild
+{
+ my($sect, $subsect, $text) = @_;
+ open my $pipe, '|-', 'putpkgtree' => 'PKGBUILD', $sect, $subsect
+ or die "open putpkgtree: $!";
+ print $pipe $text;
+ close $pipe or exit $? >> 8;
+}
+
+sub putfuncs
+{
+ my($funcs) = @_;
+ for my $f (keys %$funcs){
+ my $sects = $funcs->{$f};
+ while(my ($s, $txt) = each %$sects){
+ putpkgbuild($f, $s, $txt);
+ }
+ }
+}
+
+sub startfunc
+{
+ my($name) = @_;
+ return <<"ENDTXT";
+${name}()
+(
+ cd "\$_distdir"
+ENDTXT
+}
+
+sub functxt
+{
+ my $fmt = shift;
+ $fmt .= "\n" unless($fmt =~ /\n\z/);
+ my $txt = sprintf $fmt, @_;
+ $txt =~ s/^/ /gm;
+ return $txt;
+}
+
+sub main
+{
+ if(@_ == 0 || ($_[0] ne 'MM' && $_[0] ne 'MB')){
+ print STDERR qq{usage: $PROG ["MM" or "MB"]\n};
+ return 1;
+ }
+
+ my $type = shift;
+ my($script, $make, $iargs);
+ my @badenv = qw/PERL5LIB/;
+ my @exports = qw/PERL_MM_USE_DEFAULT=1/;
+ if($type eq 'MM'){
+ $script = 'Makefile.PL';
+ $make = 'make';
+ $iargs = q{INSTALLDIRS=vendor DESTDIR="$pkgdir"};
+ push @exports, 'PERL_AUTOINSTALL=--skipdeps';
+ push @badenv, 'PERL_MM_OPT';
+ }else{
+ $script = 'Build.PL';
+ $make = './Build';
+ $iargs = q{installdirs=vendor destdir="$pkgdir"};
+ push @badenv, 'PERL_MB_OPT', 'MODULEBUILDRC=/dev/null';
+ }
+
+ my %funcs;
+ my @fnames = qw/build check package/;
+ for my $f (@fnames){
+ $funcs{$f}{'beg'} = startfunc($f);
+ # Module::Build uses env vars for each stage of Build
+ if($type eq 'MB'){
+ $funcs{$f}{'beg'} = <<"ENDTXT";
+export @exports
+unset @badenv
+ENDTXT
+ }
+ }
+
+ # ExtUtils::MakeMaker only uses env vars for Makefile.PL
+ if($type eq 'MM'){
+ $funcs{'build'}{'beg'} .= functxt(<<'ENDTXT', "@exports", "@badenv");
+export %s
+unset %s
+ENDTXT
+ }
+
+ $funcs{'build'}{'body'} = functxt(<<'ENDTXT', $script, $make);
+ . functxt(<<'ENDTXT', );
+
+/usr/bin/perl %s
+%s
+ENDTXT
+
+ $funcs{'check'}{'body'} = functxt("%s test", $make);
+
+ $funcs{'package'}{'body'} = functxt(<<'ENDTXT', $make, $iargs);
+%s install %s
+find "$pkgdir" -name .packlist -o -name perllocal.pod -delete
+ENDTXT
+
+ for my $f (@fnames){
+ $funcs{$f}{'end'} = ")\n";
+ }
+ putfuncs(\%funcs);
+
+ putpkgbuild('suffix', 'body', <<'ENDTXT');
+# Local Variables:
+# mode: shell-script
+# sh-basic-offset: 2
+# End:
+# vim:set ts=2 sw=2 et:
+ENDTXT
+
+ return 0;
+}
+
+exit main(@ARGV);
diff --git a/setup b/setup
index b70a293..ea34080 100755
--- a/setup
+++ b/setup
@@ -3,10 +3,10 @@
set -e
umask 022
prog=setup
-binfiles=(genpkg mkpkgmeta modpkgmeta pbfields mergepbfields emitpkgtree)
-metas=(perl perl.d/
- perl.d/fetchcpan perl.d/perl-dist perl.d/perl-dist-funcs
- perl.d/scrapecore)
+binfiles='genpkg mkpkgmeta modpkgmeta pbfields mergepbfields putpkgtree getpkgtree'
+metas='perl perl.d/
+ perl.d/fetchcpan perl.d/perl-dist perl.d/perl-pkgbuild
+ perl.d/scrapecore'
md()
{
@@ -36,14 +36,14 @@ Run "$prog tweaks" to install tweaks into ~/pkg/tweaks.
EOF
;;
genpkg) md ~/bin
- for pkg in ${binfiles[@]}
+ for pkg in $binfiles
do
ins "bin/$pkg" ~
done
md ~/.genpkg
md ~/.genpkg/metas
- for m in ${metas[@]}
+ for m in $metas
do
ins "metas/$m" ~/.genpkg
done