From 3a3501df2d35babb508fa4944690c564a43c22f5 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Tue, 30 Jan 2024 12:20:58 -0600 Subject: h5 compiler wrappers now pass all arguments passed to it to the compile line (#3954) * The issue was that the "allargs" variable was not being used in the final command of the compiler wrapper. Any entries containing an escaped quote (\", \') or other non-matching argument (*) would not be passed to the compile line. I have fixed this problem by ensuring all arguments passed to the compiler wrapper are now included in the compile line. * added testing for compiler wrappers --- bin/h5cc.in | 16 ++++++---------- c++/examples/testh5c++.sh.in | 32 ++++++++++++++++++++++++++++++-- c++/src/h5c++.in | 16 ++++++---------- examples/testh5cc.sh.in | 32 ++++++++++++++++++++++++++++++-- fortran/examples/testh5fc.sh.in | 35 +++++++++++++++++++++++++++++++---- fortran/src/h5fc.in | 16 ++++++---------- 6 files changed, 109 insertions(+), 38 deletions(-) diff --git a/bin/h5cc.in b/bin/h5cc.in index e3dc988..e4d4368 100644 --- a/bin/h5cc.in +++ b/bin/h5cc.in @@ -62,7 +62,7 @@ host_os="@host_os@" prog_name="`basename $0`" -allargs="" +misc_args="" compile_args="" libraries="" link_args="" @@ -202,7 +202,6 @@ for arg in $@ ; do case "$arg" in -c) - allargs="$allargs $arg" compile_args="$compile_args $arg" if test "x$do_link" = "xyes" -a -n "$output_file"; then @@ -213,7 +212,6 @@ for arg in $@ ; do dash_c="yes" ;; -o) - allargs="$allargs $arg" dash_o="yes" if test "x$dash_c" = "xyes"; then @@ -225,14 +223,12 @@ for arg in $@ ; do fi ;; -E|-M|-MT) - allargs="$allargs $arg" compile_args="$compile_args $arg" dash_c="yes" do_link="no" ;; -l*) libraries=" $libraries $arg " - allargs="$allargs $arg" ;; -prefix=*) prefix="`expr "$arg" : '-prefix=\(.*\)'`" @@ -264,14 +260,14 @@ for arg in $@ ; do ;; *\"*) qarg="'"$arg"'" - allargs="$allargs $qarg" + misc_args="$misc_args $qarg" ;; *\'*) - qarg='\"'"$arg"'\"' - allargs="$allargs $qarg" + qarg='"'"$arg"'"' + misc_args="$misc_args $qarg" ;; *) - allargs="$allargs $qarg" + misc_args="$misc_args $qarg" if test -s "$arg"; then ext=`expr "$arg" : '.*\(\..*\)'` @@ -313,7 +309,7 @@ if test "x$do_compile" = "xyes"; then compile_args="-c $compile_args" fi - $SHOW $CC -I$includedir $H5BLD_CPPFLAGS $CPPFLAGS $H5BLD_CFLAGS $CFLAGS $compile_args + $SHOW $CC -I$includedir $H5BLD_CPPFLAGS $CPPFLAGS $H5BLD_CFLAGS $CFLAGS $misc_args $compile_args status=$? if test "$status" != "0"; then diff --git a/c++/examples/testh5c++.sh.in b/c++/examples/testh5c++.sh.in index 84c7752..f3a973c 100644 --- a/c++/examples/testh5c++.sh.in +++ b/c++/examples/testh5c++.sh.in @@ -47,6 +47,8 @@ prog1_o=${H5TOOL}_prog1.o prog2=${H5TOOL}_prog2.$suffix prog2_o=${H5TOOL}_prog2.o applib=libapp${H5TOOL}.a +args=${H5TOOL}_args.$suffix +args_o=${H5TOOL}_args.o # short hands # Caution: if some *.h5 files must be cleaned here, list them by names. @@ -134,16 +136,38 @@ int main (void) } EOF +# Generate args: +# An application main that test misc command line arguments being passed. +cat > $args < +#include +#include "H5Cpp.h" +#ifndef H5_NO_NAMESPACE +using namespace H5; +#endif + +const H5std_string FILE_NAME( "args.h5" ); + +int main (void) +{ + char c = SGL_QUOTE; // 'H' + char *s = DBL_QUOTE; // "HDF" + int val = MISC; // 42 + + H5File file( FILE_NAME, H5F_ACC_TRUNC ); + return 0; +} +EOF # Parse option # None -# Print a line-line message left justified in a field of 70 characters +# Print a line-line message left justified in a field of 74 characters # beginning with the word "Testing". # TESTING() { SPACES=" " - echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' + echo "Testing $* $SPACES" | cut -c1-74 | tr -d '\012' } @@ -231,6 +255,10 @@ echo "***"Just preprocess, no compile, no link. TOOLTEST -E $hdf5main TOOLTEST -E $appmain $prog1 $prog2 +# HDF5 program that depends on input args. +echo "***"Simple Compile and Link in one step with user-supplied arguments. +TOOLTEST -DSGL_QUOTE=\'H\' -DDBL_QUOTE=\"HDF\" -DMISC=42 $args + ############################################################################## # END ############################################################################## diff --git a/c++/src/h5c++.in b/c++/src/h5c++.in index 078fa73..e666ba9 100644 --- a/c++/src/h5c++.in +++ b/c++/src/h5c++.in @@ -60,7 +60,7 @@ host_os="@host_os@" prog_name="`basename $0`" -allargs="" +misc_args="" compile_args="" libraries="" link_args="" @@ -198,7 +198,6 @@ for arg in $@ ; do case "$arg" in -c) - allargs="$allargs $arg" compile_args="$compile_args $arg" if test "x$do_link" = "xyes" -a -n "$output_file"; then @@ -209,7 +208,6 @@ for arg in $@ ; do dash_c="yes" ;; -o) - allargs="$allargs $arg" dash_o="yes" if test "x$dash_c" = "xyes"; then @@ -221,14 +219,12 @@ for arg in $@ ; do fi ;; -E|-M|-MT) - allargs="$allargs $arg" compile_args="$compile_args $arg" dash_c="yes" do_link="no" ;; -l*) libraries=" $libraries $arg " - allargs="$allargs $arg" ;; -prefix=*) prefix="`expr "$arg" : '-prefix=\(.*\)'`" @@ -254,15 +250,15 @@ for arg in $@ ; do ;; *\"*) qarg="'"$arg"'" - allargs="$allargs $qarg" + misc_args="$misc_args $qarg" ;; *\'*) - qarg='\"'"$arg"'\"' - allargs="$allargs $qarg" + qarg='"'"$arg"'"' + misc_args="$misc_args $qarg" ;; *) - allargs="$allargs $qarg" + misc_args="$misc_args $qarg" if [ -s "$arg" ] ; then ext=`expr "$arg" : '.*\(\..*\)'` @@ -300,7 +296,7 @@ if test "x$do_compile" = "xyes"; then compile_args="-c $compile_args" fi - $SHOW $CXX -I$includedir $H5BLD_CPPFLAGS $CPPFLAGS $H5BLD_CXXFLAGS $CXXFLAGS $compile_args + $SHOW $CXX -I$includedir $H5BLD_CPPFLAGS $CPPFLAGS $H5BLD_CXXFLAGS $CXXFLAGS $misc_args $compile_args status=$? if test "$status" != "0"; then diff --git a/examples/testh5cc.sh.in b/examples/testh5cc.sh.in index 40771ec..f95108d 100644 --- a/examples/testh5cc.sh.in +++ b/examples/testh5cc.sh.in @@ -69,6 +69,8 @@ prog1=${H5TOOL}_prog1.$suffix prog1_o=${H5TOOL}_prog1.o prog2=${H5TOOL}_prog2.$suffix prog2_o=${H5TOOL}_prog2.o +args=${H5TOOL}_args.$suffix +args_o=${H5TOOL}_args.o applib=libapp${H5TOOL}.a # short hands @@ -327,16 +329,38 @@ main (void) } EOF +# Generate args: +# An application main that test misc command line arguments being passed. +cat > $args < $hdf5main < $hdf5main < $args <