X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=qchess%2Fupdate.sh;h=bec40eacca5f653b0ac81b954050cb62ecffe0a5;hb=707e794d26062516eb4188d1cd2902929613c46b;hp=0edb377391c5d9c6c8e1fcb89475b30574f6a34c;hpb=65d9bb84c7e2dca4a8fac4d92c225ce1bb4f7c52;p=progcomp2013.git diff --git a/qchess/update.sh b/qchess/update.sh old mode 100755 new mode 100644 index 0edb377..bec40ea --- a/qchess/update.sh +++ b/qchess/update.sh @@ -2,8 +2,14 @@ # I still can't believe I am doing this +# This updates the component files from the target, as well as the target from the components +# You can't do that with gnu make, because of the circular dependency +# But this should probably not be used by any sane person + +exit 1 + target=qchess.py -components="piece.py board.py player.py thread_util.py game.py graphics.py main.py" +components="piece.py board.py player.py network.py thread_util.py game.py graphics.py main.py" # The below seems nicer, but doesn't work because things need to be imported in the right order :( #components=$(ls *.py | tr '\t' '\n' | grep -v $target) @@ -13,22 +19,55 @@ footer="# EOF - created from update.sh on $(date)" # If the target was modified more recently than any of the components, update the component file -target_mod=$(stat -c %Y $target) +target_mod=$(stat -c %Y $target 2>/dev/null) + +if [ $? -ne 0 ]; then + merge_required=true +else + merge_required=true -merge_required=false -for f in $components; do - if [ $(stat -c %Y $f) -lt $target_mod ]; then - nawk "/+++ $f +++/, /--- $f ---/" $target | grep -v "+++ $f +++" | grep -v "\--- $f ---" > $f - else - merge_required=true -done + for f in $components; do + + component_mod=$(stat -c %Y $f 2>/dev/null) + if [ $? -ne 0 ]; then + update_required=true + elif [ $component_mod -lt $target_mod ]; then + update_required=true + else + update_required=false + fi + + if $update_required; then + echo "$0 - update $f from $target" + sanity=$(egrep "(+++ $f +++)|(--- $f ---)" $target | wc -l) + if [ $sanity -ne 2 ]; then + $(echo "$0 - $target does not have markers for $f in it!") 1>&2 + exit 1 + fi + cp $f $f~ + new_contents=$(nawk "/+++ $f +++/, /--- $f ---/" $target | grep -v "+++ $f +++" | grep -v "\--- $f ---") + + echo "$new_contents" > $f + else + echo "$0 - $f is newer than $target" + merge_required=true + fi + done + + +fi +# If any components were modified more recently than the target, merge the components into the target if $merge_required; then echo $header > $target for f in $components; do - cat $components >> $target + echo "$0 - merge $f into $target" + echo "# +++ $f +++ #" >> $target + cat $f >> $target + echo "# --- $f --- #" >> $target done - echo $footer > $target + echo $footer >> $target + chmod u+x $target fi