Skip to content

Commit

Permalink
Parse compiler version in init-compiler.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Dec 24, 2021
1 parent 1a66526 commit 3cb8075
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions eng/common/native/init-compiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,44 @@
#
# This file detects the C/C++ compiler and exports it to the CC/CXX environment variables
#
# NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here!
# NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here!

if [[ "$#" -lt 3 ]]; then
echo "Usage..."
echo "init-compiler.sh <script directory> <Architecture> <compiler> <compiler major version> <compiler minor version>"
echo "init-compiler.sh <script directory> <Architecture> <compiler>"
echo "Specify the script directory."
echo "Specify the target architecture."
echo "Specify the name of compiler (clang or gcc)."
echo "Specify the major version of compiler."
echo "Specify the minor version of compiler."
exit 1
fi

nativescriptroot="$1"
build_arch="$2"
compiler="$3"
cxxCompiler="$compiler++"
majorVersion="$4"
minorVersion="$5"

case "$compiler" in
clang*|-clang*)
# clangx.y or clang-x.y
version="$(echo "$compiler" | tr -d '[:alpha:]-=')"
parts=(${version//./ })
majorVersion="${parts[0]}"
minorVersion="${parts[1]}"
if [[ -z "$minorVersion" && "$majorVersion" -le 6 ]]; then
minorVersion=0;
fi
compiler=clang
;;

gcc*|-gcc*)
# gccx.y or gcc-x.y
version="$(echo "$compiler" | tr -d '[:alpha:]-=')"
parts=(${version//./ })
majorVersion="${parts[0]}"
minorVersion="${parts[1]}"
compiler=gcc
;;
esac

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<PropertyGroup>
<_NativeScriptsDir>$([MSBuild]::NormalizeDirectory('$(RepositoryEngineeringDir)', 'common', 'native'))</_NativeScriptsDir>
<CMakeCompilerSearchScript>
. &quot;$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '$(_NativeScriptsDir)/init-compiler.sh'))&quot; &quot;$(_NativeScriptsDir)&quot; &quot;$(Platform)&quot; &quot;$(CMakeCompilerToolchain)&quot; &quot;$(CMakeCompilerMajorVersion)&quot; &quot;$(CMakeCompilerMinorVersion)&quot;
. &quot;$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '$(_NativeScriptsDir)/init-compiler.sh'))&quot; &quot;$(_NativeScriptsDir)&quot; &quot;$(Platform)&quot; &quot;$(CMakeCompilerToolchain)&quot;
</CMakeCompilerSearchScript>
</PropertyGroup>
</Target>
Expand Down

0 comments on commit 3cb8075

Please sign in to comment.