Skip to content

Commit

Permalink
h5 compiler wrappers now pass all arguments passed to it to the compi…
Browse files Browse the repository at this point in the history
…le line (HDFGroup#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
  • Loading branch information
brtnfld authored and lrknox committed Feb 14, 2024
1 parent c6a0abd commit f57a0db
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 38 deletions.
16 changes: 6 additions & 10 deletions bin/h5cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ host_os="@host_os@"

prog_name="`basename $0`"

allargs=""
misc_args=""
compile_args=""
libraries=""
link_args=""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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=\(.*\)'`"
Expand Down Expand Up @@ -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" : '.*\(\..*\)'`
Expand Down Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions c++/examples/testh5c++.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -134,16 +136,38 @@ int main (void)
}
EOF

# Generate args:
# An application main that test misc command line arguments being passed.
cat > $args <<EOF
#include <string>
#include <iostream>
#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'
}


Expand Down Expand Up @@ -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
##############################################################################
Expand Down
16 changes: 6 additions & 10 deletions c++/src/h5c++.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ host_os="@host_os@"

prog_name="`basename $0`"

allargs=""
misc_args=""
compile_args=""
libraries=""
link_args=""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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=\(.*\)'`"
Expand All @@ -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" : '.*\(\..*\)'`
Expand Down Expand Up @@ -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
Expand Down
79 changes: 77 additions & 2 deletions examples/testh5cc.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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
Expand Down Expand Up @@ -277,16 +279,85 @@ main (void)
}
EOF

# Generate HDF5 v1.14 Main Program:
# This makes unique V1.14 API calls.
cat > $v114main <<EOF
/* This is a V1.14 API calls example Program. */
#include "hdf5.h"
#define H5FILE_NAME "tmp.h5"
#define SPACE1_RANK 3
int
main (void)
{
hid_t sid; /* Dataspace ID */
hid_t fapl = -1; /* File access property list ID */
int rank; /* Logical rank of dataspace */
hsize_t dims[] = {3, 3, 15};
size_t sbuf_size=0;
herr_t ret; /* Generic return value */
hsize_t start[] = {0, 0, 0};
hsize_t stride[] = {2, 5, 3};
hsize_t count[] = {2, 2, 2};
hsize_t block[] = {1, 3, 1};
/* Create the file access property list */
fapl = H5Pcreate(H5P_FILE_ACCESS);
/* Set low/high bounds in the fapl */
ret = H5Pset_libver_bounds(fapl, H5F_LIBVER_EARLIEST,
H5F_LIBVER_LATEST);
/* Create the dataspace */
sid = H5Screate_simple(SPACE1_RANK, dims, NULL);
/* Set the hyperslab selection */
ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, start, stride, count, block);
/* Encode simple dataspace in a buffer with the fapl setting */
ret = H5Sencode(sid, NULL, &sbuf_size, fapl);
/* Encode simple dataspace in a buffer with the fapl setting */
ret = H5Sencode2(sid, NULL, &sbuf_size, fapl);
printf("HDF5 C program created with V1.14 API ran successfully. ");
/* "File %s generated.\n", H5FILE_NAME);
remove(H5FILE_NAME); */
return 0;
}
EOF

# Generate args:
# An application main that test misc command line arguments being passed.
cat > $args <<EOF
#include "hdf5.h"
#define H5FILE_NAME "check_args.h5"
int
main (void)
{
char c = SGL_QUOTE; /* 'H' */
char *s = DBL_QUOTE; /* "HDF" */
int val = MISC; /* 42 */
hid_t file; /* file and dataset handles */
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
H5Fclose(file);
printf("HDF5 C Sample program ran successfully. File %s generated.\n", H5FILE_NAME);
remove(H5FILE_NAME);
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 71 characters
# beginning with the word "Testing".
#
TESTING() {
SPACES=" "
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
echo "Testing $* $SPACES" | cut -c1-71 | tr -d '\012'
}


Expand Down Expand Up @@ -450,6 +521,10 @@ else
TOOLTEST $v112main
fi

# Group 6: # 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
##############################################################################
Expand Down
35 changes: 31 additions & 4 deletions fortran/examples/testh5fc.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ myos=`uname -s`
myhostnama=`uname -n`

# Generate some source files and library for tests.
suffix=f90 # source file suffix
suffix=F90 # source file suffix
hdf5main=${H5TOOL}_hdf5main.$suffix
hdf5main_o=${H5TOOL}_hdf5main.o
appmain=${H5TOOL}_appmain.$suffix
appmain_o=${H5TOOL}_appmain.o
args=${H5TOOL}_args.$suffix
args_o=${H5TOOL}_args.o
prog1=${H5TOOL}_prog1.$suffix
prog1_o=${H5TOOL}_prog1.o
prog2=${H5TOOL}_prog2.$suffix
Expand Down Expand Up @@ -106,7 +108,7 @@ cat > $hdf5main <<EOF
IMPLICIT NONE
CHARACTER(LEN=8), PARAMETER :: filename = "apptmp.h5" ! File name
CHARACTER(LEN=9), PARAMETER :: filename = "apptmp.h5" ! File name
INTEGER(HID_T) :: file_id ! File identifier
INTEGER :: error ! Error flag
Expand All @@ -118,17 +120,38 @@ cat > $hdf5main <<EOF
END PROGRAM FILEEXAMPLE
EOF

# Generate an args Main Program:
# An application main that test misc command line arguments being passed.
cat > $args <<EOF
PROGRAM ARGS
USE HDF5 ! This module contains all necessary modules
IMPLICIT NONE
CHARACTER(LEN=1), PARAMETER :: chr1 = SGL_QUOTE ! 'H'
CHARACTER(LEN=3), PARAMETER :: chr3 = DBL_QUOTE ! "HDF"
INTEGER, PARAMETER :: val = MISC ! 42
CHARACTER(LEN=9), PARAMETER :: filename = "argtmp.h5" ! File name
INTEGER(HID_T) :: file_id ! File identifier
INTEGER :: error ! Error flag
CALL h5open_f (error)
CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
CALL h5fclose_f(file_id, error)
CALL h5close_f(error)
END PROGRAM ARGS
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 73 characters
# beginning with the word "Testing".
#
TESTING() {
SPACES=" "
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
echo "Testing $* $SPACES" | cut -c1-73 | tr -d '\012'
}


Expand Down Expand Up @@ -199,6 +222,10 @@ $RANLIB $applib
TOOLTEST $appmain $applib
TOOLTEST $appmain_o $applib

# 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

# No preprocess test since -E is not a common option for Fortran compilers.

##############################################################################
Expand Down
Loading

0 comments on commit f57a0db

Please sign in to comment.