Skip to content

Parse compiler version in init-compiler.sh #63126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions eng/common/native/init-compiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,45 @@
#
# 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"

case "$compiler" in
clang*|-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*|--gcc*)
# gccx.y or gcc-x.y
version="$(echo "$compiler" | tr -d '[:alpha:]-=')"
parts=(${version//./ })
majorVersion="${parts[0]}"
minorVersion="${parts[1]}"
compiler=gcc
;;
esac

cxxCompiler="$compiler++"
majorVersion="$4"
minorVersion="$5"

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

Expand Down
19 changes: 3 additions & 16 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ build_native()
scan_build=scan-build
fi

nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType \"$generator\" $scan_build $cmakeArgs"
nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $platformArch $__Compiler $__BuildType \"$generator\" $scan_build $cmakeArgs"
echo "Invoking $nextCommand"
eval $nextCommand

Expand Down Expand Up @@ -304,15 +304,7 @@ while :; do
;;

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

cmakeargs|-cmakeargs)
Expand Down Expand Up @@ -340,12 +332,7 @@ while :; do
;;

gcc*|-gcc*)
__Compiler=gcc
# gccx.y or gcc-x.y
version="$(echo "$lowerI" | tr -d '[:alpha:]-=')"
parts=(${version//./ })
__CompilerMajorVersion="${parts[0]}"
__CompilerMinorVersion="${parts[1]}"
__Compiler="$lowerI"
;;

keepnativesymbols|-keepnativesymbols)
Expand Down
10 changes: 3 additions & 7 deletions eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ scriptroot="$( cd -P "$( dirname "$0" )" && pwd )"

if [[ "$#" -lt 4 ]]; then
echo "Usage..."
echo "gen-buildsys.sh <path to top level CMakeLists.txt> <path to intermediate directory> <Architecture> <compiler> <compiler major version> <compiler minor version> [build flavor] [ninja] [scan-build] [cmakeargs]"
echo "gen-buildsys.sh <path to top level CMakeLists.txt> <path to intermediate directory> <Architecture> <compiler> [build flavor] [ninja] [scan-build] [cmakeargs]"
echo "Specify the path to the top level CMake file."
echo "Specify the path that the build system files are generated in."
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."
echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG."
echo "Optionally specify 'scan-build' to enable build with clang static analyzer."
echo "Use the Ninja generator instead of the Unix Makefiles generator."
Expand All @@ -23,12 +21,10 @@ fi

build_arch="$3"
compiler="$4"
majorVersion="$5"
minorVersion="$6"

if [[ "$compiler" != "default" ]]; then
nativescriptroot="$( cd -P "$scriptroot/../common/native" && pwd )"
source "$nativescriptroot/init-compiler.sh" "$nativescriptroot" "$build_arch" "$compiler" "$majorVersion" "$minorVersion"
source "$nativescriptroot/init-compiler.sh" "$nativescriptroot" "$build_arch" "$compiler"

CCC_CC="$CC"
CCC_CXX="$CXX"
Expand All @@ -43,7 +39,7 @@ scan_build=OFF
generator="Unix Makefiles"
__UnprocessedCMakeArgs=""

for i in "${@:7}"; do
for i in "${@:5}"; do
upperI="$(echo "$i" | tr "[:lower:]" "[:upper:]")"
case "$upperI" in
# Possible build types are DEBUG, CHECKED, RELEASE, RELWITHDEBINFO.
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ __CodeCoverage=0

# Set the various build properties here so that CMake and MSBuild can pick them up
__Compiler=clang
__CompilerMajorVersion=
__CompilerMinorVersion=
__CommonMSBuildArgs=
__ConfigureOnly=0
__CrossBuild=0
Expand Down
23 changes: 3 additions & 20 deletions src/coreclr/tools/aot/ObjWriter/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ RepoRoot="$2"
BuildArch="$3"
TargetArch="$4"
BuildType="${5:-Release}"
CompilerId="$(echo "$6" | tr "[:upper:]" "[:lower:]")"
Compiler="$(echo "$6" | tr "[:upper:]" "[:lower:]")"
Compiler="${Compiler:-clang}"

LLVMBranch="release/12.x"

Expand All @@ -16,24 +17,6 @@ if [ $# -lt 4 ]; then
exit 1
fi

if [ -z "$CompilerId" ]; then
Compiler=clang
CompilerMajorVer=
CompilerMinorVer=
# Expecting a compiler id similar to -clang9 or -gcc10.2. See also eng/native/build-commons.sh.
elif [[ "$CompilerId" =~ ^-?([a-z]+)(-?([0-9]+)(\.([0-9]+))?)?$ ]]; then
Compiler=${BASH_REMATCH[1]}
CompilerMajorVer=${BASH_REMATCH[3]}
CompilerMinorVer=${BASH_REMATCH[5]}
if [[ "$Compiler" == "clang" && -n "$CompilerMajorVer" && "$CompilerMajorVer" -le 6
&& -z "$CompilerMinorVer" ]]; then
CompilerMinorVer=0
fi
else
echo "Unexpected compiler identifier '$6'"
exit 1
fi

cd "$ArtifactsDir" || exit 1
PatchApplied=0

Expand Down Expand Up @@ -81,7 +64,7 @@ fi
# [build flavor] [ninja] [scan-build] [cmakeargs]
"${RepoRoot}eng/native/gen-buildsys.sh" \
"$PWD" "$PWD/build/$TargetArch" "$TargetArch" \
"$Compiler" "$CompilerMajorVer" "$CompilerMinorVer" "$BuildType" \
"$Compiler" "$BuildType" \
-DCMAKE_BUILD_TYPE="$BuildType" \
-DCMAKE_INSTALL_PREFIX=install \
-DLLVM_BUILD_TOOLS=0 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<PropertyGroup>
<NativeCompiler>$(Compiler)</NativeCompiler>
<NativeCompiler Condition="'$(NativeCompiler)' == ''">clang</NativeCompiler>
<NativeCompiler Condition="$(NativeCompiler.StartsWith('-'))">$(NativeCompiler.TrimStart('-'))</NativeCompiler>
</PropertyGroup>

<Exec Command="bash -c 'source &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &quot;$(RepositoryEngineeringDir)/common/native&quot; $(TargetArchitecture) $(NativeCompiler) &amp;&amp; echo $CC'"
Expand Down
4 changes: 0 additions & 4 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
<MonoCCompiler Condition="'$(MonoCCompiler)' == ''">clang</MonoCCompiler>
<_CompilerTargetArch Condition="'$(RealTargetArchitecture)' == ''">$(Platform)</_CompilerTargetArch>
<_CompilerTargetArch Condition="'$(RealTargetArchitecture)' != ''">$(RealTargetArchitecture)</_CompilerTargetArch>
<!-- when we use runtime/build.sh -gcc, it is passed to eng/build.sh which sets the raw value to $(Compiler); strip the leading hyphens. -->
<MonoCCompiler Condition="$(MonoCCompiler.StartsWith('-'))">$(MonoCCompiler.TrimStart('-'))</MonoCCompiler>
<MonoCxxCompiler Condition="'$(MonoCCompiler)' == 'clang'">clang++</MonoCxxCompiler>
<MonoCxxCompiler Condition="'$(MonoCCompiler)' == 'gcc'">g++</MonoCxxCompiler>
<RepositoryEngineeringCommonDir>$([MSBuild]::NormalizeDirectory('$(RepositoryEngineeringDir)', 'common'))</RepositoryEngineeringCommonDir>
<CrossToolchainFile>$([MSBuild]::NormalizePath('$(RepositoryEngineeringCommonDir)', 'cross', 'toolchain.cmake'))</CrossToolchainFile>
</PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/native/corehost/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ __TargetOS=Linux
__BuildType=Debug
__CMakeArgs=""
__Compiler=clang
__CompilerMajorVersion=
__CompilerMinorVersion=
__CrossBuild=0
__PortableBuild=1
__RootBinDir="$__RepoRootDir/artifacts"
Expand Down
2 changes: 0 additions & 2 deletions src/native/libs/build-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ __TargetOS=Linux
__BuildType=Debug
__CMakeArgs=""
__Compiler=clang
__CompilerMajorVersion=
__CompilerMinorVersion=
__CrossBuild=0
__PortableBuild=1
__RootBinDir="$__RepoRootDir/artifacts"
Expand Down
4 changes: 1 addition & 3 deletions src/tests/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ export __ProjectDir
__SkipTestWrappers=0
__BuildTestWrappersOnly=0
__Compiler=clang
__CompilerMajorVersion=
__CompilerMinorVersion=
__ConfigureOnly=0
__CopyNativeProjectsAfterCombinedTestBuild=true
__CopyNativeTestBinaries=0
Expand Down Expand Up @@ -394,7 +392,7 @@ if [[ "$__RebuildTests" -ne 0 ]]; then
echo "Removing test build dir: ${__TestBinDir}"
rm -rf "${__TestBinDir}"
echo "Removing test intermediate dir: ${__TestIntermediatesDir}"
rm -rf "${__TestIntermediatesDir}"
rm -rf "${__TestIntermediatesDir}"
fi

build_Tests
Expand Down