* lib/ylwrap: Now chdir into the temporary directory `$dirname' only to run the wrapped program. This will be useful mostly for useful refactorings. (handle_renaming, dos_fix_yacc_filenames): Update. * tests/ylwrap-chdir-back-fail.test: Update. * tests/silent-yacc-headers.test: Extend. --- ChangeLog | 10 ++++++++++ lib/ylwrap | 25 ++++++++++--------------- tests/silent-yacc-headers.test | 28 ++++++++++++++++++++++++++++ tests/ylwrap-chdir-back-fail.test | 14 +------------- 4 files changed, 49 insertions(+), 28 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 6f5f573..d378296 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2011-05-05 Stefano Lattarini <stefano.lattar...@gmail.com> + ylwrap: go into tempdir only when running wrapped program + * lib/ylwrap: Now chdir into the temporary directory `$dirname' + only to run the wrapped program. This will be useful mostly for + useful refactorings. + (handle_renaming, dos_fix_yacc_filenames): Update. + * tests/ylwrap-chdir-back-fail.test: Update. + * tests/silent-yacc-headers.test: Extend. + +2011-05-05 Stefano Lattarini <stefano.lattar...@gmail.com> + ylwrap: get rid of the loop on "FROM TARGET" couples * lib/ylwrap: The new shape in which the previous refactoring have left the code allows us to get rid on the confusing loop on the diff --git a/lib/ylwrap b/lib/ylwrap index 9f9190c..4e6dd0f 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -68,7 +68,7 @@ dos_fix_yacc_filenames () { test $wrapped = yacc || return 0 if test -z "$y_tab_nodot"; then - if test -f y_tab.c || test -f y_tab.h; then + if test -f $dirname/y_tab.c || test -f $dirname/y_tab.h; then y_tab_nodot=yes else y_tab_nodot=no @@ -86,8 +86,9 @@ handle_renaming () { from=$1 ofrom=$from + target=$2 dos_fix_yacc_filenames - if test ! -f $from; then + if test ! -f $dirname/$from; then # When using yacc, if the `-d' option is not used, we don't want an # error when the header file is "missing". Similarly, if `-v' is not # used, we don't want an error when the `y.output' file is "missing". @@ -101,13 +102,6 @@ handle_renaming () return fi - # If $2 is an absolute path name, then just use that, - # otherwise prepend `../'. - case $2 in - [\\/]* | ?:[\\/]*) target=$2;; - *) target=../$2;; - esac - # We do not want to overwrite a header file if it hasn't # changed. This avoid useless recompilations. However the # parser itself (the first file) should always be updated, @@ -134,18 +128,18 @@ handle_renaming () # Solaris yacc seems not to generate such include guards either. # So, how much is this code still relevant today? FROM=`tr_cpp "$from"` - TARGET=`tr_cpp "$2"` + TARGET=`tr_cpp "$target"` - sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \ - -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? + sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$target," \ + -e "s,$FROM,$TARGET," $dirname/"$from" >"$target" || ret=$? # Check whether header files must be updated. if test $wrapped = yacc && test $ofrom = y.tab.h; then if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then - echo "$2" is unchanged + echo "$realtarget is unchanged" rm -f "$target" else - echo updating "$2" + echo "updating $realtarget" mv -f "$target" "$realtarget" fi fi @@ -244,13 +238,14 @@ trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 mkdir $dirname || exit 1 -cd $dirname || exit 1 +cd $dirname || exit 1 case $# in 0) "$prog" "$input" ;; *) "$prog" "$@" "$input" ;; esac ret=$? +cd "$ocwd" || exit 1 test $ret -eq 0 || eval "$do_exit" diff --git a/tests/silent-yacc-headers.test b/tests/silent-yacc-headers.test index f8dd99e..dd146c1 100755 --- a/tests/silent-yacc-headers.test +++ b/tests/silent-yacc-headers.test @@ -92,6 +92,20 @@ grep 'updating *parse\.h' stdout grep 'YACC *bar-parse\.c' stdout grep 'updating *bar-parse\.h' stdout +# Check dummy header updating. +$sleep +touch parse.y +$MAKE parse.h bar-parse.h >stdout || { cat stdout; Exit 1; } +cat stdout + +$EGREP ' (-c|-d|-o)' stdout && Exit 1 +$EGREP '(mv|ylwrap) ' stdout && Exit 1 + +grep 'YACC *parse\.c' stdout +grep '^parse\.h *is unchanged' stdout +grep 'YACC *bar-parse\.c' stdout +grep '^bar-parse\.h *is unchanged' stdout + # Cleaning and then rebuilding with the same V flag (and without # removing the generated sources in between) shouldn't trigger a # different set of rules. @@ -123,6 +137,20 @@ grep 'updating *parse\.h' stdout grep 'YACC *bar-parse\.c' stdout grep 'updating *bar-parse\.h' stdout +# Check dummy header updating. +$sleep +touch parse.y +$MAKE parse.h bar-parse.h >stdout || { cat stdout; Exit 1; } +cat stdout + +$EGREP ' (-c|-d|-o)' stdout && Exit 1 +$EGREP '(mv|ylwrap) ' stdout && Exit 1 + +grep 'YACC *parse\.c' stdout +grep '^parse\.h *is unchanged' stdout +grep 'YACC *bar-parse\.c' stdout +grep '^bar-parse\.h *is unchanged' stdout + # Ensure a truly clean rebuild. $MAKE maintainer-clean diff --git a/tests/ylwrap-chdir-back-fail.test b/tests/ylwrap-chdir-back-fail.test index 6dc9483..5212880 100755 --- a/tests/ylwrap-chdir-back-fail.test +++ b/tests/ylwrap-chdir-back-fail.test @@ -42,22 +42,10 @@ chmod a+x fake-yacc mkdir foodir cd foodir -# ylwrap should succeed ... $SHELL "$ocwd"/ylwrap --yacc .y "$ocwd"/x.y "$ocwd"/x.c "$ocwd"/fake-yacc \ - 2>"$ocwd"/stderr || { cat "$ocwd"/stderr >&2; Exit 1; } + 2>"$ocwd"/stderr && { cat "$ocwd"/stderr >&2; Exit 1; } cd "$ocwd" cat stderr >&2 -# ... but should also give warnings ... grep "cd: .*$me\.dir/foodir" stderr -chmod u+x foodir -# .. and not remove the temporary directory ... -ls -l foodir/ylwrap[0-9]* -test -d foodir/ylwrap[0-9]* -# ... but still, ylwrap should correctly move/copy the generated C -# source and header files into their final location. -cat x.c -cat x.h -test `cat x.c` = foobar -test `cat x.h` = zardoz : -- 1.7.2.3