=== modified file 'common.zsh' --- common.zsh 2017-12-12 17:03:06 +0000 +++ common.zsh 2017-12-12 10:33:38 +0000 @@ -8,16 +8,15 @@ OUT=$3 FUNCDIR=${0:h:a}/functions TARGET=${BASE##*/}.${${${DO:t}%.do}#default.} -typeset -ga finish_hooks # helper that prints out error message and exits die() { - print -r - "$fg_bold[red]* $fg[cyan]${${${DO:t}%.do}#default.}:$reset_color $@" >&2 + print -r - "$fg_bold[red]*$reset_color $@" >&2 exit 1 } info() { - print -r - "$fg_bold[green]* $fg[cyan]${${${DO:t}%.do}#default.}:$reset_color $@" >&2 + print -r - "$fg_bold[green]*$reset_color $@" >&2 } autoload_functions() { @@ -72,17 +71,6 @@ info "entering: $name $(decode_argstr)" } -add_finish_hook() { - finish_hooks+=( ${(pj:\0:)@} ) -} - -run_finish_hooks() { - local hook - for hook in "$finish_hooks[@]"; do - "${(0@)hook}" || die "Hook failed: ${(0)hook}" - done -} - finish-info(){ local name name=${${${DO:t}%.do}#default.} @@ -93,7 +81,6 @@ } finish() { - run_finish_hooks finish-info print-meta >$OUT exit 0 @@ -118,52 +105,19 @@ (( $#empty )) && die "required parameters are empty: ${(@q)empty}" } -dep_add_file() { - local out - out=$(sha256sum $1) || die - vars[__check_deps__]+='if { test -e '${(qqq)1}$' }\n' - vars[__check_deps__]+='if { pipeline -d { printf "%s\n" '${(qqq)out}$' } sha256sum -c }\n' -} - -dep_add_missing() { - [[ -e $1 ]] || die "$0: ${(qqq)1} exists" - vars[__check_deps__]+='if -n { test -e '${(qqq)1}$' }\n' -} - -dep_add_file_or_missing() { +filehash() { if [[ -f $1 ]]; then - dep_add_file $1 - elif [[ -e $1 ]]; then - die "$0: ${(qqq)1} exists and is not a file" + sha256sum $1 else - dep_add_missing + printf '- %s\n' $1 fi } -dep_add_dir() { - [[ -d $1 ]] || die "$0: ${(qqq)1} does not exist or not a directory" - local out - out=$(tar -cvp -C $1 --mtime=1970-01-01 . | sha256sum -) - (( ${(j.|.)pipestatus} )) \ - && die "$0: Failed to checksum directory: ${(qqq)1}" - vars[__check_deps__]+='if { pipeline -d { printf "%s\n" '${(qqq)out}'} fdmove 3 1 pipeline -d { tar -cvp --mtime=1970-01-01 -C '${(qqq)1}$' . } sha256sum -c /proc/self/fd/3 }\n' -} - -dep_add_dir_mtimes() { - [[ -d $1 ]] || die "$0: ${(qqq)1} does not exist or not a directory" - local out - out=$(tar -cvp -C $1 . | sha256sum -) - (( ${(j.|.)pipestatus} )) \ - && die "$0: Failed to checksum directory: ${(qqq)1}" - vars[__check_deps__]+='if { pipeline -d { printf "%s\n" '${(qqq)out}'} fdmove 3 1 pipeline -d { tar -cvp -C '${(qqq)1}$' . } sha256sum -c /proc/self/fd/3 }\n' -} - ifchange() { local arg redo-ifchange "$@" || die "failed to build one or more dependencies: $*" for arg in "$@"; do - vars[__check_deps__]+='if { redo-ifchange '${(qqq)arg}$' }\n' - dep_add_file $arg + vars[__deps__]+=$'\n'$(filehash $arg) done } @@ -183,10 +137,10 @@ for arg in "${(s::Q)$(<$FILE)}"; do if [[ "$arg" != *=* ]]; then - die "$0: Malformed argument: ${(qqq)arg}" + die "Malformed argument: ${(qqq)arg}" fi if (( $+previous[${arg%%=*}] )); then - die "$0: Duplicate argument: ${arg%%=*}" + die "Duplicate argument: ${arg%%=*}" fi previous[${arg%%=*}]=${arg#*=} done @@ -195,12 +149,59 @@ has_previous=1 } +is-unchanged() { + local arg + + parse-previous + + if [[ "${(ko)vars}" != "${(ko)previous}" ]]; then + info "changed: different variables" + info "now: ${(ko)vars}" + info "was: ${(ko)previous}" + return 2 + fi + + for arg in ${(k)vars}; do + if [[ $arg == __deps__ ]]; then + local line + for line in ${(f)${previous[$arg]}}; do + if [[ $line == '- '* ]]; then + if [[ -e $line[4,-1] ]]; then + info "changed: file exists: ${(qqq)line[4,-1]}" + return 4 + fi + else + if ! sha256sum -c <<<$line; then + info "changed: file changed: ${(qqq)line#* }" + return 5 + fi + fi + done + elif [[ $vars[$arg] != $previous[$arg] ]]; then + info "changed: variable $arg" + info "now: ${(qqq)vars[$arg]}" + info "was: ${(qqq)previous[$arg]}" + return 3 + fi + done + return 0 +} + exit-unchanged() { info "$DO:t unchanged, skipping build" cp $FILE $OUT exit 0 } +exit-if-unchanged() { + if is-unchanged; then + exit-unchanged + else + print-meta > $FILE.new + [[ -f $FILE ]] && cp $FILE $FILE.prev + fi +} + depend() { # TODO: edit this comment copied over from confz # usage: require [] [-- ] @@ -281,12 +282,7 @@ autoload_functions decode_args start-info - dep_add_file $DO - dep_add_file common.zsh - parse-previous - if (($+previous[__check_deps__])) && execlineb -c $previous[__check_deps__]; then - exit-unchanged - fi + vars[__deps__]=$(sha256sum $DO common.zsh) main || exit $? finish fi === modified file 'functions/clone-build-dir' --- functions/clone-build-dir 2017-12-12 17:03:06 +0000 +++ functions/clone-build-dir 2017-11-30 21:40:46 +0000 @@ -1,4 +1,3 @@ -init-build-dir-vars while grep -q "^overlay ${vars[build_dir]:A} overlay" /proc/mounts; do umount ${vars[build_dir]:A} || die "Failed to umount ${(qqq)vars[build_dir]}" done === added file 'functions/hash-build-dir' --- functions/hash-build-dir 1970-01-01 00:00:00 +0000 +++ functions/hash-build-dir 2017-11-30 21:49:11 +0000 @@ -0,0 +1,9 @@ +if [[ -d $vars[build_dir] ]]; then + local sum + sum=$(pax -w $vars[build_dir] | sha256sum -) \ + || die "Failed to checksum build directory ${(qqq)vars[build_dir]}" + vars[sha256sum]=${sum%% *} +else + vars[sha256sum]=- +fi +# vim: fileencoding=utf8 ft=zsh noet sw=4 ts=4 sts=4 === added file 'functions/hash-build-files' --- functions/hash-build-files 1970-01-01 00:00:00 +0000 +++ functions/hash-build-files 2017-11-30 21:49:11 +0000 @@ -0,0 +1,9 @@ +if [[ -d $vars[build_dir] ]]; then + local sum + sum=$(sha256sum $vars[build_dir]/**/*(.D) | sha256sum -) \ + || die "Failed to checksum files in build directory ${(qqq)vars[build_dir]}" + vars[sha256sum]=${sum%% *} +else + vars[sha256sum]=- +fi +# vim: fileencoding=utf8 ft=zsh noet sw=4 ts=4 sts=4 === added file 'functions/hash-changes' --- functions/hash-changes 1970-01-01 00:00:00 +0000 +++ functions/hash-changes 2017-11-30 21:40:46 +0000 @@ -0,0 +1,9 @@ +if [[ -d $vars[changes_dir] ]]; then + local sum + sum=$(pax -w $vars[changes_dir] | sha256sum -) \ + || die "Failed to checksum changes directory ${(qqq)vars[changes_dir]}" + vars[sha256sum]=${sum%% *} +else + vars[sha256sum]=- +fi +# vim: fileencoding=utf8 ft=zsh noet sw=4 ts=4 sts=4 === removed file 'functions/output-dir' --- functions/output-dir 2017-12-12 17:03:06 +0000 +++ functions/output-dir 1970-01-01 00:00:00 +0000 @@ -1,14 +0,0 @@ -while grep -q "^[^ ]\\+ ${1:A} " /proc/mounts; do - umount ${1:A} || die "$0: Failed to umount ${(qqq)1}" -done - -local -a remove -[[ -e $1 ]] && remove+=( $1/*(DN) ) -if (($#remove)); then - rm -rf $remove || die "$0: Failed to clean output directory: ${(qqq)1}" -fi - -mkdir -p $1 || die "Failed to create output directory: ${(qqq)1}" - -add_finish_hook dep_add_dir $1 -# vim: fileencoding=utf8 ft=zsh noet sw=4 ts=4 sts=4