Skip to content

Commit a6168c6

Browse files
committed
Compose B2 arguments for Windows in enforce.sh
Windows CMD is not powerful enough for the correct translation of quoted B2 input variables like `B2_DEFINE`
1 parent 3c700ff commit a6168c6

4 files changed

Lines changed: 50 additions & 29 deletions

File tree

.github/workflows/reusable.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,18 @@ jobs:
611611
B2_TOOLSET: ${{matrix.toolset}}
612612
SELF: ${{inputs.library_folder}}
613613

614-
- name: Run tests
615-
if: '!matrix.coverage'
616-
run: ci\build.bat
614+
- name: Determine B2 arguments
615+
run: |
616+
# Use Bash which is more flexible than CMD and we can reuse the logic
617+
. ci/enforce.sh
618+
echo "B2_FULL_ARGS=${B2_ARGS[@]}" >> "$GITHUB_ENV"
619+
echo "SELF=$SELF" >> "$GITHUB_ENV"
620+
if [[ -z "$B2_TARGETS" ]]; then
621+
B2_TARGETS=libs/$SELF/test
622+
fi
623+
echo "B2_TARGETS=$B2_TARGETS" >> "$GITHUB_ENV"
624+
echo "SELF=$SELF" >> "$GITHUB_ENV"
625+
shell: bash
617626
env:
618627
B2_TOOLSET: ${{matrix.toolset}}
619628
B2_TARGET_OS: ${{matrix.target-os}}
@@ -622,23 +631,17 @@ jobs:
622631
B2_DEFINES: ${{inputs.b2_defines}}
623632
B2_LINK: ${{inputs.b2_link}}
624633
B2_VARIANT: ${{inputs.b2_variant}}
625-
SELF: ${{inputs.library_folder}}
626634
B2_TARGETS: ${{inputs.b2_targets}}
635+
SELF: ${{inputs.library_folder}}
636+
637+
- name: Run tests
638+
if: '!matrix.coverage'
639+
run: ci\build.bat
627640

628641
- name: Collect coverage
629642
shell: powershell
630643
if: matrix.coverage
631644
run: ci\opencppcoverage.ps1
632-
env:
633-
B2_TOOLSET: ${{matrix.toolset}}
634-
B2_TARGET_OS: ${{matrix.target-os}}
635-
B2_CXXSTD: ${{matrix.cxxstd}}
636-
B2_ADDRESS_MODEL: ${{matrix.address-model}}
637-
B2_DEFINES: ${{inputs.b2_defines}}
638-
B2_LINK: ${{inputs.b2_link}}
639-
B2_VARIANT: ${{inputs.b2_variant}}
640-
SELF: ${{inputs.library_folder}}
641-
B2_TARGETS: ${{inputs.b2_targets}}
642645

643646
- name: Upload coverage
644647
if: matrix.coverage

ci/build.bat

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ IF "%B2_CI_VERSION%" == "0" (
1515

1616
IF DEFINED ADDPATH (SET "PATH=%ADDPATH%%PATH%")
1717

18+
cd %BOOST_ROOT%
19+
20+
set SELF_S=%SELF:\=/%
21+
IF NOT DEFINED B2_TARGETS (SET B2_TARGETS=libs/!SELF_S!/test)
22+
1823
SET B2_TOOLCXX=toolset=%B2_TOOLSET%
1924

2025
IF DEFINED B2_CXXSTD (SET B2_CXXSTD=cxxstd=%B2_CXXSTD%)
@@ -26,8 +31,6 @@ IF DEFINED B2_TARGET_OS (SET B2_TARGET_OS=target-os=%B2_TARGET_OS%)
2631
IF DEFINED B2_LINK (SET B2_LINK=link=%B2_LINK%)
2732
IF DEFINED B2_VARIANT (SET B2_VARIANT=variant=%B2_VARIANT%)
2833

29-
set SELF_S=%SELF:\=/%
30-
IF NOT DEFINED B2_TARGETS (SET B2_TARGETS=libs/!SELF_S!/test)
3134
IF NOT DEFINED B2_JOBS (SET B2_JOBS=3)
3235

3336
REM clang-win requires to use the linker for the manifest
@@ -39,10 +42,13 @@ IF "%B2_TOOLSET%" == "clang-win" (
3942
)
4043
)
4144

42-
cd %BOOST_ROOT%
43-
4445
IF DEFINED SCRIPT (
4546
call libs\%SELF%\%SCRIPT%
47+
) ELSE IF DEFINED B2_FULL_ARGS (
48+
REM Echo the complete build command to the build log
49+
ECHO b2 --abbreviate-paths %B2_TARGETS% %B2_FULL_ARGS%
50+
REM Now go build...
51+
b2 --abbreviate-paths %B2_TARGETS% %B2_FULL_ARGS%
4652
) ELSE (
4753
REM Echo the complete build command to the build log
4854
ECHO b2 --abbreviate-paths %B2_TARGETS% %B2_TOOLCXX% %B2_CXXSTD% %B2_CXXFLAGS% %B2_DEFINES% %B2_INCLUDE% %B2_THREADING% %B2_ADDRESS_MODEL% %B2_TARGET_OS% %B2_LINK% %B2_VARIANT% -j%B2_JOBS% %B2_FLAGS%

ci/enforce.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
# Copyright 2017 - 2019 James E. King III
4-
# Copyright 2020 - 2025 Alexander Grund
4+
# Copyright 2020 - 2026 Alexander Grund
55
# Distributed under the Boost Software License, Version 1.0.
66
# (See accompanying file LICENSE_1_0.txt or copy at
77
# http://www.boost.org/LICENSE_1_0.txt)
@@ -60,8 +60,13 @@ fi
6060

6161
# default parallel build jobs: number of CPUs available + 1
6262
if [ -z "${B2_JOBS:-}" ]; then
63-
pythonexecutable=$(get_python_executable)
64-
cpus=$(grep -c 'processor' /proc/cpuinfo || $pythonexecutable -c 'import multiprocessing as mp; print(mp.cpu_count())' || echo "2")
63+
if ! cpus=$(grep -c 'processor' /proc/cpuinfo); then
64+
if pythonexecutable=$(get_python_executable); then
65+
cpus=$($pythonexecutable -c 'import multiprocessing as mp; print(mp.cpu_count())' || echo "2")
66+
else
67+
cpus=2
68+
fi
69+
fi
6570
export B2_JOBS=$((cpus + 1))
6671
fi
6772

@@ -97,14 +102,9 @@ if ((${B2_CI_VERSION:-1} > 0)); then
97102

98103
B2_ARGS=(
99104
${B2_TOOLSET:+"toolset=$B2_TOOLSET"}
100-
"cxxstd=$B2_CXXSTD"
105+
${B2_CXXSTD:+"cxxstd=$B2_CXXSTD"}
101106
${B2_CXXFLAGS:+"cxxflags=$B2_CXXFLAGS"}
102-
)
103-
append_b2_args B2_DEFINES define
104-
append_b2_args B2_INCLUDE include
105-
# shellcheck disable=SC2206
106-
B2_ARGS=(
107-
"${B2_ARGS[@]}"
107+
${B2_TARGET_OS:+"target-os=$B2_TARGET_OS"}
108108
${B2_LINKFLAGS:+"linkflags=$B2_LINKFLAGS"}
109109
${B2_TESTFLAGS:-}
110110
${B2_ADDRESS_MODEL:+address-model=$B2_ADDRESS_MODEL}
@@ -117,8 +117,16 @@ if ((${B2_CI_VERSION:-1} > 0)); then
117117
${B2_TSAN:+thread-sanitizer=norecover}
118118
${B2_UBSAN:+undefined-sanitizer=norecover}
119119
-j"${B2_JOBS}"
120-
${B2_FLAGS:-}
121120
)
121+
append_b2_args B2_DEFINES define
122+
append_b2_args B2_INCLUDE include
123+
# clang-win requires to use the linker for the manifest
124+
if [[ ${B2_TOOLSET:-} == "clang-win" ]]; then
125+
B2_ARGS+=(embed-manifest-via=linker)
126+
fi
127+
128+
# shellcheck disable=SC2206
129+
B2_ARGS+=(${B2_FLAGS:-})
122130
else
123131
# Legacy codepath for compatibility for for old versions of the .github/*.yml files:
124132
# In (most) variables the prefix (such as "cxxflags=" for B2_CXXFLAGS) was included in the value, so it isn't added (again) here

test/Jamfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ local B2_ADDRESS_MODEL = [ os.environ B2_ADDRESS_MODEL ] ;
1616
local B2_CXXFLAGS = [ os.environ B2_CXXFLAGS ] ;
1717
local B2_CXXSTD = [ os.environ B2_CXXSTD ] ;
1818
local B2_DEFINES = [ os.environ B2_DEFINES ] ;
19+
local B2_FULL_ARGS = [ os.environ B2_FULL_ARGS ] ;
1920
local B2_INCLUDE = [ os.environ B2_INCLUDE ] ;
2021
local B2_JOBS = [ os.environ B2_JOBS ] ;
2122
local B2_LINK = [ os.environ B2_LINK ] ;
2223
local B2_LINKFLAGS = [ os.environ B2_LINKFLAGS ] ;
24+
local B2_TARGETS = [ os.environ B2_TARGETS ] ;
2325
local B2_TESTFLAGS = [ os.environ B2_TESTFLAGS ] ;
2426
local B2_THREADING = [ os.environ B2_THREADING ] ;
2527
local B2_TOOLSET = [ os.environ B2_TOOLSET ] ;
@@ -33,10 +35,12 @@ ECHO " B2_ADDRESS_MODEL:" $(B2_ADDRESS_MODEL) ;
3335
ECHO " B2_CXXFLAGS:" $(B2_CXXFLAGS) ;
3436
ECHO " B2_CXXSTD:" $(B2_CXXSTD) ;
3537
ECHO " B2_DEFINES:" $(B2_DEFINES) ;
38+
ECHO " B2_FULL_ARGS:" $(B2_FULL_ARGS) ;
3639
ECHO " B2_INCLUDE:" $(B2_INCLUDE) ;
3740
ECHO " B2_JOBS:" $(B2_JOBS) ;
3841
ECHO " B2_LINK:" $(B2_LINK) ;
3942
ECHO " B2_LINKFLAGS:" $(B2_LINKFLAGS) ;
43+
ECHO " B2_TARGETS:" $(B2_TARGETS) ;
4044
ECHO " B2_TESTFLAGS:" $(B2_TESTFLAGS) ;
4145
ECHO " B2_THREADING:" $(B2_THREADING) ;
4246
ECHO " B2_TOOLSET:" $(B2_TOOLSET) ;

0 commit comments

Comments
 (0)