Skip to content

Commit 3a36c40

Browse files
committed
Add build-pfunit.sh script missed in #50
1 parent 01f8e4b commit 3a36c40

1 file changed

Lines changed: 152 additions & 0 deletions

File tree

scripts/build-pfunit.sh

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
PFUNIT_REMOTE_URL="https://github.com/Goddard-Fortran-Ecosystem/pFUnit.git"
6+
PFUNIT_INSTALLED_PATH="" # Path to pFUnit/installed directory
7+
8+
DEFAULT_PFUNIT_SRC_PATH="$(pwd)/pFUnit"
9+
DEFAULT_PFUNIT_VERSION="v4.12.0"
10+
11+
clean=false
12+
build=false
13+
test=false
14+
pfunit_src_path="$DEFAULT_PFUNIT_SRC_PATH"
15+
pfunit_version="$DEFAULT_PFUNIT_VERSION"
16+
17+
help() {
18+
echo "Usage:"
19+
echo " $0 [-h|--help] [-c|--clean] [-b|--build] [-p|--path <path/to/pfunit>] [-v|--version <version>]"
20+
echo ""
21+
echo "ARGS:"
22+
echo " -h | --help Display this help message."
23+
echo " -c | --clean Clean all build artifacts."
24+
echo " -b | --build Build pFUnit."
25+
echo " -t | --test Test a pFUnit installation."
26+
echo " -p | --path Absolute path to the pFUnit src. Defaults to $DEFAULT_PFUNIT_SRC_PATH."
27+
echo " -v | --version <version> The version of pFUnit to install. Defaults to $DEFAULT_PFUNIT_VERSION."
28+
exit 0
29+
}
30+
31+
# check for no input arguments and show help
32+
if [ $# -eq 0 ];
33+
then
34+
help
35+
exit 1
36+
fi
37+
38+
# parse input arguments
39+
while [ $# -gt 0 ] ; do
40+
case $1 in
41+
-h | --help)
42+
help
43+
exit 0
44+
;;
45+
-c | --clean)
46+
clean=true
47+
shift 1
48+
continue
49+
;;
50+
-b | --build)
51+
build=true
52+
shift 1
53+
continue
54+
;;
55+
-t | --test)
56+
test=true
57+
shift 1
58+
continue
59+
;;
60+
-p | --path)
61+
pfunit_src_path=$2
62+
PFUNIT_INSTALLED_PATH="$pfunit_src_path/build/installed"
63+
shift 2
64+
continue
65+
;;
66+
-v | --version)
67+
pfunit_version=$2
68+
shift 2
69+
continue
70+
;;
71+
*)
72+
echo "Invalid option: $1" >&2;
73+
help
74+
exit 1
75+
;;
76+
esac
77+
shift 1
78+
done
79+
80+
# if nothing to do, tell user
81+
if [[ "$build" == "false" && "$clean" == "false" && "$test" == "false" ]]
82+
then
83+
echo "Nothing to do. Please specify at least one of --clean, --build or --test. Use --help for details"
84+
exit 0
85+
fi
86+
87+
# Clean pFUnit build dir
88+
if [ "$clean" == "true" ]
89+
then
90+
if [ -d "$pfunit_src_path/build" ]
91+
then
92+
echo "Cleaning pFUnit build"
93+
rm -rf $pfunit_src_path/build
94+
else
95+
echo "No pFUnit build found at $pfunit_src_path/build. Nothing to clean."
96+
fi
97+
fi
98+
99+
# Build pFUnit
100+
if [ "$build" == "true" ]
101+
then
102+
# Verify the provided pfunit dir
103+
if [ "$pfunit_src_path" == "" ]
104+
then
105+
echo "Building pFUnit requested but no root dir for pFUnit provided. Please provide a path using --path."
106+
exit 0
107+
else
108+
if [ -d "$pfunit_src_path" ]
109+
then
110+
pushd $pfunit_src_path > /dev/null
111+
if [ $(git remote get-url origin) != "$PFUNIT_REMOTE_URL" ]
112+
then
113+
echo "pFUnit source path $pfunit_src_path is not a valid pFUnit clone. Please remove the existing clone or choose a different path."
114+
exit 1
115+
fi
116+
current_pfunit_version=$(git describe --exact-match --tags)
117+
118+
if [ "$current_pfunit_version" != "$pfunit_version" ]
119+
then
120+
echo "pFUnit version $current_pfunit_version found but $pfunit_version was requested. Please switch versions or remove the existing clone."
121+
exit 1
122+
fi
123+
popd > /dev/null
124+
else
125+
mkdir $pfunit_src_path
126+
pushd $pfunit_src_path > /dev/null
127+
echo "Cloning pFUnit from $PFUNIT_REMOTE_PATH"
128+
git clone --branch $pfunit_version $PFUNIT_REMOTE_URL $pfunit_src_path
129+
popd > /dev/null
130+
fi
131+
fi
132+
133+
echo "Building pFUnit from source"
134+
cmake $pfunit_src_path -B $pfunit_src_path/build -DINSTALL_PATH=$PFUNIT_INSTALLED_PATH -DMPI=YES -DCMAKE_Fortran_COMPILER=mpif90 -DOPENMP=YES
135+
cmake --build $pfunit_src_path/build "-j$num_build_threads" --target install
136+
137+
echo ""
138+
echo "Successfully built pFUnit. To use installation, add the following to cmake flags"
139+
echo " -DCMAKE_PREFIX_PATH=$PFUNIT_INSTALLED_PATH"
140+
fi
141+
142+
if [ "$test" == "true" ]
143+
then
144+
if [ "$pfunit_src_path" == "" ]
145+
then
146+
echo "Testing pFUnit requested but no root dir for pFUnit provided. Please provide a path using --path."
147+
exit 0
148+
else
149+
# exclude tests starting with test_derived as these are for a dependency of pFUnit
150+
ctest --test-dir "$pfunit_src_path/build" --output-on-failure -E "(test_derived).*"
151+
fi
152+
fi

0 commit comments

Comments
 (0)