Skip to content

Commit 3cb8075

Browse files
committed
Parse compiler version in init-compiler.sh
1 parent 1a66526 commit 3cb8075

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

eng/common/native/init-compiler.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,44 @@
22
#
33
# This file detects the C/C++ compiler and exports it to the CC/CXX environment variables
44
#
5-
# NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here!
5+
# NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here!
66

77
if [[ "$#" -lt 3 ]]; then
88
echo "Usage..."
9-
echo "init-compiler.sh <script directory> <Architecture> <compiler> <compiler major version> <compiler minor version>"
9+
echo "init-compiler.sh <script directory> <Architecture> <compiler>"
1010
echo "Specify the script directory."
1111
echo "Specify the target architecture."
1212
echo "Specify the name of compiler (clang or gcc)."
13-
echo "Specify the major version of compiler."
14-
echo "Specify the minor version of compiler."
1513
exit 1
1614
fi
1715

1816
nativescriptroot="$1"
1917
build_arch="$2"
2018
compiler="$3"
2119
cxxCompiler="$compiler++"
22-
majorVersion="$4"
23-
minorVersion="$5"
20+
21+
case "$compiler" in
22+
clang*|-clang*)
23+
# clangx.y or clang-x.y
24+
version="$(echo "$compiler" | tr -d '[:alpha:]-=')"
25+
parts=(${version//./ })
26+
majorVersion="${parts[0]}"
27+
minorVersion="${parts[1]}"
28+
if [[ -z "$minorVersion" && "$majorVersion" -le 6 ]]; then
29+
minorVersion=0;
30+
fi
31+
compiler=clang
32+
;;
33+
34+
gcc*|-gcc*)
35+
# gccx.y or gcc-x.y
36+
version="$(echo "$compiler" | tr -d '[:alpha:]-=')"
37+
parts=(${version//./ })
38+
majorVersion="${parts[0]}"
39+
minorVersion="${parts[1]}"
40+
compiler=gcc
41+
;;
42+
esac
2443

2544
. "$nativescriptroot"/../pipeline-logging-functions.sh
2645

src/Microsoft.DotNet.CMake.Sdk/build/Microsoft.DotNet.CMake.Sdk.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<PropertyGroup>
124124
<_NativeScriptsDir>$([MSBuild]::NormalizeDirectory('$(RepositoryEngineeringDir)', 'common', 'native'))</_NativeScriptsDir>
125125
<CMakeCompilerSearchScript>
126-
. &quot;$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '$(_NativeScriptsDir)/init-compiler.sh'))&quot; &quot;$(_NativeScriptsDir)&quot; &quot;$(Platform)&quot; &quot;$(CMakeCompilerToolchain)&quot; &quot;$(CMakeCompilerMajorVersion)&quot; &quot;$(CMakeCompilerMinorVersion)&quot;
126+
. &quot;$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '$(_NativeScriptsDir)/init-compiler.sh'))&quot; &quot;$(_NativeScriptsDir)&quot; &quot;$(Platform)&quot; &quot;$(CMakeCompilerToolchain)&quot;
127127
</CMakeCompilerSearchScript>
128128
</PropertyGroup>
129129
</Target>

0 commit comments

Comments
 (0)