mirror of
https://github.com/boostorg/boost-ci.git
synced 2026-01-19 04:02:12 +00:00
Handle multiple entries in B2_DEFINES
As pointed out by @sdarwin multiple values in `B2_DEFINES` led to a failing build as the scripts only supported a single value for the "new" var usages. This is a regression from the old usage where `B2_DEFINES: define=FOO=1 define=BAR=2` could be used. This is now fixed by a small parser function which generates multiple `define=*` entries and additionally now also supports spaces in the define values. Same is done for `B2_INCLUDE` which has the same issue. Also includes the change to the CI script from #177 and an additional test in test.cpp to verify that this works.
This commit is contained in:
15
.github/workflows/old_ci.yml
vendored
15
.github/workflows/old_ci.yml
vendored
@@ -55,6 +55,21 @@ jobs:
|
||||
B2_LINKFLAGS: linkflags=-fsanitize=undefined linkflags=-fno-sanitize-recover=all linkflags=-fuse-ld=gold
|
||||
os: ubuntu-20.04
|
||||
install: g++-8
|
||||
|
||||
- name: New var usage, multiple values per key
|
||||
env:
|
||||
B2_CI_VERSION: 1
|
||||
B2_TOOLSET: gcc-8
|
||||
B2_ADDRESS_MODEL: 64
|
||||
B2_LINK: shared,static
|
||||
B2_THREADING: threading=multi,single
|
||||
B2_VARIANT: release
|
||||
B2_DEFINES: BOOST_NO_STRESS_TEST=1 BOOST_IMPORTANT=1 BOOST_ALSO_IMPORTANT="with space"
|
||||
B2_LINKFLAGS: -fsanitize=undefined -fno-sanitize-recover=all -fuse-ld=gold
|
||||
B2_FLAGS: define=BOOST_CI_TEST_DEFINES=1
|
||||
os: ubuntu-20.04
|
||||
install: g++-8
|
||||
|
||||
- name: Travis-like coverage collection
|
||||
coverage: yes
|
||||
env:
|
||||
|
||||
@@ -85,12 +85,33 @@ if [ -z "$B2_CI_VERSION" ]; then
|
||||
-j${B2_JOBS}
|
||||
)
|
||||
else
|
||||
# Generate multiple "option=value" entries from the value of an environment variable
|
||||
# Handles correct splitting and quoting
|
||||
function append_b2_args
|
||||
{
|
||||
local var_name="$1"
|
||||
local option_name="$2"
|
||||
if [ -n "${!var_name}" ]; then
|
||||
while IFS= read -r -d '' value; do
|
||||
# If the value has an assignment and a space we need to quote it
|
||||
if [[ $value == *"="*" "* ]]; then
|
||||
B2_ARGS+=("${option_name}=${value%%=*}=\"${value#*=}\"")
|
||||
else
|
||||
B2_ARGS+=("${option_name}=${value}")
|
||||
fi
|
||||
done < <(echo "${!var_name}" | xargs -n 1 printf '%s\0')
|
||||
fi
|
||||
}
|
||||
|
||||
B2_ARGS=(
|
||||
${B2_TOOLSET:+"toolset=$B2_TOOLSET"}
|
||||
"cxxstd=$B2_CXXSTD"
|
||||
${B2_CXXFLAGS:+"cxxflags=$B2_CXXFLAGS"}
|
||||
${B2_DEFINES:+"define=$B2_DEFINES"}
|
||||
${B2_INCLUDE:+"include=$B2_INCLUDE"}
|
||||
)
|
||||
append_b2_args B2_DEFINES define
|
||||
append_b2_args B2_INCLUDE include
|
||||
B2_ARGS=(
|
||||
"${B2_ARGS[@]}"
|
||||
${B2_LINKFLAGS:+"linkflags=$B2_LINKFLAGS"}
|
||||
${B2_TESTFLAGS}
|
||||
${B2_ADDRESS_MODEL:+address-model=$B2_ADDRESS_MODEL}
|
||||
|
||||
@@ -17,8 +17,27 @@
|
||||
// Check that including a file from the same directory works
|
||||
#include "test2.hpp"
|
||||
|
||||
// Test of the CI scripts passing the correct defines
|
||||
#ifdef BOOST_CI_TEST_DEFINES
|
||||
#ifndef BOOST_NO_STRESS_TEST
|
||||
#error "Missing define BOOST_NO_STRESS_TEST"
|
||||
#endif
|
||||
#ifndef BOOST_IMPORTANT
|
||||
#error "Missing define BOOST_IMPORTANT"
|
||||
#endif
|
||||
#ifndef BOOST_ALSO_IMPORTANT
|
||||
#error "Missing define BOOST_ALSO_IMPORTANT"
|
||||
#endif
|
||||
#define BOOST_CI_STRINGIZE_2(x) #x
|
||||
#define BOOST_CI_STRINGIZE(x) BOOST_CI_STRINGIZE_2(x)
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef BOOST_CI_TEST_DEFINES
|
||||
const std::string macro_value = BOOST_CI_STRINGIZE(BOOST_ALSO_IMPORTANT);
|
||||
BOOST_TEST_EQ(macro_value, "with space");
|
||||
#endif
|
||||
const bool isMSVC = MSVC_VALUE;
|
||||
std::map<std::string, std::vector<int> > map;
|
||||
map["result"].push_back(boost::boost_ci::get_answer());
|
||||
|
||||
Reference in New Issue
Block a user