-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_plugin.sh
executable file
·120 lines (104 loc) · 3.36 KB
/
build_plugin.sh
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
#!/bin/bash
## Copyright © 2024 Seagate Technology LLC and/or its Affiliates
## Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
set -e #< Exit on error.
set -u #< Prohibit undefined variables.
if [[ $# > 0 && ($1 == "/?" || $1 == "-h" || $1 == "--help") ]]
then
echo "Usage: $(basename "$0") [--no-tests] [--debug] [<cmake-generation-args>...]"
echo " --debug Compile using Debug configuration (without optimizations) instead of Release."
exit
fi
# Make the build dir at the same level as the parent dir of this script, suffixed with "-build".
BASE_DIR=$(readlink -f "$(dirname "$0")") #< Absolute path to this script's dir.
BUILD_DIR="$BASE_DIR-build"
if [[ $# > 0 && $1 == "--no-tests" ]]
then
shift
NO_TESTS=1
else
NO_TESTS=0
fi
if [[ $# > 0 && $1 == "--debug" ]]
then
shift
BUILD_TYPE=Debug
else
BUILD_TYPE=Release
fi
case "$(uname -s)" in #< Check if running in Windows from Cygwin/MinGW.
CYGWIN*|MINGW*)
GEN_OPTIONS=( -G "MinGW Makefiles" -DCMAKE_C_COMPILER="C:/msys64/ucrt64/bin/gcc.exe" -DCMAKE_CXX_COMPILER="C:/msys64/ucrt64/bin/g++.exe" )
BASE_DIR=$(cygpath -w "$BASE_DIR") #< Windows-native cmake requires Windows path.
BUILD_OPTIONS=()
if [[ $BUILD_TYPE == Release ]]
then
BUILD_OPTIONS+=( --config $BUILD_TYPE )
fi
;;
*) # Assume Linux; use Ninja if it is available on PATH.
if which ninja >/dev/null
then
GEN_OPTIONS=( -GNinja ) #< Generate for Ninja and gcc; Ninja uses all CPU cores.
BUILD_OPTIONS=()
else
GEN_OPTIONS=() #< Generate for GNU make and gcc.
BUILD_OPTIONS=( -- -j ) #< Use all available CPU cores.
fi
if [[ $BUILD_TYPE == Release ]]
then
GEN_OPTIONS+=( -DCMAKE_BUILD_TYPE=$BUILD_TYPE )
fi
;;
esac
(set -x #< Log each command.
# rm -rf "$BUILD_DIR/"
)
# Build source plugin
SOURCE_DIR="$BASE_DIR/src"
PLUGIN_NAME="cloudfuse_plugin"
(set -x #< Log each command.
mkdir -p "$BUILD_DIR/$PLUGIN_NAME"
cd "$BUILD_DIR/$PLUGIN_NAME"
cmake "$SOURCE_DIR" `# allow empty array #` ${GEN_OPTIONS[@]+"${GEN_OPTIONS[@]}"} "$@"
cmake --build . `# allow empty array #` ${BUILD_OPTIONS[@]+"${BUILD_OPTIONS[@]}"}
)
ARTIFACT=$(find "$BUILD_DIR" -name "$PLUGIN_NAME.dll" -o -name "lib$PLUGIN_NAME.so")
if [ ! -f "$ARTIFACT" ]
then
echo "ERROR: Failed to build $PLUGIN_NAME."
exit 64
fi
echo ""
echo "Built: $ARTIFACT"
echo ""
# Build unit tests
SOURCE_DIR="$BASE_DIR/src/unit_tests"
UNIT_TESTS="unit_tests"
(set -x #< Log each command.
mkdir -p "$BUILD_DIR/$UNIT_TESTS"
cd "$BUILD_DIR/$UNIT_TESTS"
cmake "$SOURCE_DIR" `# allow empty array #` ${GEN_OPTIONS[@]+"${GEN_OPTIONS[@]}"} "$@"
cmake --build . `# allow empty array #` ${BUILD_OPTIONS[@]+"${BUILD_OPTIONS[@]}"}
)
ARTIFACT=$(find "$BUILD_DIR" -name "analytics_plugin_ut.exe" -o -name "analytics_plugin_ut")
if [ ! -f "$ARTIFACT" ]
then
echo "ERROR: Failed to build $UNIT_TESTS."
exit 64
fi
echo ""
echo "Built: $ARTIFACT"
echo ""
# Run unit tests if needed.
if [[ $NO_TESTS == 1 ]]
then
echo "NOTE: Unit tests were not run."
else
(set -x #< Log each command.
cd "$BUILD_DIR/unit_tests"
ctest --output-on-failure -C $BUILD_TYPE
)
fi
echo ""
echo "Samples built successfully, see the binaries in $BUILD_DIR"