Skip to content

Commit

Permalink
Clang: Use --version instead of -dumpversion (#39)
Browse files Browse the repository at this point in the history
* Clang: Use --version instead of -dumpversion

Fixes issue when Clang 8 and below determined as 4.2.1 version.

* Bootstrap and test with versioned toolset

Eliminates need to manual configure toolsets via `user-config.jam` for testing, and allows to pass to `bootstrap.sh` the same toolset string as you would to B2 invocation what eliminates need to specify a custom exec via `--cxx=`.
  • Loading branch information
Kojoley committed Jun 11, 2021
1 parent 5318d71 commit b522b50
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 72 deletions.
16 changes: 5 additions & 11 deletions .ci/azp-linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,28 @@ steps:
set -e
cd src/engine
set PATH=${PATH};${CXX_PATH}
./build.sh ${TOOLSET} --cxx=${CXX}
./build.sh ${TOOLSET}
./b2 -v
cd ../..
displayName: Build
- bash: |
set -e
CXX_PATH=`which ${CXX}`
cd test
echo "using ${TEST_TOOLSET} : : ${CXX_PATH} ;" > ${HOME}/user-config.jam
python test_all.py ${TEST_TOOLSET}
python test_all.py ${TOOLSET}
cd ..
displayName: Test
- bash: |
set -e
CXX_PATH=`which ${CXX}`
echo "using ${TEST_TOOLSET} : : ${CXX_PATH} ;" > ${HOME}/user-config.jam
./src/engine/b2 b2 warnings-as-errors=on variant=debug,release address-model=32,64 toolset=${TEST_TOOLSET}
./src/engine/b2 b2 warnings-as-errors=on variant=debug,release address-model=32,64 toolset=${TOOLSET}
displayName: "No Warnings"
- bash: |
set -e
CXX_PATH=`which ${CXX}`
echo "using ${TEST_TOOLSET} : : ${CXX_PATH} ;" > ${HOME}/user-config.jam
./bootstrap.sh ${TOOLSET}
./b2 --prefix=$HOME/temp/.b2 install ${TEST_TOOLSET}
./b2 --prefix=$HOME/temp/.b2 install toolset=${TOOLSET}
rm ./b2
export PATH=$HOME/temp/.b2/bin:$PATH
cd $HOME
touch build.jam
b2 -v
b2 -n --debug-configuration
b2 -n --debug-configuration toolset=${TOOLSET}
displayName: Bootstrap
48 changes: 24 additions & 24 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ stages:
- job: 'Linux_Latest'
strategy:
matrix:
GCC 11: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-11, PACKAGES: g++-11, VM_IMAGE: 'ubuntu-latest'}
Clang 12: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-12, PACKAGES: clang-12, LLVM_OS: focal, LLVM_VER: 12, VM_IMAGE: 'ubuntu-latest'}
GCC 11: {TOOLSET: gcc-11, PACKAGES: g++-11, VM_IMAGE: 'ubuntu-latest'}
Clang 12: {TOOLSET: clang-12, PACKAGES: clang-12, LLVM_OS: focal, LLVM_VER: 12, VM_IMAGE: 'ubuntu-latest'}
pool:
vmImage: $(VM_IMAGE)
steps:
Expand Down Expand Up @@ -97,28 +97,28 @@ stages:
- job: 'Linux'
strategy:
matrix:
GCC 10: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-10, PACKAGES: g++-10, VM_IMAGE: 'ubuntu-latest'}
GCC 9: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-9, PACKAGES: g++-9, VM_IMAGE: 'ubuntu-18.04'}
GCC 8: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-8, PACKAGES: g++-8, VM_IMAGE: 'ubuntu-18.04'}
GCC 7: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-7, PACKAGES: g++-7, VM_IMAGE: 'ubuntu-18.04'}
GCC 6: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-6, PACKAGES: g++-6, VM_IMAGE: 'ubuntu-18.04'}
GCC 5: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-5, PACKAGES: g++-5, VM_IMAGE: 'ubuntu-18.04'}
GCC 4.9: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-4.9, PACKAGES: g++-4.9, VM_IMAGE: 'ubuntu-16.04'}
GCC 4.8: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-4.8, PACKAGES: g++-4.8, VM_IMAGE: 'ubuntu-16.04'}
GCC 4.7: {TOOLSET: gcc, TEST_TOOLSET: gcc, CXX: g++-4.7, PACKAGES: g++-4.7, VM_IMAGE: 'ubuntu-16.04'}
Clang 11: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-11, PACKAGES: clang-11, LLVM_OS: focal, LLVM_VER: 11, VM_IMAGE: 'ubuntu-latest'}
Clang 10: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-10, PACKAGES: clang-10, LLVM_OS: bionic, LLVM_VER: 10, VM_IMAGE: 'ubuntu-18.04'}
Clang 9: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-9, PACKAGES: clang-9, LLVM_OS: bionic, LLVM_VER: 9, VM_IMAGE: 'ubuntu-18.04'}
Clang 8: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-8, PACKAGES: clang-8, LLVM_OS: bionic, LLVM_VER: 8, VM_IMAGE: 'ubuntu-18.04'}
Clang 7: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-7, PACKAGES: clang-7, LLVM_OS: bionic, LLVM_VER: 7, VM_IMAGE: 'ubuntu-18.04'}
Clang 6: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-6.0, PACKAGES: clang-6.0, LLVM_OS: bionic, LLVM_VER: 6.0, VM_IMAGE: 'ubuntu-18.04'}
Clang 5: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-5.0, PACKAGES: clang-5.0, LLVM_OS: bionic, LLVM_VER: 5.0, VM_IMAGE: 'ubuntu-18.04'}
Clang 4: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-4.0, PACKAGES: clang-4.0, LLVM_OS: xenial, LLVM_VER: 4.0, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.9: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-3.9, PACKAGES: clang-3.9, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.8: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-3.8, PACKAGES: clang-3.8, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.7: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-3.7, PACKAGES: clang-3.7, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.6: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-3.6, PACKAGES: clang-3.6, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.5: {TOOLSET: clang, TEST_TOOLSET: clang, CXX: clang++-3.5, PACKAGES: clang-3.5, VM_IMAGE: 'ubuntu-16.04'}
GCC 10: {TOOLSET: gcc-10, PACKAGES: g++-10, VM_IMAGE: 'ubuntu-latest'}
GCC 9: {TOOLSET: gcc-9, PACKAGES: g++-9, VM_IMAGE: 'ubuntu-18.04'}
GCC 8: {TOOLSET: gcc-8, PACKAGES: g++-8, VM_IMAGE: 'ubuntu-18.04'}
GCC 7: {TOOLSET: gcc-7, PACKAGES: g++-7, VM_IMAGE: 'ubuntu-18.04'}
GCC 6: {TOOLSET: gcc-6, PACKAGES: g++-6, VM_IMAGE: 'ubuntu-18.04'}
GCC 5: {TOOLSET: gcc-5, PACKAGES: g++-5, VM_IMAGE: 'ubuntu-18.04'}
GCC 4.9: {TOOLSET: gcc-4.9, PACKAGES: g++-4.9, VM_IMAGE: 'ubuntu-16.04'}
GCC 4.8: {TOOLSET: gcc-4.8, PACKAGES: g++-4.8, VM_IMAGE: 'ubuntu-16.04'}
GCC 4.7: {TOOLSET: gcc-4.7, PACKAGES: g++-4.7, VM_IMAGE: 'ubuntu-16.04'}
Clang 11: {TOOLSET: clang-11, PACKAGES: clang-11, LLVM_OS: focal, LLVM_VER: 11, VM_IMAGE: 'ubuntu-latest'}
Clang 10: {TOOLSET: clang-10, PACKAGES: clang-10, LLVM_OS: bionic, LLVM_VER: 10, VM_IMAGE: 'ubuntu-18.04'}
Clang 9: {TOOLSET: clang-9, PACKAGES: clang-9, LLVM_OS: bionic, LLVM_VER: 9, VM_IMAGE: 'ubuntu-18.04'}
Clang 8: {TOOLSET: clang-8, PACKAGES: clang-8, LLVM_OS: bionic, LLVM_VER: 8, VM_IMAGE: 'ubuntu-18.04'}
Clang 7: {TOOLSET: clang-7, PACKAGES: clang-7, LLVM_OS: bionic, LLVM_VER: 7, VM_IMAGE: 'ubuntu-18.04'}
Clang 6: {TOOLSET: clang-6.0, PACKAGES: clang-6.0, LLVM_OS: bionic, LLVM_VER: 6.0, VM_IMAGE: 'ubuntu-18.04'}
Clang 5: {TOOLSET: clang-5.0, PACKAGES: clang-5.0, LLVM_OS: bionic, LLVM_VER: 5.0, VM_IMAGE: 'ubuntu-18.04'}
Clang 4: {TOOLSET: clang-4.0, PACKAGES: clang-4.0, LLVM_OS: xenial, LLVM_VER: 4.0, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.9: {TOOLSET: clang-3.9, PACKAGES: clang-3.9, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.8: {TOOLSET: clang-3.8, PACKAGES: clang-3.8, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.7: {TOOLSET: clang-3.7, PACKAGES: clang-3.7, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.6: {TOOLSET: clang-3.6, PACKAGES: clang-3.6, VM_IMAGE: 'ubuntu-16.04'}
Clang 3.5: {TOOLSET: clang-3.5, PACKAGES: clang-3.5, VM_IMAGE: 'ubuntu-16.04'}
pool:
vmImage: $(VM_IMAGE)
steps:
Expand Down
21 changes: 12 additions & 9 deletions src/engine/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ test_compiler ()

test_toolset ()
{
if test "${B2_TOOLSET}" = "" ; then return ${TRUE} ; fi
if test "${B2_TOOLSET}" = "$1" -o "${B2_TOOLSET}" = "$2" -o "${B2_TOOLSET}" = "$3" ; then return ${TRUE} ; fi
if test "${TOOLSET}" = "" ; then return ${TRUE} ; fi
if test "${TOOLSET}" = "$1" -o "${TOOLSET}" = "$2" -o "${TOOLSET}" = "$3" ; then return ${TRUE} ; fi
return 1
}

Expand All @@ -151,15 +151,18 @@ test_toolset ()
#
check_toolset ()
{
TOOLSET=${B2_TOOLSET%%-*}
TOOLSET_SUFFIX=${B2_TOOLSET##$TOOLSET}

# Prefer Clang (clang) on macOS..
if test_toolset clang && test_uname Darwin && test_compiler clang++ -x c++ -std=c++11 ; then B2_TOOLSET=clang ; return ${TRUE} ; fi
if test_toolset clang && test_uname Darwin && test_compiler clang++$TOOLSET_SUFFIX -x c++ -std=c++11 ; then B2_TOOLSET=clang$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# GCC (gcc)..
if test_toolset gcc && test_compiler g++ -x c++ -std=c++11 ; then B2_TOOLSET=gcc ; return ${TRUE} ; fi
if test_toolset gcc && test_compiler g++ -x c++ -std=c++11 -D_GNU_SOURCE ; then B2_TOOLSET=gcc ; return ${TRUE} ; fi
if test_toolset gcc && test_compiler g++$TOOLSET_SUFFIX -x c++ -std=c++11 ; then B2_TOOLSET=gcc$TOOLSET_SUFFIX ; return ${TRUE} ; fi
if test_toolset gcc && test_compiler g++$TOOLSET_SUFFIX -x c++ -std=c++11 -D_GNU_SOURCE ; then B2_TOOLSET=gcc$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# GCC (gcc) with -pthread arg (for AIX)..
if test_toolset gcc && test_compiler g++ -x c++ -std=c++11 -pthread ; then B2_TOOLSET=gcc ; return ${TRUE} ; fi
if test_toolset gcc && test_compiler g++$TOOLSET_SUFFIX -x c++ -std=c++11 -pthread ; then B2_TOOLSET=gcc$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# Clang (clang)..
if test_toolset clang && test_compiler clang++ -x c++ -std=c++11 ; then B2_TOOLSET=clang ; return ${TRUE} ; fi
if test_toolset clang && test_compiler clang++$TOOLSET_SUFFIX -x c++ -std=c++11 ; then B2_TOOLSET=clang$TOOLSET_SUFFIX ; return ${TRUE} ; fi
# Intel macOS (intel-darwin)
if test_toolset intel-darwin && test -r "${HOME}/intel/oneapi/setvars.sh" && test_uname Darwin ; then
B2_SETUP="source ${HOME}/intel/oneapi/setvars.sh"
Expand Down Expand Up @@ -318,7 +321,7 @@ fi
# Set the additional options needed to build the engine based on the toolset.
case "${B2_TOOLSET}" in

gcc)
gcc|gcc-*)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O2 -s"
B2_CXXFLAGS_DEBUG="-O0 -g"
Expand Down Expand Up @@ -384,7 +387,7 @@ case "${B2_TOOLSET}" in
B2_CXXFLAGS_DEBUG="-g"
;;

clang*)
clang|clang-*)
CXX_VERSION_OPT=${CXX_VERSION_OPT:---version}
B2_CXXFLAGS_RELEASE="-O3 -s"
B2_CXXFLAGS_DEBUG="-O0 -fno-inline -g"
Expand Down
16 changes: 13 additions & 3 deletions src/tools/clang-linux.jam
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,22 @@ rule init ( version ? : command * : options * ) {

rule get-full-version ( command-string )
{
return [ gcc.get-full-version $(command-string) ] ;
return [ common.match-command-output version : "version ([0-9.]+)"
: "$(command-string) --version" ] ;
}

rule get-short-version ( command-string )
rule get-short-version ( command-string : single-digit-since ? )
{
return [ gcc.get-short-version $(command-string) : 4 ] ;
local version = [ get-full-version $(command-string) ] ;
version = [ SPLIT_BY_CHARACTERS $(version) : . ] ;

import version ;
if [ version.version-less $(version) : $(single-digit-since:E=4) ]
{
return $(version[1-2]:J=.) ;
}

return $(version[1]) ;
}

###############################################################################
Expand Down
19 changes: 19 additions & 0 deletions src/tools/common.jam
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,25 @@ rule find-compiler ( toolset : tool : version ? : command * : additional-paths *
return $(command) ;
}

rule match-command-output ( kind ? : pattern : command-string )
{
local output = [ SHELL $(command-string) : exit-status ] ;
if 0 != $(output[2])
{
errors.error '$(command-string)'
exited with error code $(output[2]) ;
}

local match = [ MATCH $(pattern) : $(output[1]) ] ;
if ! $(match)
{
errors.error '$(command-string)'
returned an invalid $kind string '$(output[1])' ;
}

return $(match) ;
}

rule __test__ ( )
{
import assert ;
Expand Down
24 changes: 3 additions & 21 deletions src/tools/gcc.jam
Original file line number Diff line number Diff line change
Expand Up @@ -289,36 +289,18 @@ if [ os.name ] = NT
JAMSHELL = % ;
}

local rule get-version ( command-string )
{
local output = [ SHELL $(command-string) : exit-status ] ;
if 0 != $(output[2])
{
errors.error '$(command-string)'
exited with error code $(output[2]) ;
}

local version = [ MATCH "^([0-9.]+)" : $(output[1]) ] ;
if ! $(version)
{
errors.error '$(command-string)'
returned an invalid version string '$(output[1])' ;
}

return $(version) ;
}

rule get-full-version ( command-string )
{
# -dumpfullversion is only supported for gcc 7+.
# Passing both options works, as the first one that's
# recognized will be used.
return [ get-version "$(command-string) -dumpfullversion -dumpversion" ] ;
return [ common.match-command-output version : "^([0-9.]+)"
: "$(command-string) -dumpfullversion -dumpversion" ] ;
}

rule get-short-version ( command-string : single-digit-since ? )
{
local version = [ get-version "$(command-string) -dumpversion" ] ;
local version = [ get-full-version $(command-string) ] ;
version = [ SPLIT_BY_CHARACTERS $(version) : . ] ;

import version ;
Expand Down
24 changes: 20 additions & 4 deletions test/BoostBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ def get_toolset():
elif hasattr(os, "uname"):
default_os = os.uname()[0].lower()


def expand_toolset(toolset, target_os=default_os):
match = re.match(r'^(clang|intel)(-[\d\.]+|)$', toolset)
if match:
if match.group(1) == "intel" and target_os == "windows":
return match.expand(r'\1-win\2')
elif target_os == "darwin":
return match.expand(r'\1-darwin\2')
else:
return match.expand(r'\1-linux\2')

return toolset


def prepare_prefixes_and_suffixes(toolset, target_os=default_os):
ind = toolset.find('-')
if ind == -1:
Expand Down Expand Up @@ -258,6 +272,7 @@ def __init__(self, arguments=None, executable=None,
self.use_test_config = use_test_config

self.toolset = get_toolset()
self.expanded_toolset = expand_toolset(self.toolset)
self.pass_toolset = pass_toolset
self.ignore_toolset_requirements = ignore_toolset_requirements

Expand Down Expand Up @@ -318,6 +333,7 @@ def cleanup(self):

def set_toolset(self, toolset, target_os=default_os):
self.toolset = toolset
self.expanded_toolset = expand_toolset(toolset, target_os)
self.pass_toolset = True
prepare_prefixes_and_suffixes(toolset, target_os)

Expand Down Expand Up @@ -401,7 +417,7 @@ def rm(self, names):
n = glob.glob(self.native_file_name(name))
if n: n = n[0]
if not n:
n = self.glob_file(name.replace("$toolset", self.toolset + "*")
n = self.glob_file(name.replace("$toolset", self.expanded_toolset + "*")
)
if n:
if os.path.isdir(n):
Expand All @@ -420,7 +436,7 @@ def expand_toolset(self, name):
toolset currently being tested.
"""
self.write(name, self.read(name).replace("$toolset", self.toolset))
self.write(name, self.read(name).replace("$toolset", self.expanded_toolset))

def dump_stdio(self):
annotation("STDOUT", self.stdout())
Expand Down Expand Up @@ -758,7 +774,7 @@ def expect_content_lines(self, filename, line, expected=True):

def expect_content(self, name, content, exact=False):
actual = self.read(name)
content = content.replace("$toolset", self.toolset + "*")
content = content.replace("$toolset", self.expanded_toolset + "*")

matched = False
if exact:
Expand Down Expand Up @@ -852,7 +868,7 @@ def adjust_names(self, names):
names = [names]
r = map(self.adjust_lib_name, names)
r = map(self.adjust_suffix, r)
r = map(lambda x, t=self.toolset: x.replace("$toolset", t + "*"), r)
r = map(lambda x, t=self.expanded_toolset: x.replace("$toolset", t + "*"), r)
return list(r)

def adjust_name(self, name):
Expand Down

0 comments on commit b522b50

Please sign in to comment.