Skip to content

Commit 167d291

Browse files
chore(build): fix issues with build_standalone.sh (#15105)
## Description This PR updates `build_standalone.sh` to fix certain issues or usability shortcomings I've encountered with it. * Pass `-gdwarf-4` because the `valgrind` version we have on workspaces doesn't support DWARF 5 * Report an error early if `clang`/`gcc` isn't available (e.g. not installed in the workspace) instead of letting CMake fail later with a less clear error message * Add `-v|--valgrind` in the help message (which was already supported, but not documented) * Validate that there are exactly three arguments
1 parent b2d11f1 commit 167d291

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

ddtrace/internal/datadog/profiling/build_standalone.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ compiler_args["cppcheck"]="-DDO_CPPCHECK=ON"
9494
compiler_args["infer"]="-DDO_INFER=ON"
9595
compiler_args["clangtidy"]="-DDO_CLANGTIDY=ON"
9696
compiler_args["clangtidy_cmd"]="-DCLANGTIDY_CMD=${CLANGTIDY_CMD}"
97-
compiler_args["valgrind"]="-DDO_VALGRIND=ON"
97+
compiler_args["valgrind"]="-DDO_VALGRIND=ON -DCMAKE_CXX_FLAGS=-gdwarf-4 -DCMAKE_C_FLAGS=-gdwarf-4"
9898

9999
ctest_args=()
100100

@@ -126,6 +126,12 @@ set_cc() {
126126

127127
# Helper functions for finding the compiler(s)
128128
set_clang() {
129+
# Check that clang is available (required for most build modes)
130+
if [[ -z "$highest_clang" ]] || [[ -z "$highest_clangxx" ]]; then
131+
echo "Error: clang/clang++ not found. This build mode requires clang."
132+
exit 1
133+
fi
134+
129135
if [ -z "${CC:-}" ]; then
130136
export CC=$highest_clang
131137
fi
@@ -139,6 +145,12 @@ set_clang() {
139145
}
140146

141147
set_gcc() {
148+
# Check that gcc/g++ is available (required for most build modes)
149+
if [[ -z "$highest_gcc" ]] || [[ -z "$highest_gxx" ]]; then
150+
echo "Error: gcc/g++ not found. This build mode requires gcc."
151+
exit 1
152+
fi
153+
142154
# Only set CC or CXX if they're not set
143155
if [ -z "${CC:-}" ]; then
144156
export CC=$highest_gcc
@@ -197,7 +209,8 @@ print_help() {
197209
echo " -C --cppcheck Clang + " ${compiler_args["cppcheck"]}
198210
echo " -I --infer Clang + " ${compiler_args["infer"]}
199211
echo " -T --clangtidy Clang + " ${compiler_args["clangtidy"]}
200-
echo " -f, --fanalyze GCC + " ${compiler_args["fanalyzer"]}
212+
echo " -f, --fanalyze GCC + " ${compiler_args["fanalyzer"]}
213+
echo " -v, --valgrind Clang + Valgrind + " ${compiler_args["valgrind"]}
201214
echo " -c, --clang Clang (alone)"
202215
echo " -g, --gcc GCC (alone)"
203216
echo " -- Don't do anything special"
@@ -207,11 +220,9 @@ print_help() {
207220
echo " Release"
208221
echo " RelWithDebInfo"
209222
echo ""
210-
echo "(any possible others, depending on what cmake supports for"
211-
echo "BUILD_TYPE out of the box)"
223+
echo "(any possible others, depending on what cmake supports for BUILD_TYPE out of the box)"
212224
echo ""
213225
echo "Targets:"
214-
echo " all"
215226
echo " all_test (default)"
216227
echo " stack_v2 (also builds dd_wrapper)"
217228
echo " stack_v2_test (also builds dd_wrapper_test)"
@@ -268,7 +279,7 @@ add_compiler_args() {
268279
cmake_args+=(${compiler_args["memory"]})
269280
set_clang
270281
;;
271-
--valgrind)
282+
-v|--valgrind)
272283
cmake_args+=(${compiler_args["valgrind"]})
273284
ctest_args+="-T memcheck"
274285
set_clang
@@ -370,6 +381,12 @@ if [ $# -eq 0 ]; then
370381
exit 1
371382
fi
372383

384+
if [ $# -ne 3 ]; then
385+
echo "Error: Expected exactly 3 arguments"
386+
print_help
387+
exit 1
388+
fi
389+
373390
add_compiler_args "$1"
374391
add_build_mode "$2"
375392
add_target "$3"

0 commit comments

Comments
 (0)