Skip to content

Commit 17f6483

Browse files
committed
Factor out CMake builds from the CI file
Allow reuse and a centralized place for improvements
1 parent 977ebb4 commit 17f6483

File tree

6 files changed

+161
-30
lines changed

6 files changed

+161
-30
lines changed

.github/workflows/ci.yml

+9-30
Original file line numberDiff line numberDiff line change
@@ -374,39 +374,18 @@ jobs:
374374
[[ "$GITHUB_REPOSITORY" =~ "boost-ci" ]] || cp -r boost-ci-cloned/ci .
375375
rm -rf boost-ci-cloned
376376
- name: Setup Boost
377-
env: {B2_DONT_BOOTSTRAP: 1}
377+
env:
378+
B2_DONT_BOOTSTRAP: 1
379+
BCM_GENERATOR: ${{matrix.generator}}
380+
BCM_BUILD_TYPE: ${{matrix.build_type}}
381+
BCM_SHARED_LIBS: ${{matrix.build_shared}}
378382
run: source ci/github/install.sh
379383

380384
- name: Run CMake tests
381-
run: |
382-
cd "$BOOST_ROOT"
383-
mkdir __build_cmake_test__ && cd __build_cmake_test__
384-
cmake -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBOOST_INCLUDE_LIBRARIES=$SELF -DBUILD_SHARED_LIBS=${{matrix.build_shared}} -DBUILD_TESTING=ON -DBoost_VERBOSE=ON ..
385-
cmake --build . --target tests --config ${{matrix.build_type}}
386-
ctest --output-on-failure --build-config ${{matrix.build_type}}
385+
run: ci/cmake_test.sh
387386

388387
- name: Run CMake subdir tests
389-
run: |
390-
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test" # New unified folder
391-
[ -d "$cmake_test_folder" ] || cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_subdir_test"
392-
cd "$cmake_test_folder"
393-
mkdir __build_cmake_subdir_test__ && cd __build_cmake_subdir_test__
394-
cmake -G "${{matrix.generator}}" -DBOOST_CI_INSTALL_TEST=OFF -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBUILD_SHARED_LIBS=${{matrix.build_shared}} ..
395-
cmake --build . --config ${{matrix.build_type}}
396-
ctest --output-on-failure --build-config ${{matrix.build_type}}
397-
398-
- name: Install Library
399-
run: |
400-
cd "$BOOST_ROOT"
401-
mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__
402-
cmake -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBOOST_INCLUDE_LIBRARIES=$SELF -DBUILD_SHARED_LIBS=${{matrix.build_shared}} -DCMAKE_INSTALL_PREFIX=~/.local -DBoost_VERBOSE=ON -DBoost_DEBUG=ON ..
403-
cmake --build . --target install --config ${{matrix.build_type}}
388+
run: ci/cmake_subdir_test.sh
389+
404390
- name: Run CMake install tests
405-
run: |
406-
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test" # New unified folder
407-
[ -d "$cmake_test_folder" ] || cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_install_test"
408-
cd "$cmake_test_folder"
409-
mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__
410-
cmake -G "${{matrix.generator}}" -DBOOST_CI_INSTALL_TEST=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBUILD_SHARED_LIBS=${{matrix.build_shared}} -DCMAKE_PREFIX_PATH=~/.local ..
411-
cmake --build . --config ${{matrix.build_type}}
412-
ctest --output-on-failure --build-config ${{matrix.build_type}}
391+
run: ci/cmake_install_test.sh

ci/cmake_build.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#! /bin/bash
2+
#
3+
# Copyright 2022 Alexander Grund
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# (See accompanying file LICENSE_1_0.txt or copy at
6+
# http://www.boost.org/LICENSE_1_0.txt)
7+
#
8+
# Bash script to perform a CMake build of Boost
9+
#
10+
# Requires the following env vars:
11+
# - BOOST_ROOT & SELF (setup step)
12+
# - BCM_GENERATOR
13+
# - BCM_BUILD_TYPE
14+
# - BCM_SHARED_LIBS
15+
# - BCM_ARGS
16+
# - BCM_TARGET
17+
18+
set -e
19+
20+
. "$(dirname "${BASH_SOURCE[0]}")"/set_num_jobs.sh
21+
22+
cd "$BOOST_ROOT"
23+
buildDir=__build
24+
while [ -d "$buildDir" ]; do
25+
buildDir="${buildDir}_2"
26+
done
27+
mkdir "$buildDir" && cd "$buildDir"
28+
29+
echo "Configuring..."
30+
set -x
31+
cmake -G "$BCM_GENERATOR" -DCMAKE_BUILD_TYPE=$BCM_BUILD_TYPE -DBUILD_SHARED_LIBS=$BCM_SHARED_LIBS -DBOOST_INCLUDE_LIBRARIES=$SELF -DBoost_VERBOSE=ON "${BCM_ARGS[@]}" ..
32+
set +x
33+
34+
echo "Building..."
35+
cmake --build . --target $BCM_TARGET --config $BCM_BUILD_TYPE -j$B2_JOBS

ci/cmake_install_test.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! /bin/bash
2+
#
3+
# Copyright 2022 Alexander Grund
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# (See accompanying file LICENSE_1_0.txt or copy at
6+
# http://www.boost.org/LICENSE_1_0.txt)
7+
#
8+
# Bash script to test consuming a Boost library via CMakes add_subdirectory command
9+
#
10+
# Requires the following env vars:
11+
# - BOOST_ROOT & SELF (setup step)
12+
# - BCM_GENERATOR
13+
# - BCM_BUILD_TYPE
14+
# - BCM_SHARED_LIBS
15+
16+
set -eu
17+
18+
echo "Installing Boost via CMake"
19+
BCM_INSTALL_PATH=/tmp/boost_install
20+
21+
BCM_ARGS=(
22+
-DCMAKE_INSTALL_PREFIX=$BCM_INSTALL_PATH
23+
)
24+
BCM_TARGET=install
25+
26+
. "$(dirname "${BASH_SOURCE[0]}")"/cmake_build.sh
27+
28+
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test"
29+
# New unified folder used for the subdir and install test with BOOST_CI_INSTALL_TEST to distinguish in CMake
30+
if [ -d "$cmake_test_folder" ]; then
31+
echo "Using the unified test folder $cmake_test_folder"
32+
33+
else
34+
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_install_test"
35+
echo "Using the dedicated install test folder $cmake_test_folder"
36+
fi
37+
38+
cd "$cmake_test_folder"
39+
mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__
40+
41+
echo "Configuring..."
42+
cmake -G "$BCM_GENERATOR" -DCMAKE_BUILD_TYPE=$BCM_BUILD_TYPE -DBUILD_SHARED_LIBS=$BCM_SHARED_LIBS -DBOOST_CI_INSTALL_TEST=ON -DCMAKE_PREFIX_PATH=$BCM_INSTALL_PATH ..
43+
44+
echo "Building..."
45+
cmake --build . --config $BCM_BUILD_TYPE -j$B2_JOBS
46+
47+
echo "Testing..."
48+
ctest --output-on-failure --build-config $BCM_BUILD_TYPE

ci/cmake_subdir_test.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#! /bin/bash
2+
#
3+
# Copyright 2022 Alexander Grund
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# (See accompanying file LICENSE_1_0.txt or copy at
6+
# http://www.boost.org/LICENSE_1_0.txt)
7+
#
8+
# Bash script to test consuming a Boost library via CMakes add_subdirectory command
9+
#
10+
# Requires the following env vars:
11+
# - BOOST_ROOT & SELF (setup step)
12+
# - BCM_GENERATOR
13+
# - BCM_BUILD_TYPE
14+
# - BCM_SHARED_LIBS
15+
16+
set -eu
17+
18+
. "$(dirname "${BASH_SOURCE[0]}")"/set_num_jobs.sh
19+
20+
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test"
21+
# New unified folder used for the subdir and install test with BOOST_CI_INSTALL_TEST to distinguish in CMake
22+
if [ -d "$cmake_test_folder" ]; then
23+
echo "Using the unified test folder $cmake_test_folder"
24+
25+
else
26+
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_subdir_test"
27+
echo "Using the dedicated subdir test folder $cmake_test_folder"
28+
fi
29+
30+
cd "$cmake_test_folder"
31+
mkdir __build_cmake_subdir_test__ && cd __build_cmake_subdir_test__
32+
33+
echo "Configuring..."
34+
cmake -G "$BCM_GENERATOR" -DCMAKE_BUILD_TYPE=$BCM_BUILD_TYPE -DBUILD_SHARED_LIBS=$BCM_SHARED_LIBS -DBOOST_CI_INSTALL_TEST=OFF ..
35+
36+
echo "Building..."
37+
cmake --build . --config $BCM_BUILD_TYPE -j$B2_JOBS
38+
39+
echo "Testing..."
40+
ctest --output-on-failure --build-config $BCM_BUILD_TYPE

ci/cmake_test.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#! /bin/bash
2+
#
3+
# Copyright 2022 Alexander Grund
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# (See accompanying file LICENSE_1_0.txt or copy at
6+
# http://www.boost.org/LICENSE_1_0.txt)
7+
#
8+
# Bash script to perform a CMake build of Boost
9+
#
10+
# Requires the following env vars:
11+
# - BOOST_ROOT & SELF (setup step)
12+
# - BCM_GENERATOR
13+
# - BCM_BUILD_TYPE
14+
# - BCM_SHARED_LIBS
15+
16+
set -e
17+
18+
BCM_ARGS=(
19+
-DBUILD_TESTING=ON
20+
)
21+
BCM_TARGET=tests
22+
23+
. "$(dirname "${BASH_SOURCE[0]}")"/cmake_build.sh
24+
25+
echo "Testing..."
26+
ctest --output-on-failure --build-config $BCM_BUILD_TYPE

ci/github/install.sh

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ echo "B2_COMPILER=$B2_COMPILER" >> $GITHUB_ENV
5757
[ -z "$B2_TSAN" ] || echo "B2_TSAN=$B2_TSAN" >> $GITHUB_ENV
5858
[ -z "$B2_UBSAN" ] || echo "B2_UBSAN=$B2_UBSAN" >> $GITHUB_ENV
5959
[ -z "$B2_FLAGS" ] || echo "B2_FLAGS=$B2_FLAGS" >> $GITHUB_ENV
60+
[ -z "$BCM_GENERATOR" ] || echo "BCM_GENERATOR=$BCM_GENERATOR" >> $GITHUB_ENV
61+
[ -z "$BCM_BUILD_TYPE" ] || echo "BCM_BUILD_TYPE=$BCM_BUILD_TYPE" >> $GITHUB_ENV
62+
[ -z "$BCM_SHARED_LIBS" ] || echo "BCM_SHARED_LIBS=$BCM_SHARED_LIBS" >> $GITHUB_ENV

0 commit comments

Comments
 (0)