summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJustin Davis <jrcd83@gmail.com>2011-09-20 15:40:19 +0200
committerJustin Davis <jrcd83@gmail.com>2011-09-20 15:40:19 +0200
commitebea51086e04da8a9fc72fe78a1821d195d81455 (patch)
tree23966afdfc5c67757508fd584c3b2a098908ca82 /bin
parenta0855591a8beb49ddef92e19ca442a10c2220ea9 (diff)
downloadgenpkg-ebea51086e04da8a9fc72fe78a1821d195d81455.tar.gz
genpkg-ebea51086e04da8a9fc72fe78a1821d195d81455.tar.xz
Move "macro" expansion to new script. Simplifies pbjparse.awk.
Use the ! op in perl-cpan instead of running perl-dist separately. Lots of code shuffling.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/macros/perl-cpan6
-rwxr-xr-xbin/pbj55
-rwxr-xr-xbin/pbjexpand19
-rwxr-xr-xbin/pbjparse.awk130
4 files changed, 97 insertions, 113 deletions
diff --git a/bin/macros/perl-cpan b/bin/macros/perl-cpan
index cc87c4d..a28d852 100755
--- a/bin/macros/perl-cpan
+++ b/bin/macros/perl-cpan
@@ -31,8 +31,4 @@ print STDERR "OK\n";
print "+ url $url\n";
print "+ source $href\n";
-system "perl-dist $file";
-if ($? != 0) {
- printf STDERR "$0: failed to run perl-dist%s\n", ($! ? " ($!)" : q{});
- exit 1;
-}
+print "! perl-dist $file\n";
diff --git a/bin/pbj b/bin/pbj
index 1157075..a8e41df 100755
--- a/bin/pbj
+++ b/bin/pbj
@@ -3,7 +3,7 @@
VERSION=0.01
die() {
- echo "error: $1"
+ echo "error: $*"
exit 1
}
@@ -15,7 +15,8 @@ pbjtopkg()
cd "$pkgroot/$pkg"
jamfile="$jamdir/$1.pbj"
- if [ ! -f "$jamfile" ] ; then
+ if [ ! -f "$jamfile" ]
+ then
die "$jamfile is missing"
fi
@@ -23,49 +24,39 @@ pbjtopkg()
# Provide values for other things macros won't be able to.
printf "+ pkgname $pkg\n+ pkgrel ${PKGREL:-1}\n+ pbjver $VERSION\n" \
| cat - "$jamfile" \
+ | pbjexpand \
| awk -f "$bindir/pbjparse.awk" \
- > PKGBUILD
+ > PKGMETA
- if [ $? -ne 0 ] ; then
- echo "Failed to write $pkgroot/$pkg/PKGBUILD"
- exit $?
+ if [ $? -ne 0 ]
+ then
+ die "Failed to write $pkgroot/$pkg/PKGMETA"
fi
- echo "Wrote $pkgroot/$pkg/PKGBUILD."
-}
+ # pbjparse.awk also creates a makepb script in our cwd.
+ if ! ./makepb >PKGBUILD
+ then
+ die "makepb failed, error code $?"
+ fi
-if [ -z "$1" ] ; then
- die "Usage: $0 [package name]"
-fi
+ echo "$pkgroot/$pkg/PKGBUILD"
+}
-if [ "$PBJROOT" ] ; then
- cd "$PBJROOT"
-fi
+if [ -z "$1" ]; then die "Usage: $0 [package name]"; fi
+if [ "$PBJROOT" ]; then cd "$PBJROOT"; fi
bindir="$(pwd)/bin"
-if [ ! -d "$bindir" ] ; then
- die "$bindir does not exist"
-fi
+if [ ! -d "$bindir" ]; then die "$bindir does not exist"; fi
PATH="$PATH:$bindir"
-if [ -n "$PKGROOT" ] ; then
- pkgroot="$PKGROOT"
-else
- pkgroot="$(pwd)/pkg"
+if [ -n "$PKGROOT" ]; then pkgroot="$PKGROOT"
+else pkgroot="$(pwd)/pkg"
fi
-if [ ! -d "$pkgroot" ] ; then
- die "$pkgroot does not exist"
-fi
+if [ ! -d "$pkgroot" ]; then die "$pkgroot does not exist"; fi
jamdir="$(pwd)/pbj"
-if [ ! -d "$jamdir" ] ; then
- die "$jamdir does not exist"
-fi
+if [ ! -d "$jamdir" ]; then die "$jamdir does not exist"; fi
export PATH="$PATH:$bindir/macros:$bindir/templ"
-
-while [ $# -gt 0 ] ; do
- pbjtopkg $1
- shift
-done
+for pbj; do pbjtopkg "$pbj"; done
diff --git a/bin/pbjexpand b/bin/pbjexpand
new file mode 100755
index 0000000..ed86301
--- /dev/null
+++ b/bin/pbjexpand
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+cat $1 | while read op arg
+do
+ case "$op" in
+ '!')
+ expdepth=$((expdepth + 1))
+ if [ "$expdepth" -gt 10 ]
+ then
+ echo 'pbjexpand: depth of 10 recursive macros, aborting.' 1>&2
+ exit 1
+ fi
+
+ export expdepth
+ $arg | $0 ;;
+ *)
+ echo $op $arg
+ esac
+done
diff --git a/bin/pbjparse.awk b/bin/pbjparse.awk
index 6da1d34..8d86ad9 100755
--- a/bin/pbjparse.awk
+++ b/bin/pbjparse.awk
@@ -1,94 +1,68 @@
# pbjparse.awk
##
-# Parse a PBJ data file and print a PBDATA datafile to STDOUT.
+# Parse a .pbj data file and print a PKGMETA data file to stdout.
# Justin Davis <jrcd83@gmail.com>
-BEGIN {
- templcount = 0 # number of templates that will be in the templates array
- PROG = "pbjparse"
+BEGIN { PROG = "pbjparse" }
+
+{ sub(/#.*/, "") }
+
+$1 == "+" { pushval($2, joinfields(3)); next }
+
+$1 == "-" { remval($2, $3); next }
+
+$1 == "<" {
+ i = findval($2, $3)
+ stack[++stacklen] = pbvars[$2, i]
+ remelem($2, i)
+ next
+}
+
+$1 == ">" {
+ if (stacklen < 1)
+ die("No values on the stack. Make sure you use '<' first.")
+ pushval($2, stack[stacklen--])
+ next
}
-{ parsepbj() }
+$1 == "=" {
+ if ($2 == "optdepends") die("cannot use '=' with optdepends.")
+ remall($2)
+ for (i=3; i<=NF; i++) pushval($2, $i)
+ next
+}
+
+$1 == "!" {
+ cmd = joinfields(2)
+ while ((ret = cmd | getline) > 0) parsepbj()
+ if (ret == -1) die("failed to run " cmd)
+ close(cmd)
+ next
+}
+
+$1 == "|" { pbpipes[++pipecount] = joinfields(2); next }
+
+# ignore lines of whitespace
+$1 !~ /^[ \t]*$/ { die("invalid input: " $0) }
END {
- if (templcount > 0) {
- tcmd = templates[1]
- for (i=2; i<=templcount; i++) tcmd = tcmd "|" templates[i]
- }
- else tcmd = "cat"
+ OFS = "\n"
+ writemakepb()
for (name in pbcount) {
len = pbcount[name]
if (len == 0) continue
- print name | tcmd
- for (i=1; i<=len; i++) print pbvars[name, i] | tcmd
- print "" | tcmd
- }
-
- if (optdepcount > 0) {
- print "optdepends" | tcmd
- for (name in optdeps) print optdeps[name] | tcmd
- print "" | tcmd
+ print name
+ for (i=1; i<=len; i++) print pbvars[name, i]
+ print ""
}
if (!seenpkgr) {
pkger = ENVIRON["PACKAGER"]
if (pkger == "") pkger = "Anonymous"
- print "packager\n" pkger | tcmd
- }
-}
-
-function parsepbj ( cmd) # cmd is a "local" var
-{
- # Ignore comments.
- sub(/#.*/, "")
-
- # Optdeps are special. In an annoying way.
- if ($1 == "+") {
- if ($2 == "optdepends") {
- msg = joinfields(3)
-
- ++optdepcount
- name = optdepname($3)
- optdeps[name] = msg
- }
- else {
- # We print the default packager if none was seen.
- pushval($2, joinfields(3))
- }
- }
- else if ($1 == "-") {
- if ($2 == "optdepends")
- die("cannot delete an optdep once it is created.")
- remval($2, $3)
- }
- else if ($1 == "<") {
- i = findval($2, $3)
- stack[++stacklen] = pbvars[$2, i]
- remelem($2, i)
- }
- else if ($1 == ">") {
- if (stacklen < 1)
- die("No values on the stack. Make sure you used '<' first.")
- pushval($2, stack[stacklen--])
- }
- else if ($1 == "=") {
- if ($2 == "optdepends") die("cannot use '=' with optdepends.")
- remall($2)
- for (i=3; i<=NF; i++) pushval($2, $i)
- }
- else if ($1 == "!") {
- cmd = joinfields(2)
- while ((ret = cmd | getline) > 0) parsepbj()
- if (ret == -1) die("failed to run " cmd)
- close(cmd)
- }
- else if ($1 == "|") {
- templates[++templcount] = joinfields(2)
+ print "packager\n" pkger
}
- else if ($1 ~ /^[ \t]*$/) ; # ignore lines of whitespace
- else die("invalid input: " $0)
}
function die (msg)
@@ -140,9 +114,13 @@ function findval (field, prefix, i, len)
return i
}
-function optdepname (msgbeg)
+function writemakepb ()
{
- if (! match(msgbeg, "^[a-z_-]+:$"))
- die("bad optdepends name: " msgbeg)
- return substr(msgbeg, 1, RLENGTH-1)
+ tcmd = pbpipes[1]
+ for (i = 2; i <= pipecount; i++) tcmd = tcmd " | \\\n " pbpipes[i]
+ print "#!/bin/sh" > "makepb"
+ print "PATH=" ENVIRON["PATH"] > "makepb"
+ print "cat PKGMETA | " tcmd > "makepb"
+ close("makepb")
+ system("chmod +x makepb")
}