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 From 00c0f7dee4811a4df04a5f89e68fd7cada541765 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 00:44:26 +0100 Subject: ship build: export debug=true for debug output --- ship/build | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ship') diff --git a/ship/build b/ship/build index 916953cc..31f45061 100755 --- a/ship/build +++ b/ship/build @@ -2,8 +2,8 @@ set -euf ## SYNOPSIS -# build compile SRCFILE DSTFILE -# build deps SRCFILE +# [debug=true] build compile SRCFILE DSTFILE +# [debug=true] build deps SRCFILE build() { case "$1" in compile) build_compile "$2" "$3";; @@ -12,6 +12,16 @@ build() { esac } +# usage: debug_script VARNAME [DESCRIPTION] +debug_script() { + if test "${debug-false}" = true; then + printf '====== %s%s\n%s\n' \ + "$1" \ + "${2+" ($2)"}" \ + "$(eval echo \"\$$1\" | nl -b a)" >&2 + fi +} + ## build directives build_info_directive='#@info' build_include_directive='#@include \([0-9A-Za-z]\+\)' @@ -21,6 +31,7 @@ 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:" +debug_script input_parser ## usage: build_include LINENO LIBNAME build_include() { cat< "$2" @@ -66,7 +79,11 @@ needs_compilation() { # directives in SRCFILE. make_sedscript_maker_shellscript() { sedscript_generator="$(echo "$1" | nl -b a -s ' ' | sed "$input_parser")" + debug_script sedscript_generator 'sed input_parser srcfile' + sedscript="$(eval "$sedscript_generator")" + debug_script sedscript 'eval sedscript_generator' + echo "$sedscript" } -- cgit v1.2.3 From 7d6b65a71a3a18bb50c699e57738723d2056f436 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 01:03:16 +0100 Subject: ship build: recursive deps resolver --- ship/build | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'ship') diff --git a/ship/build b/ship/build index 31f45061..486f4bed 100755 --- a/ship/build +++ b/ship/build @@ -3,11 +3,11 @@ set -euf ## SYNOPSIS # [debug=true] build compile SRCFILE DSTFILE -# [debug=true] build deps SRCFILE +# [debug=true] build deps SRCFILE... build() { case "$1" in compile) build_compile "$2" "$3";; - deps) build_deps "$2";; + deps) shift; build_deps "$@";; *) echo "build: $1: bad command" >&2; return 23;; esac } @@ -87,11 +87,22 @@ make_sedscript_maker_shellscript() { echo "$sedscript" } -## usage: build_deps SRCFILE +## usage: build_deps SRCFILE... +# Print all the dependencies of SRCFILE... (in alphabetic order) to stdout. build_deps() { - for libname in $(sed -n 's:^'"$build_include_directive"'$:\1:p' "$1"); do - build_resolve "$libname" - done + while test $# -gt 0; do + deps="$( + for f; do + for d in $(sed -n 's:^'"$build_include_directive"'$:\1:p' "$f"); do + build_resolve $d + done + done + )" + set -- $deps + if test $# -gt 0; then + echo "$deps" + fi + done | sort | uniq } ## usage: build_resolve LIBNAME -- cgit v1.2.3