From 04a0d8bc1a8337df3cc2eded36c0986f0d0a4f6f Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 03:12:44 +0100 Subject: build ship: generate directives and input_parser --- ship/build | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 15 deletions(-) (limited to 'ship/build') diff --git a/ship/build b/ship/build index 486f4bed..3c510f91 100755 --- a/ship/build +++ b/ship/build @@ -12,6 +12,25 @@ build() { esac } +## usage: init +init() { + directive_pattern='s:^ *\\([0-9]\\+\\) \1$:\2 \3:' + + input_parser="$(make_input_parser "$0")" + debug_script input_parser '$0' + + build_directives="$(make_build_directives "$0")" + debug_script build_directives '$0' + + build_x_directive_loader="$(make_build_x_directive_loader "$0")" + debug_script build_x_directive_loader '$0' + + eval "$build_x_directive_loader" + + needs_compilation_sentinel="$(make_needs_compilation_sentinel $build_directives)" + debug_script needs_compilation_sentinel 'build_directives' +} + # usage: debug_script VARNAME [DESCRIPTION] debug_script() { if test "${debug-false}" = true; then @@ -22,18 +41,7 @@ debug_script() { fi } -## build directives -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:" -debug_script input_parser - -## usage: build_include LINENO LIBNAME +## usage: #@include \([0-9A-Za-z]\+\) -> build_include \1 \2 build_include() { cat< build_info \1 build_info() { cat< \([^ ]\+\) \(.*\)$/s:^ *\\([0-9]\\+\\) \1$:\2 \3:/p + $a\ +t;s:^ *\\([0-9]\\+\\) .*:echo \\1p: + ' "$1")" +} + +## usage: make_build_directives FILENAME +make_build_directives() { + echo "$(sed -n ' + s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/\2_directive/p + ' "$0")" +} + +## usage: make_build_x_directive_loader FILENAME +make_build_x_directive_loader() { + sed -n ' + s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/\2_directive='"'"'\1'"'"'/p + ' "$1" +} + +## usage: make_needs_compilation_sentinel BUILD_DIRECTIVES... +make_needs_compilation_sentinel() { + echo "^\\($( + for directive; do + eval echo \"\$$directive\" + done | + tr \\n \| | + sed 's/|/\\|/' + )\\)$" +} + +## main +init build "$@" -- cgit v1.2.3 From 7631078cfc08b85954aca3dcf0e8521a3fa2d9f9 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 03:32:46 +0100 Subject: ship build: purge init --- ship/build | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'ship/build') diff --git a/ship/build b/ship/build index 3c510f91..ad902231 100755 --- a/ship/build +++ b/ship/build @@ -12,25 +12,6 @@ build() { esac } -## usage: init -init() { - directive_pattern='s:^ *\\([0-9]\\+\\) \1$:\2 \3:' - - input_parser="$(make_input_parser "$0")" - debug_script input_parser '$0' - - build_directives="$(make_build_directives "$0")" - debug_script build_directives '$0' - - build_x_directive_loader="$(make_build_x_directive_loader "$0")" - debug_script build_x_directive_loader '$0' - - eval "$build_x_directive_loader" - - needs_compilation_sentinel="$(make_needs_compilation_sentinel $build_directives)" - debug_script needs_compilation_sentinel 'build_directives' -} - # usage: debug_script VARNAME [DESCRIPTION] debug_script() { if test "${debug-false}" = true; then @@ -65,8 +46,19 @@ build_compile() { srcfile="$(cat "$1")" debug_script srcfile 'SRCFILE' - while needs_compilation "$srcfile"; do - script="$(make_sedscript_maker_shellscript "$srcfile")" + build_directives="$(make_build_directives "$0")" + debug_script build_directives '$0' + + build_x_directive_loader="$(make_build_x_directive_loader "$0")" + debug_script build_x_directive_loader '$0' + + eval "$build_x_directive_loader" + + input_parser="$(make_input_parser "$0")" + sentinel="$(make_needs_compilation_sentinel $build_directives)" + + while needs_compilation "$srcfile" "$sentinel"; do + script="$(make_sedscript_maker_shellscript "$srcfile" "$input_parser")" srcfile="$(echo "$srcfile" | sed -n "$script")" debug_script srcfile 'sed sedscript srcfile' done @@ -75,17 +67,17 @@ build_compile() { chmod +x "$2" } -## usage: needs_compilation SHELLSCRIPT +## usage: needs_compilation SHELLSCRIPT SENTINEL # Returns true if SRCFILE contains compilation directives. needs_compilation() { - echo "$1" | grep -q "$needs_compilation_sentinel" + echo "$1" | grep -q "$2" } -## usage: make_sedscript_maker_shellscript SRCFILE +## usage: make_sedscript_maker_shellscript SRCFILE INPUT_PARSER # Print a shellscript that creates a sedscript that resolves all the build # directives in SRCFILE. make_sedscript_maker_shellscript() { - sedscript_generator="$(echo "$1" | nl -b a -s ' ' | sed "$input_parser")" + sedscript_generator="$(echo "$1" | nl -b a -s ' ' | sed "$2")" debug_script sedscript_generator 'sed input_parser srcfile' sedscript="$(eval "$sedscript_generator")" @@ -160,5 +152,4 @@ make_needs_compilation_sentinel() { } ## main -init build "$@" -- cgit v1.2.3 From 0db968b3ca9d7efbf49730226f00a3912f4bca17 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 04:01:41 +0100 Subject: ship build: add defvar --- ship/build | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'ship/build') diff --git a/ship/build b/ship/build index ad902231..aa8806ca 100755 --- a/ship/build +++ b/ship/build @@ -12,16 +12,6 @@ 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 -} - ## usage: #@include \([0-9A-Za-z]\+\) -> build_include \1 \2 build_include() { cat< "$2" @@ -77,12 +61,9 @@ needs_compilation() { # Print a shellscript that creates a sedscript that resolves all the build # directives in SRCFILE. make_sedscript_maker_shellscript() { - sedscript_generator="$(echo "$1" | nl -b a -s ' ' | sed "$2")" - debug_script sedscript_generator 'sed input_parser srcfile' - - sedscript="$(eval "$sedscript_generator")" - debug_script sedscript 'eval sedscript_generator' - + defvar sedscript_generator "$(echo "$1" | nl -b a -s ' ' | sed "$2")" \ + 'sed input_parser srcfile' + defvar sedscript "$(eval "$sedscript_generator")" 'eval sedscript_generator' echo "$sedscript" } @@ -151,5 +132,16 @@ make_needs_compilation_sentinel() { )\\)$" } +## usage: defvar NAME VALUE [DESCRIPTION] +defvar() { + eval "$1=\"\$2\"" + if test "${debug-false}" = true; then + printf '====== %s%s\n%s\n' \ + "$1" \ + "${3+" ($3)"}" \ + "$(eval echo \"\$$1\" | nl -b a)" >&2 + fi +} + ## main build "$@" -- cgit v1.2.3 From 4c300189fb47ac203b67904535006cab4c60a7bc Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 05:39:04 +0100 Subject: ship build: purge make_sedscript_maker_shellscript --- ship/build | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'ship/build') diff --git a/ship/build b/ship/build index aa8806ca..3fd1469a 100755 --- a/ship/build +++ b/ship/build @@ -33,21 +33,23 @@ EOF ## usage: build_compile SRCFILE DSTFILE build_compile() { - defvar srcfile "$(cat "$1")" 'SRCFILE' - defvar build_directives "$(make_build_directives "$0")" '$0' - defvar build_x_directive_loader "$(make_build_x_directive_loader "$0")" '$0' + setf build_directives '$(make_build_directives "$%s")' 0 + setf build_x_directive_loader '$(make_build_x_directive_loader "$%s")' 0 eval "$build_x_directive_loader" - defvar input_parser "$(make_input_parser "$0")" - defvar sentinel "$(make_needs_compilation_sentinel $build_directives)" + setf input_parser '$(make_input_parser "$%s")' 0 + setf sentinel '$(make_needs_compilation_sentinel $%s)' build_directives - while needs_compilation "$srcfile" "$sentinel"; do - defvar script "$(make_sedscript_maker_shellscript "$srcfile" "$input_parser")" - defvar srcfile "$(echo "$srcfile" | sed -n "$script")" 'sed script srcfile' + SRCFILE="$1" setf src '$(cat "$%s")' SRCFILE + + while needs_compilation "$src" "$sentinel"; do + setf sedgen '$(echo "$%s" | nl -b a -s \ | sed "$%s")' src input_parser + setf sedscript '$(eval "$%s")' sedgen + setf src '$(echo "$%s" | sed -n "$%s")' src sedscript done - echo "$srcfile" > "$2" + echo "$src" > "$2" chmod +x "$2" } @@ -57,16 +59,6 @@ needs_compilation() { echo "$1" | grep -q "$2" } -## usage: make_sedscript_maker_shellscript SRCFILE INPUT_PARSER -# Print a shellscript that creates a sedscript that resolves all the build -# directives in SRCFILE. -make_sedscript_maker_shellscript() { - defvar sedscript_generator "$(echo "$1" | nl -b a -s ' ' | sed "$2")" \ - 'sed input_parser srcfile' - defvar sedscript "$(eval "$sedscript_generator")" 'eval sedscript_generator' - echo "$sedscript" -} - ## usage: build_deps SRCFILE... # Print all the dependencies of SRCFILE... (in alphabetic order) to stdout. build_deps() { @@ -132,15 +124,16 @@ make_needs_compilation_sentinel() { )\\)$" } -## usage: defvar NAME VALUE [DESCRIPTION] -defvar() { - eval "$1=\"\$2\"" +## usage: setf NAME FMT [ARG...] +setf() { + value_script="$(shift; printf "$@")" + + eval "$1=$value_script" + if test "${debug-false}" = true; then - printf '====== %s%s\n%s\n' \ - "$1" \ - "${3+" ($3)"}" \ - "$(eval echo \"\$$1\" | nl -b a)" >&2 - fi + eval 'echo "$1=\"$value_script\""' + eval 'echo "'"\$$1"'"' | nl -b a + fi >&2 } ## main -- cgit v1.2.3 From a55f7d7593c54eb67c4e703fab42b65273cf9b3f Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 06:45:15 +0100 Subject: ship build: inline make_* --- ship/build | 51 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) (limited to 'ship/build') diff --git a/ship/build b/ship/build index 3fd1469a..a0b9220a 100755 --- a/ship/build +++ b/ship/build @@ -33,17 +33,29 @@ EOF ## usage: build_compile SRCFILE DSTFILE build_compile() { - setf build_directives '$(make_build_directives "$%s")' 0 - setf build_x_directive_loader '$(make_build_x_directive_loader "$%s")' 0 + usage_pattern='## usage: \(.*\) -> \([^ ]\+\) \(.*\)' + + script='s/^'"$usage_pattern"'$/\2_directive/p' \ + setf build_directives '$(sed -n "$script" "$%s")' 0 + + script='s/^'"$usage_pattern"'$/\2_directive='"'"'\1'"'"'/p' \ + setf build_x_directive_loader '$(sed -n "$script" "$%s")' 0 eval "$build_x_directive_loader" - setf input_parser '$(make_input_parser "$%s")' 0 - setf sentinel '$(make_needs_compilation_sentinel $%s)' build_directives + setf incomplete_pattern '$(make_incomplete_pattern $%s)' build_directives + + script=' + s/^'"$usage_pattern"'$/s:^ *\\([0-9]\\+\\) \1$:\2 \3:/p + $a\ + t\ + s:^ *\\([0-9]\\+\\) .*:echo \\1p: + ' \ + setf input_parser '$(sed -n "$script" "$%s")' 0 SRCFILE="$1" setf src '$(cat "$%s")' SRCFILE - while needs_compilation "$src" "$sentinel"; do + while needs_compilation "$src" "$incomplete_pattern"; do setf sedgen '$(echo "$%s" | nl -b a -s \ | sed "$%s")' src input_parser setf sedscript '$(eval "$%s")' sedgen setf src '$(echo "$%s" | sed -n "$%s")' src sedscript @@ -53,7 +65,7 @@ build_compile() { chmod +x "$2" } -## usage: needs_compilation SHELLSCRIPT SENTINEL +## usage: needs_compilation SHELLSCRIPT PATTERN # Returns true if SRCFILE contains compilation directives. needs_compilation() { echo "$1" | grep -q "$2" @@ -90,31 +102,8 @@ build_resolve() { } } -## usage: make_input_parser FILENAME -make_input_parser() { - echo "$(sed -n ' - s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/s:^ *\\([0-9]\\+\\) \1$:\2 \3:/p - $a\ -t;s:^ *\\([0-9]\\+\\) .*:echo \\1p: - ' "$1")" -} - -## usage: make_build_directives FILENAME -make_build_directives() { - echo "$(sed -n ' - s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/\2_directive/p - ' "$0")" -} - -## usage: make_build_x_directive_loader FILENAME -make_build_x_directive_loader() { - sed -n ' - s/^## usage: \(.*\) -> \([^ ]\+\) \(.*\)$/\2_directive='"'"'\1'"'"'/p - ' "$1" -} - -## usage: make_needs_compilation_sentinel BUILD_DIRECTIVES... -make_needs_compilation_sentinel() { +## usage: make_incomplete_pattern BUILD_DIRECTIVES... +make_incomplete_pattern() { echo "^\\($( for directive; do eval echo \"\$$directive\" -- cgit v1.2.3 From 212e9dcb7b9ed3fd7f09f6b69b0b39e7aff2d84f Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 6 Nov 2013 14:15:08 +0100 Subject: ship build: load directives before build_deps Because build_deps requires #@include. This is required because build_deps requires the #@include directive. --- ship/build | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'ship/build') diff --git a/ship/build b/ship/build index a0b9220a..10fc4345 100755 --- a/ship/build +++ b/ship/build @@ -5,6 +5,14 @@ set -euf # [debug=true] build compile SRCFILE DSTFILE # [debug=true] build deps SRCFILE... build() { + + # usage_pattern is used to extract build directive declarations. + usage_pattern='## usage: \(.*\) -> \([^ ]\+\) \(.*\)' + + script='s/^'"$usage_pattern"'$/\2_directive='"'"'\1'"'"'/p' \ + setf build_x_directive_loader '$(sed -n "$script" "$%s")' 0 + eval "$build_x_directive_loader" + case "$1" in compile) build_compile "$2" "$3";; deps) shift; build_deps "$@";; @@ -34,17 +42,9 @@ EOF ## usage: build_compile SRCFILE DSTFILE build_compile() { - usage_pattern='## usage: \(.*\) -> \([^ ]\+\) \(.*\)' - script='s/^'"$usage_pattern"'$/\2_directive/p' \ setf build_directives '$(sed -n "$script" "$%s")' 0 - script='s/^'"$usage_pattern"'$/\2_directive='"'"'\1'"'"'/p' \ - setf build_x_directive_loader '$(sed -n "$script" "$%s")' 0 - eval "$build_x_directive_loader" - - setf incomplete_pattern '$(make_incomplete_pattern $%s)' build_directives - script=' s/^'"$usage_pattern"'$/s:^ *\\([0-9]\\+\\) \1$:\2 \3:/p $a\ @@ -53,6 +53,8 @@ build_compile() { ' \ setf input_parser '$(sed -n "$script" "$%s")' 0 + setf incomplete_pattern '$(make_incomplete_pattern $%s)' build_directives + SRCFILE="$1" setf src '$(cat "$%s")' SRCFILE while needs_compilation "$src" "$incomplete_pattern"; do -- cgit v1.2.3