From bf87133ae8e2ce6eb7923dc22c29b8f162c8756a Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Nov 2013 12:53:34 +0100 Subject: ship README: add title --- ship/README | 1 + 1 file changed, 1 insertion(+) create mode 100644 ship/README (limited to 'ship') diff --git a/ship/README b/ship/README new file mode 100644 index 00000000..b824b503 --- /dev/null +++ b/ship/README @@ -0,0 +1 @@ +# ship - shellscript installation processor -- cgit v1.2.3 From b676ca6e2f030622333e6f42ccd4ecfe90efb0ad Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Nov 2013 19:34:23 +0100 Subject: ship build: initial commit --- ship/bin/punani | 3 +-- ship/build | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ship/deploy | 6 +---- ship/lib/punani | 2 +- 4 files changed, 84 insertions(+), 8 deletions(-) create mode 100755 ship/build (limited to 'ship') diff --git a/ship/bin/punani b/ship/bin/punani index 1e3fab87..99a5a813 100755 --- a/ship/bin/punani +++ b/ship/bin/punani @@ -1,4 +1,3 @@ #!/bin/sh -# include core -# include punani +#@include punani punani "$@" diff --git a/ship/build b/ship/build new file mode 100755 index 00000000..6c26e6f3 --- /dev/null +++ b/ship/build @@ -0,0 +1,81 @@ +#! /bin/sh +set -euf + +## SYNOPSIS +# build compile SRCFILE DSTFILE +# build deps SRCFILE +build() { + case "$1" in + compile) build_compile "$2" "$3";; + deps) build_deps "$2";; + *) echo "build: $1: bad command" >&2; return 23;; + esac +} + +## build directives +build_include_directive='#@include \([0-9A-Za-z]\+\)' + +## usage: build_compile SRCFILE DSTFILE +build_compile() { + cp "$1" "$2" + + while needs_compilation "$2"; do + script="$(make_sedscript_maker_shellscript "$2" | sh)" + sed -n "$script" "$2" >"$2.tmp" + mv "$2.tmp" "$2" + done + + chmod +x "$2" +} + +## usage: needs_compilation SRCFILE +# Returns true if SRCFILE contains compilation directives. +needs_compilation() { + grep -q "^$build_include_directive$" "$1" +} + +## usage: make_sedscript_maker_shellscript SRCFILE +# Print a shellscript that creates a sedscript that resolves all the build +# directives in SRCFILE. +make_sedscript_maker_shellscript() { + echo 'set -euf' + deps="$(build_deps "$1")" + for lib in $deps; do + echo "_build_include_$(basename $lib)=$lib" + done + nl -b a -s ' ' "$1" | + sed ' + s:^ *:: + s:^\([0-9]\+\) '"$build_include_directive"'$:\1a\\\\\ +# BEGIN \2\ + \1r\$_build_include_\2\ + \1a\\\\\ +# END \2: + s:^\([0-9]\+\) .*:\1p: + + 1s:^:echo ": + $s:$:": + ' +} + +## usage: build_deps SRCFILE +build_deps() { + for libname in $(sed -n 's:^'"$build_include_directive"'$:\1:p' "$1"); do + build_resolve "$libname" + done +} + +## usage: build_resolve LIBNAME +build_resolve() { + echo "$BUILD_PATH" | tr : \\n | + xargs -I: printf '%s/%s\n' : "$1" | + xargs -I: ls -d : 2>/dev/null | + head -n 1 | + grep . || + { + echo "build resolve: $1: library not found" >&2 + return 23 + } +} + +build "$@" diff --git a/ship/deploy b/ship/deploy index 5c282398..0f3e5219 100755 --- a/ship/deploy +++ b/ship/deploy @@ -4,11 +4,7 @@ cd $(dirname $0) bindir=$PWD/bin/ libdir=$PWD/lib/ outdir=$PWD/out/ -# Hill-Billy style package builder for file in `ls -1 $bindir`;do - # cat every lib and the file itself afterwards into outfile - find $libdir -type f -exec cat '{}' \; > $outdir/$file - cat $bindir/$file >> $outdir/$file + BUILD_PATH=$libdir ./build compile bin/$file out/$file chmod 755 $outdir/$file done - diff --git a/ship/lib/punani b/ship/lib/punani index beaee27c..e4a5a5e9 100644 --- a/ship/lib/punani +++ b/ship/lib/punani @@ -1,5 +1,5 @@ #!/bin/sh -#include core +#@include core ## begin punani DB _punanidb_pacman_= -- cgit v1.2.3 From 01ddf924ae017b71470d1e83124f69a53566e62c Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Nov 2013 20:16:04 +0100 Subject: ship build: add #@info directive --- ship/bin/punani | 1 + ship/build | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'ship') diff --git a/ship/bin/punani b/ship/bin/punani index 99a5a813..28bf7d1a 100755 --- a/ship/bin/punani +++ b/ship/bin/punani @@ -1,3 +1,4 @@ #!/bin/sh +#@info #@include punani punani "$@" diff --git a/ship/build b/ship/build index 6c26e6f3..cb4c20af 100755 --- a/ship/build +++ b/ship/build @@ -13,6 +13,7 @@ build() { } ## build directives +build_info_directive='#@info' build_include_directive='#@include \([0-9A-Za-z]\+\)' ## usage: build_compile SRCFILE DSTFILE @@ -31,7 +32,7 @@ build_compile() { ## usage: needs_compilation SRCFILE # Returns true if SRCFILE contains compilation directives. needs_compilation() { - grep -q "^$build_include_directive$" "$1" + grep -q "^\\($build_include_directive\\|$build_info_directive\\)$" "$1" } ## usage: make_sedscript_maker_shellscript SRCFILE @@ -39,18 +40,32 @@ needs_compilation() { # directives in SRCFILE. make_sedscript_maker_shellscript() { echo 'set -euf' + + echo "_build_info='$( + echo "# This file was generated by //ship/build \\" + echo "# Date: $(date -u --rfc-3339=s) \\" + echo "# Git-Commit: $(git show --pretty=oneline | awk '{print$1}')" + )'" + deps="$(build_deps "$1")" for lib in $deps; do echo "_build_include_$(basename $lib)=$lib" done + nl -b a -s ' ' "$1" | sed ' s:^ *:: + + s:^\([0-9]\+\) '"$build_info_directive"'$:\1a\\\\\ +$_build_info\ + : + s:^\([0-9]\+\) '"$build_include_directive"'$:\1a\\\\\ # BEGIN \2\ \1r\$_build_include_\2\ \1a\\\\\ # END \2: + s:^\([0-9]\+\) .*:\1p: 1s:^:echo ": -- cgit v1.2.3 From 816471fe35bb2e9886ed3c3fdff8f23f700c912b Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Nov 2013 20:21:49 +0100 Subject: ship build: remove excessive space --- ship/build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ship') diff --git a/ship/build b/ship/build index cb4c20af..1c6f2e75 100755 --- a/ship/build +++ b/ship/build @@ -42,8 +42,8 @@ make_sedscript_maker_shellscript() { echo 'set -euf' echo "_build_info='$( - echo "# This file was generated by //ship/build \\" - echo "# Date: $(date -u --rfc-3339=s) \\" + echo "# This file was generated by //ship/build\\" + echo "# Date: $(date -u --rfc-3339=s)\\" echo "# Git-Commit: $(git show --pretty=oneline | awk '{print$1}')" )'" -- cgit v1.2.3 From 85c99011060b4b37a760fa24d0a0e23e83413bef Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Nov 2013 23:29:34 +0100 Subject: ship build: modularize directive decls --- ship/build | 75 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'ship') diff --git a/ship/build b/ship/build index 1c6f2e75..916953cc 100755 --- a/ship/build +++ b/ship/build @@ -16,61 +16,58 @@ build() { build_info_directive='#@info' build_include_directive='#@include \([0-9A-Za-z]\+\)' +input_parser="\ +s:^ *\([0-9]\+\) "$build_info_directive"$:build_info \1: +s:^ *\([0-9]\+\) "$build_include_directive"$:build_include \1 \2: +t +s:^ *\([0-9]\+\) .*:echo \1p:" + +## usage: build_include LINENO LIBNAME +build_include() { cat<"$2.tmp" - mv "$2.tmp" "$2" + while needs_compilation "$srcfile"; do + script="$(make_sedscript_maker_shellscript "$srcfile")" + srcfile="$(echo "$srcfile" | sed -n "$script")" done + echo "$srcfile" > "$2" chmod +x "$2" } -## usage: needs_compilation SRCFILE +## usage: needs_compilation SHELLSCRIPT # Returns true if SRCFILE contains compilation directives. needs_compilation() { - grep -q "^\\($build_include_directive\\|$build_info_directive\\)$" "$1" + echo "$1" | + grep -q "^\\($build_include_directive\\|$build_info_directive\\)$" } ## usage: make_sedscript_maker_shellscript SRCFILE # Print a shellscript that creates a sedscript that resolves all the build # directives in SRCFILE. make_sedscript_maker_shellscript() { - echo 'set -euf' - - echo "_build_info='$( - echo "# This file was generated by //ship/build\\" - echo "# Date: $(date -u --rfc-3339=s)\\" - echo "# Git-Commit: $(git show --pretty=oneline | awk '{print$1}')" - )'" - - deps="$(build_deps "$1")" - for lib in $deps; do - echo "_build_include_$(basename $lib)=$lib" - done - - nl -b a -s ' ' "$1" | - sed ' - s:^ *:: - - s:^\([0-9]\+\) '"$build_info_directive"'$:\1a\\\\\ -$_build_info\ - : - - s:^\([0-9]\+\) '"$build_include_directive"'$:\1a\\\\\ -# BEGIN \2\ - \1r\$_build_include_\2\ - \1a\\\\\ -# END \2: - - s:^\([0-9]\+\) .*:\1p: - - 1s:^:echo ": - $s:$:": - ' + sedscript_generator="$(echo "$1" | nl -b a -s ' ' | sed "$input_parser")" + sedscript="$(eval "$sedscript_generator")" + echo "$sedscript" } ## usage: build_deps SRCFILE -- cgit v1.2.3