-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_and_test.sh
More file actions
executable file
·121 lines (102 loc) · 3.48 KB
/
build_and_test.sh
File metadata and controls
executable file
·121 lines (102 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Script to build and test simLandIceMeshGen with and without SimModSuite
set -e # Exit on any error
usage="Usage: ./build_and_test.sh /path/to/simLandIceMeshGen /path/to/simmodsuite/env /path/to/omegah/install [--asan]
--asan Enable AddressSanitizer for memory error and leak detection"
# Parse command line arguments
USE_ASAN=false
ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
--asan)
USE_ASAN=true
shift
;;
-h|--help)
echo "$usage"
exit 0
;;
*)
ARGS+=("$1")
shift
;;
esac
done
# Check required arguments
[[ ${#ARGS[@]} -ne 3 ]] && echo "$usage" && exit 1
PROJECT_DIR=$PWD
SOURCE_DIR=${ARGS[0]}
SIMMODSUITE_ENV=${ARGS[1]}
[[ ! -d $SOURCE_DIR ]] && "SOURCE_DIR ${SOURCE_DIR} does not exist... exiting" && exit 1
[[ ! -e $SIMMODSUITE_ENV ]] && "SIMMODSUITE_ENV ${SIMMODSUITE_ENV} does not exist... exiting" && exit 1
OMEGAH_DIR=${ARGS[2]}
[[ ! -d $OMEGAH_DIR ]] && "OMEGAH_DIR ${OMEGAH_DIR} does not exist... exiting" && exit 1
export CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH:$OMEGAH_DIR
echo "=== Building and Testing simLandIceMeshGen ==="
echo "Project directory: $PROJECT_DIR"
echo "Source directory: $SOURCE_DIR"
echo
# Function to clean build directory
clean_build() {
local build_dir=$1
if [ -d "$build_dir" ]; then
echo "Cleaning $build_dir..."
rm -rf "$build_dir"
fi
}
# Function to build and test
build_and_test() {
local config=$1
local build_dir=$2
local cmake_options=$3
local env_setup=$4
# Add AddressSanitizer options if requested
cxxflags=""
if [ "$USE_ASAN" = true ]; then
config="$config (with AddressSanitizer)"
cxxflags="-fsanitize=address -fsanitize=leak -fno-omit-frame-pointer -g"
build_dir="${build_dir}_asan"
fi
echo "=== Building with $config ==="
# Clean previous build
clean_build "$build_dir"
# Configure
echo "Configuring..."
if [ -n "$env_setup" ]; then
set -x
eval "$env_setup && cmake -S \"$SOURCE_DIR\" -B \"$build_dir\" $cmake_options -DCMAKE_CXX_FLAGS=\"${cxxflags}\""
set +x
else
set -x
cmake -S "$SOURCE_DIR" -B "$build_dir" $cmake_options -DCMAKE_CXX_FLAGS="${cxxflags}"
set +x
fi
# Build
echo "Building..."
cmake --build "$build_dir"
# Test
echo "Running tests..."
if [ -n "$env_setup" ]; then
eval "$env_setup && ctest --test-dir \"$build_dir\" --output-on-failure"
else
ctest --test-dir "$build_dir" --output-on-failure
fi
echo "✅ $config build and test completed successfully"
echo
}
# Build without SimModSuite
echo "🔧 Testing WITHOUT SimModSuite support..."
build_and_test "SimModSuite DISABLED" "$PROJECT_DIR/buildSimLandIceMeshGen" "-DUSE_SIMMODSUITE=OFF"
# Build with SimModSuite
echo "🔧 Testing WITH SimModSuite support..."
build_and_test "SimModSuite ENABLED" "$PROJECT_DIR/buildSimLandIceMeshGenWithSim" "-DUSE_SIMMODSUITE=ON" "source ${SIMMODSUITE_ENV}"
echo "🎉 All builds and tests completed successfully!"
echo
echo "Summary:"
if [ "$USE_ASAN" = true ]; then
echo "- SimModSuite DISABLED (with AddressSanitizer): buildSimLandIceMeshGen_asan/"
echo "- SimModSuite ENABLED (with AddressSanitizer): buildSimLandIceMeshGenWithSim_asan/"
else
echo "- SimModSuite DISABLED: buildSimLandIceMeshGen/"
echo "- SimModSuite ENABLED: buildSimLandIceMeshGenWithSim/"
fi