diff --git a/contrib/devtools/build_cmake.sh b/contrib/devtools/build_cmake.sh --- a/contrib/devtools/build_cmake.sh +++ b/contrib/devtools/build_cmake.sh @@ -8,8 +8,10 @@ : "${BUILD_DIR:=${TOPLEVEL}/build}" function usage() { - echo "Usage: $0 [--Werror]" - echo "Build the default target using cmake and ninja." + echo "Usage: $0 [--Werror] [targets]" + echo "Build the targets using cmake and ninja." + echo "If no target is provided the default (all) target is built." + echo echo "Options:" echo " --Werror: add -Werror to the compiler flags" echo "Environment variables:" @@ -27,6 +29,7 @@ read -a CMAKE_FLAGS <<< "${CMAKE_FLAGS}" +TARGETS=() while [[ $# -gt 0 ]]; do case $1 in --Werror) @@ -37,13 +40,32 @@ shift ;; *) - usage - exit 1 + TARGETS+=("$1") + shift ;; esac done cmake -GNinja .. "${CMAKE_FLAGS[@]}" +# If valid targets are given, use them, otherwise default to "all". +if [ ${#TARGETS[@]} -eq 0 ]; then + TARGETS=("all") +else + mapfile -t VALID_TARGETS < <(ninja -t targets all | cut -d ':' -f 1) + # "all" is not part of the targets exported by ninja, so add it. + VALID_TARGETS+=("all") + IFS=" " + for TARGET in "${TARGETS[@]}" + do + # The array prints as a space delimited word list, surround the target with + # spaces to avoid partial match. + if [[ ! " ${VALID_TARGETS[*]} " =~ \ ${TARGET}\ ]]; then + echo "Trying to build an invalid target: ${TARGET}" + exit 2 + fi + done +fi + # Run build -ninja +ninja "${TARGETS[@]}" diff --git a/contrib/teamcity/build-configurations.sh b/contrib/teamcity/build-configurations.sh --- a/contrib/teamcity/build-configurations.sh +++ b/contrib/teamcity/build-configurations.sh @@ -212,7 +212,7 @@ "-DSECP256K1_ENABLE_MODULE_ECDH=ON" "-DSECP256K1_ENABLE_MODULE_MULTISET=ON" ) - CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh --Werror + CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh secp256k1 --Werror ninja check-secp256k1 @@ -220,7 +220,7 @@ CMAKE_FLAGS+=( "-DSECP256K1_ENABLE_ENDOMORPHISM=ON" ) - CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh --Werror + CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh secp256k1 --Werror ninja check-secp256k1 @@ -231,7 +231,7 @@ "-DSECP256K1_ENABLE_JNI=ON" "-DUSE_JEMALLOC=OFF" ) - CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh --Werror + CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh secp256k1 --Werror ninja check-secp256k1-java ;; @@ -314,7 +314,7 @@ "-DSECP256K1_ENABLE_MODULE_ECDH=ON" "-DSECP256K1_ENABLE_MODULE_MULTISET=ON" ) - CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh --Werror + CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh bitcoin-bench --Werror ./src/bench/bitcoin-bench -printer=junit > junit_results_bench.xml ninja bench-secp256k1 ;; @@ -462,7 +462,7 @@ ;; check-seeds) - "${DEVTOOLS_DIR}"/build_cmake.sh + "${DEVTOOLS_DIR}"/build_cmake.sh bitcoind bitcoin-cli # Run on different ports to avoid a race where the rpc port used in the # first run may not be closed in time for the second to start. SEEDS_DIR="${TOPLEVEL}"/contrib/seeds