Skip to content

Commit

Permalink
Factor out CMake builds from the CI file
Browse files Browse the repository at this point in the history
Allow reuse and a centralized place for improvements
  • Loading branch information
Flamefire committed Apr 28, 2022
1 parent 6521312 commit f9b53fc
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 30 deletions.
39 changes: 9 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,39 +374,18 @@ jobs:
[[ "$GITHUB_REPOSITORY" =~ "boost-ci" ]] || cp -r boost-ci-cloned/ci .
rm -rf boost-ci-cloned
- name: Setup Boost
env: {B2_DONT_BOOTSTRAP: 1}
env:
B2_DONT_BOOTSTRAP: 1
BCM_GENERATOR: ${{matrix.generator}}
BCM_BUILD_TYPE: ${{matrix.build_type}}
BCM_SHARED_LIBS: ${{matrix.build_shared}}
run: source ci/github/install.sh

- name: Run CMake tests
run: |
cd "$BOOST_ROOT"
mkdir __build_cmake_test__ && cd __build_cmake_test__
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 ..
cmake --build . --target tests --config ${{matrix.build_type}}
ctest --output-on-failure --build-config ${{matrix.build_type}}
run: ci/cmake_test.sh

- name: Run CMake subdir tests
run: |
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test" # New unified folder
[ -d "$cmake_test_folder" ] || cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_subdir_test"
cd "$cmake_test_folder"
mkdir __build_cmake_subdir_test__ && cd __build_cmake_subdir_test__
cmake -G "${{matrix.generator}}" -DBOOST_CI_INSTALL_TEST=OFF -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBUILD_SHARED_LIBS=${{matrix.build_shared}} ..
cmake --build . --config ${{matrix.build_type}}
ctest --output-on-failure --build-config ${{matrix.build_type}}
- name: Install Library
run: |
cd "$BOOST_ROOT"
mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__
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 ..
cmake --build . --target install --config ${{matrix.build_type}}
run: ci/cmake_subdir_test.sh

- name: Run CMake install tests
run: |
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test" # New unified folder
[ -d "$cmake_test_folder" ] || cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_install_test"
cd "$cmake_test_folder"
mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__
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 ..
cmake --build . --config ${{matrix.build_type}}
ctest --output-on-failure --build-config ${{matrix.build_type}}
run: ci/cmake_install_test.sh
35 changes: 35 additions & 0 deletions ci/cmake_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /bin/bash
#
# Copyright 2022 Alexander Grund
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Bash script to perform a CMake build of Boost
#
# Requires the following env vars:
# - BOOST_ROOT & SELF (setup step)
# - BCM_GENERATOR
# - BCM_BUILD_TYPE
# - BCM_SHARED_LIBS
# - BCM_ARGS
# - BCM_TARGET

set -e

. "$(dirname "${BASH_SOURCE[0]}")"/set_num_jobs.sh

cd "$BOOST_ROOT"
buildDir=__build
while [ -d "$buildDir" ]; do
buildDir="${buildDir}_2"
done
mkdir "$buildDir" && cd "$buildDir"

echo "Configuring..."
set -x
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[@]}" ..
set +x

echo "Building..."
cmake --build . --target $BCM_TARGET --config $BCM_BUILD_TYPE -j$B2_JOBS
48 changes: 48 additions & 0 deletions ci/cmake_install_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#! /bin/bash
#
# Copyright 2022 Alexander Grund
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Bash script to test consuming a Boost library via CMakes add_subdirectory command
#
# Requires the following env vars:
# - BOOST_ROOT & SELF (setup step)
# - BCM_GENERATOR
# - BCM_BUILD_TYPE
# - BCM_SHARED_LIBS

set -eu

echo "Installing Boost via CMake"
BCM_INSTALL_PATH=/tmp/boost_install

BCM_ARGS=(
-DCMAKE_INSTALL_PREFIX=$BCM_INSTALL_PATH
)
BCM_TARGET=install

. "$(dirname "${BASH_SOURCE[0]}")"/cmake_build.sh

cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test"
# New unified folder used for the subdir and install test with BOOST_CI_INSTALL_TEST to distinguish in CMake
if [ -d "$cmake_test_folder" ]; then
echo "Using the unified test folder $cmake_test_folder"

else
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_install_test"
echo "Using the dedicated install test folder $cmake_test_folder"
fi

cd "$cmake_test_folder"
mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__

echo "Configuring..."
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 ..

echo "Building..."
cmake --build . --config $BCM_BUILD_TYPE -j$B2_JOBS

echo "Testing..."
ctest --output-on-failure --build-config $BCM_BUILD_TYPE
40 changes: 40 additions & 0 deletions ci/cmake_subdir_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /bin/bash
#
# Copyright 2022 Alexander Grund
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Bash script to test consuming a Boost library via CMakes add_subdirectory command
#
# Requires the following env vars:
# - BOOST_ROOT & SELF (setup step)
# - BCM_GENERATOR
# - BCM_BUILD_TYPE
# - BCM_SHARED_LIBS

set -eu

. "$(dirname "${BASH_SOURCE[0]}")"/set_num_jobs.sh

cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test"
# New unified folder used for the subdir and install test with BOOST_CI_INSTALL_TEST to distinguish in CMake
if [ -d "$cmake_test_folder" ]; then
echo "Using the unified test folder $cmake_test_folder"

else
cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_subdir_test"
echo "Using the dedicated subdir test folder $cmake_test_folder"
fi

cd "$cmake_test_folder"
mkdir __build_cmake_subdir_test__ && cd __build_cmake_subdir_test__

echo "Configuring..."
cmake -G "$BCM_GENERATOR" -DCMAKE_BUILD_TYPE=$BCM_BUILD_TYPE -DBUILD_SHARED_LIBS=$BCM_SHARED_LIBS -DBOOST_CI_INSTALL_TEST=OFF ..

echo "Building..."
cmake --build . --config $BCM_BUILD_TYPE -j$B2_JOBS

echo "Testing..."
ctest --output-on-failure --build-config $BCM_BUILD_TYPE
26 changes: 26 additions & 0 deletions ci/cmake_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /bin/bash
#
# Copyright 2022 Alexander Grund
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Bash script to perform a CMake build of Boost
#
# Requires the following env vars:
# - BOOST_ROOT & SELF (setup step)
# - BCM_GENERATOR
# - BCM_BUILD_TYPE
# - BCM_SHARED_LIBS

set -e

BCM_ARGS=(
-DBUILD_TESTING=ON
)
BCM_TARGET=tests

. "$(dirname "${BASH_SOURCE[0]}")"/cmake_build.sh

echo "Testing..."
ctest --output-on-failure --build-config $BCM_BUILD_TYPE
3 changes: 3 additions & 0 deletions ci/github/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ echo "B2_COMPILER=$B2_COMPILER" >> $GITHUB_ENV
[ -z "$B2_TSAN" ] || echo "B2_TSAN=$B2_TSAN" >> $GITHUB_ENV
[ -z "$B2_UBSAN" ] || echo "B2_UBSAN=$B2_UBSAN" >> $GITHUB_ENV
[ -z "$B2_FLAGS" ] || echo "B2_FLAGS=$B2_FLAGS" >> $GITHUB_ENV
[ -z "$BCM_GENERATOR" ] || echo "BCM_GENERATOR=$BCM_GENERATOR" >> $GITHUB_ENV
[ -z "$BCM_BUILD_TYPE" ] || echo "BCM_BUILD_TYPE=$BCM_BUILD_TYPE" >> $GITHUB_ENV
[ -z "$BCM_SHARED_LIBS" ] || echo "BCM_SHARED_LIBS=$BCM_SHARED_LIBS" >> $GITHUB_ENV

0 comments on commit f9b53fc

Please sign in to comment.