7 # Some OS groups should default to use the portable packages
8 if [ "$__BuildOS" == "OSX" ]; then
12 if [ "$__HostOS" == "Linux" ]; then
13 if [ -e /etc/redhat-release ]; then
14 local redhatRelease=$(</etc/redhat-release)
15 if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
16 __HostDistroRid="rhel.6-$__HostArch"
20 elif [ -e /etc/os-release ]; then
21 source /etc/os-release
22 if [[ $ID == "alpine" ]]; then
23 __HostDistroRid="linux-musl-$__HostArch"
26 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
29 elif [ "$__HostOS" == "FreeBSD" ]; then
30 __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
31 __HostDistroRid="freebsd.$__freebsd_version-$__HostArch"
34 # Portable builds target the base RID
35 if [ "$__PortableBuild" == 1 ]; then
36 if [ "$__BuildOS" == "OSX" ]; then
37 export __HostDistroRid="osx-$__BuildArch"
38 elif [ "$__BuildOS" == "Linux" ]; then
39 export __HostDistroRid="linux-$__BuildArch"
43 if [ "$__HostDistroRid" == "" ]; then
44 echo "WARNING: Cannot determine runtime id for current distro."
47 echo "Setting __HostDistroRid to $__HostDistroRid"
52 if [ $__CrossBuild == 1 ]; then
53 if [ "$__BuildOS" == "Linux" ]; then
54 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
55 if [ -e $ROOTFS_DIR/android_platform ]; then
56 source $ROOTFS_DIR/android_platform
57 export __DistroRid="$RID"
59 echo "WARNING: Cannot determine runtime id for current distro."
63 source $ROOTFS_DIR/etc/os-release
64 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
68 export __DistroRid="$__HostDistroRid"
71 if [ "$ID.$VERSION_ID" == "ubuntu.16.04" ]; then
72 export __DistroRid="ubuntu.14.04-$__BuildArch"
75 # Portable builds target the base RID
76 if [ "$__PortableBuild" == 1 ]; then
77 if [ "$__BuildOS" == "Linux" ]; then
78 export __DistroRid="linux-$__BuildArch"
79 export __RuntimeId="linux-$__BuildArch"
80 elif [ "$__BuildOS" == "OSX" ]; then
81 export __DistroRid="osx-$__BuildArch"
82 export __RuntimeId="osx-$__BuildArch"
86 echo "__DistroRid: " $__DistroRid
89 isMSBuildOnNETCoreSupported()
91 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
93 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
97 if [ "$__HostArch" == "x64" ]; then
98 if [ "$__HostOS" == "Linux" ]; then
99 __isMSBuildOnNETCoreSupported=1
100 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
101 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
103 if [ "$__HostDistroRid" == "$UNSUPPORTED_RID" ]; then
104 __isMSBuildOnNETCoreSupported=0
108 elif [ "$__HostOS" == "OSX" ]; then
109 __isMSBuildOnNETCoreSupported=1
116 __TestDir=$__ProjectDir/tests
117 __ProjectFilesDir=$__TestDir
118 __TestBinDir=$__TestWorkingDir
120 if [ $__RebuildTests -ne 0 ]; then
121 if [ -d "${__TestBinDir}" ]; then
122 echo "Removing tests build dir: ${__TestBinDir}"
127 __CMakeBinDir="${__TestBinDir}"
129 if [ -z "$__TestIntermediateDir" ]; then
130 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
133 echo "__BuildOS: ${__BuildOS}"
134 echo "__BuildArch: ${__BuildArch}"
135 echo "__BuildType: ${__BuildType}"
136 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
138 if [ ! -f "$__TestBinDir" ]; then
139 echo "Creating TestBinDir: ${__TestBinDir}"
140 mkdir -p $__TestBinDir
142 if [ ! -f "$__LogsDir" ]; then
143 echo "Creating LogsDir: ${__LogsDir}"
147 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
149 # =========================================================================================
151 # === Restore product binaries from packages
153 # =========================================================================================
155 build_Tests_internal "Restore_Packages" "${__ProjectDir}/tests/build.proj" "Restore product binaries (build tests)" "-BatchRestorePackages"
157 if [ -n "$__UpdateInvalidPackagesArg" ]; then
158 __up=-updateinvalidpackageversion
161 echo "${__MsgPrefix}Creating test overlay..."
163 if [ -z "$xUnitTestBinBase" ]; then
164 xUnitTestBinBase=$__TestWorkingDir
167 export CORE_ROOT=$xUnitTestBinBase/Tests/Core_Root
169 if [ -d "${CORE_ROOT}" ]; then
175 build_Tests_internal "Tests_Overlay_Managed" "${__ProjectDir}/tests/runtest.proj" "Creating test overlay" "-testOverlay"
177 chmod +x $__BinDir/corerun
178 chmod +x $__BinDir/crossgen
180 # Make sure to copy over the pulled down packages
181 cp -r $__BinDir/* $CORE_ROOT/ > /dev/null
187 export TEST_HOST=$xUnitTestBinBase/testhost
189 if [ -d "${TEST_HOST}" ]; then
193 echo "${__MsgPrefix}Creating test overlay..."
196 build_Tests_internal "Tests_Generate_TestHost" "${__ProjectDir}/tests/runtest.proj" "Creating test host" "-testHost"
202 __TestDir=$__ProjectDir/tests
203 __ProjectFilesDir=$__TestDir
204 __TestBinDir=$__TestWorkingDir
206 if [ $__RebuildTests -ne 0 ]; then
207 if [ -d "${__TestBinDir}" ]; then
208 echo "Removing tests build dir: ${__TestBinDir}"
213 __CMakeBinDir="${__TestBinDir}"
215 if [ -z "$__TestIntermediateDir" ]; then
216 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
219 echo "__BuildOS: ${__BuildOS}"
220 echo "__BuildArch: ${__BuildArch}"
221 echo "__BuildType: ${__BuildType}"
222 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
224 if [ ! -f "$__TestBinDir" ]; then
225 echo "Creating TestBinDir: ${__TestBinDir}"
226 mkdir -p $__TestBinDir
228 if [ ! -f "$__LogsDir" ]; then
229 echo "Creating LogsDir: ${__LogsDir}"
233 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
235 # =========================================================================================
237 # === Restore product binaries from packages
239 # =========================================================================================
241 build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" "Restore product binaries (build tests)" "-BatchRestorePackages"
243 if [ -n "$__BuildAgainstPackagesArg" ]; then
244 build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "Restore product binaries (run tests)" "-BinPlaceRef" "-BinPlaceProduct" "-CopyCrossgenToProduct"
247 echo "Starting the Managed Tests Build..."
249 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "Managed tests build (build tests)" "$__up"
251 if [ $? -ne 0 ]; then
252 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
255 echo "Checking the Managed Tests Build..."
257 if [ -n __priority1 ]; then
262 build_Tests_internal "Check_Test_Build" "${__ProjectDir}/tests/runtest.proj" "Check Test Build" "/t:CheckTestBuild /p:CLRTestPriorityToBuild=$__Priority"
264 if [ $? -ne 0 ]; then
265 echo "${__MsgPrefix}Error: Check Test Build failed."
269 echo "Managed tests build success!"
272 if [ $__BuildTestWrappers -ne -0 ]; then
273 echo "${__MsgPrefix}Creating test wrappers..."
275 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
277 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
279 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "Test Xunit Wrapper" "-BuildWrappers" "-MsBuildEventLogging= " "-TargetsWindows=false"
281 if [ $? -ne 0 ]; then
282 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
285 echo "XUnit Wrappers have been built."
286 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
287 touch $__XUnitWrapperBuiltMarker
290 echo "XUnit Wrappers had been built before."
294 if [ -n "$__UpdateInvalidPackagesArg" ]; then
295 __up=-updateinvalidpackageversion
298 echo "${__MsgPrefix}Creating test overlay..."
302 if [ $__ZipTests -ne 0 ]; then
303 echo "${__MsgPrefix}ZIP tests packages..."
304 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" "Prep test binaries for Helix publishing" " "
308 build_Tests_internal()
316 extraBuildParameters=("$@")
318 # Set up directories and file names
319 __BuildLogRootName=$subDirectoryName
320 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
321 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
322 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
324 # Use binclashlogger by default if no other logger is specified
325 if [[ "${extraBuildParameters[*]}" == *"-MsBuildEventLogging"* ]]; then
326 msbuildEventLogging=""
328 msbuildEventLogging="-MsBuildEventLogging=\"/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log\""
331 if [[ "$subDirectoryName" == "Tests_Managed" ]]; then
332 # Execute msbuild managed test build in stages - workaround for excessive data retention in MSBuild ConfigCache
333 # See https://github.com/Microsoft/msbuild/issues/2993
335 # __SkipPackageRestore and __SkipTargetingPackBuild used to control build by tests/src/dirs.proj
336 export __SkipPackageRestore=false
337 export __SkipTargetingPackBuild=false
338 export __BuildLoopCount=2
339 export __TestGroupToBuild=1
342 if [ -n __priority1 ]; then
343 export __BuildLoopCount=16
344 export __TestGroupToBuild=2
347 for (( slice=1 ; slice <= __BuildLoopCount; slice = slice + 1 ))
349 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog};Append=${__AppendToLog}\""
350 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn};Append=${__AppendToLog}\""
351 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr};Append=${__AppendToLog}\""
353 export TestBuildSlice=$slice
355 # Generate build command
356 buildArgs=("-Project=$projectName" "-MsBuildLog=${__msbuildLog}" "-MsBuildWrn=${__msbuildWrn}" "-MsBuildErr=${__msbuildErr}")
357 buildArgs+=("$msbuildEventLogging")
358 buildArgs+=("${extraBuildParameters[@]}")
359 buildArgs+=("${__RunArgs[@]}")
360 buildArgs+=("${__UnprocessedBuildArgs[@]}")
362 echo "Building step '$stepName' slice=$slice via $buildCommand"
365 "$__ProjectRoot/run.sh" build "${buildArgs[@]}"
367 # Make sure everything is OK
368 if [ $? -ne 0 ]; then
369 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
375 export __SkipPackageRestore=true
376 export __SkipTargetingPackBuild=true
380 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
381 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
382 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
384 # Generate build command
385 buildArgs=("-Project=$projectName" "-MsBuildLog=${__msbuildLog}" "-MsBuildWrn=${__msbuildWrn}" "-MsBuildErr=${__msbuildErr}")
386 buildArgs+=("$msbuildEventLogging")
387 buildArgs+=("${extraBuildParameters[@]}")
388 buildArgs+=("${__RunArgs[@]}")
389 buildArgs+=("${__UnprocessedBuildArgs[@]}")
391 echo "Building step '$stepName' via $buildCommand"
394 "$__ProjectRoot/run.sh" build "${buildArgs[@]}"
396 # Make sure everything is OK
397 if [ $? -ne 0 ]; then
398 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
409 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
410 echo "BuildArch can be: x64, x86, arm, armel, arm64"
411 echo "BuildType can be: debug, checked, release"
412 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
413 echo "ninja - target ninja instead of GNU make"
414 echo "clangx.y - optional argument to build using clang version x.y - supported version 3.5 - 6.0"
415 echo "cross - optional argument to signify cross compilation,"
416 echo " - will use ROOTFS_DIR environment variable if set."
417 echo "crosscomponent - optional argument to build cross-architecture component,"
418 echo " - will use CAC_ROOTFS_DIR environment variable if set."
419 echo "portableLinux - build for Portable Linux Distribution"
420 echo "portablebuild - Use portable build."
421 echo "verbose - optional argument to enable verbose build output."
422 echo "rebuild - if tests have already been built - rebuild them"
423 echo "generatelayoutonly - only pull down dependencies and build coreroot"
424 echo "generatetesthostonly - only pull down dependencies and build coreroot and the CoreFX testhost"
425 echo "buildagainstpackages - pull down and build using packages."
426 echo "runtests - run tests after building them"
427 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
428 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
429 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
430 echo "priority1 - include priority=1 tests in the build"
435 # Obtain the location of the bash script to figure out where the root of the repo is.
436 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
438 # $__ProjectRoot/build.sh $1 $2
440 # Use uname to determine what the CPU is.
443 # Some Linux platforms report unknown for platform, but the arch for machine.
444 if [ "$CPUName" == "unknown" ]; then
450 echo "Unsupported CPU $CPUName detected, build might not succeed!"
461 echo "Unsupported CPU $CPUName detected, build might not succeed!"
472 echo "Unknown CPU $CPUName detected, configuring as if for x64"
478 # Use uname to determine what the OS is.
512 echo "Unsupported OS $OSName detected, configuring as if for Linux"
520 __IncludeTests=INCLUDE_TESTS
522 # Set the various build properties here so that CMake and MSBuild can pick them up
523 export __ProjectDir="$__ProjectRoot"
524 __SourceDir="$__ProjectDir/src"
525 __PackagesDir="$__ProjectDir/packages"
526 __RootBinDir="$__ProjectDir/bin"
527 __BuildToolsDir="$__ProjectDir/Tools"
528 __UnprocessedBuildArgs=
535 __ClangMajorVersion=0
536 __ClangMinorVersion=0
537 __NuGetPath="$__PackagesDir/NuGet.exe"
539 __BuildAgainstPackagesArg=
543 __msbuildonunsupportedplatform=0
545 __NativeTestIntermediatesDir=
548 __BuildTestWrappers=1
549 __GenerateLayoutOnly=
550 __GenerateTestHostOnly=
555 if [ $# -le 0 ]; then
559 lowerI="$(echo $1 | awk '{print tolower($0)}')"
599 __CodeCoverage=Coverage
611 if [ "$__BuildOS" == "Linux" ]; then
614 echo "ERROR: portableLinux not supported for non-Linux platforms."
624 __ClangMajorVersion=3
625 __ClangMinorVersion=5
629 __ClangMajorVersion=3
630 __ClangMinorVersion=6
634 __ClangMajorVersion=3
635 __ClangMinorVersion=7
639 __ClangMajorVersion=3
640 __ClangMinorVersion=8
644 __ClangMajorVersion=3
645 __ClangMinorVersion=9
649 __ClangMajorVersion=4
650 __ClangMinorVersion=0
654 __ClangMajorVersion=5
655 __ClangMinorVersion=0
659 __ClangMajorVersion=6
660 __ClangMinorVersion=0
680 __GenerateLayoutOnly=1
682 generatetesthostonly)
683 __GenerateTestHostOnly=1
685 buildagainstpackages)
686 __BuildAgainstPackagesArg=1
692 if [ ! -d $__RootBinDir ]; then
695 __RootBinParent=$(dirname $__RootBinDir)
696 __RootBinName=${__RootBinDir##*/}
697 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
700 echo "ERROR: 'bindir' requires a non-empty option argument"
705 msbuildonunsupportedplatform)
706 __msbuildonunsupportedplatform=1
710 __UnprocessedBuildArgs+=("-priority=1")
713 __UnprocessedBuildArgs+=("$1")
721 __RunArgs=("-BuildArch=$__BuildArch" "-BuildType=$__BuildType" "-BuildOS=$__BuildOS")
723 # Configure environment if we are doing a verbose build
724 if [ $__VerboseBuild == 1 ]; then
726 __RunArgs+=("-verbose")
729 # Set default clang version
730 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
731 if [ $__CrossBuild == 1 ]; then
732 __ClangMajorVersion=3
733 __ClangMinorVersion=6
735 __ClangMajorVersion=3
736 __ClangMinorVersion=5
741 # Set dependent variables
742 __LogsDir="$__RootBinDir/Logs"
744 # init the host distro name
747 # Set the remaining variables based upon the determined build configuration
748 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
749 __PackagesBinDir="$__BinDir/.nuget"
750 __ToolsDir="$__RootBinDir/tools"
751 __TestDir="$__ProjectDir/tests"
752 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
753 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
754 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
755 __isMSBuildOnNETCoreSupported=0
756 __CrossComponentBinDir="$__BinDir"
757 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
759 __CrossArch="$__HostArch"
760 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
763 if [ $__CrossBuild == 1 ]; then
764 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
766 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
767 __CrossgenExe="$__CrossComponentBinDir/crossgen"
769 isMSBuildOnNETCoreSupported
771 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to it.
772 # This is needed by CLI to function.
773 if [ -z "$HOME" ]; then
774 if [ ! -d "$__ProjectDir/temp_home" ]; then
777 export HOME=$__ProjectDir/temp_home
778 echo "HOME not defined; setting it to $HOME"
781 # Specify path to be set for CMAKE_INSTALL_PREFIX.
782 # This is where all built CoreClr libraries will copied to.
783 export __CMakeBinDir="$__BinDir"
784 if [ [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ] ]; then
785 if [ [ -z "$__GenerateLayoutOnly" ] && [ -z "$__GenerateTestHostOnly" ] ]; then
787 echo "Cannot find build directory for the CoreCLR native tests."
788 echo "Please make sure native tests are built before building managed tests."
789 echo "Example use: './build.sh $__BuildArch $__BuildType' without -skiptests switch"
791 echo "Cannot find build directory for the CoreCLR Product."
792 echo "Please make sure CoreCLR and native tests are built before building managed tests."
793 echo "Example use: './build.sh $__BuildArch $__BuildType' "
800 # Configure environment if we are doing a cross compile.
801 if [ $__CrossBuild == 1 ]; then
802 export CROSSCOMPILE=1
803 if ! [[ -n "$ROOTFS_DIR" ]]; then
804 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
808 # init the target distro name
811 # Override tool directory
813 __CoreClrVersion=1.1.0
814 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
817 if [[ (-z "$__GenerateLayoutOnly") && (-z "$__GenerateTestHostOnly") ]]; then
818 echo "Building Tests..."
821 echo "Generating test layout..."
823 if [ ! -z "$__GenerateTestHostOnly" ]; then
824 echo "Generating test host..."
829 if [ $? -ne 0 ]; then
830 echo "Failed to build tests"
834 echo "${__MsgPrefix}Test build successful."
835 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
837 __testNativeBinDir=$__IntermediatesDir/tests
839 if [ $__RunTests -ne 0 ]; then
843 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
845 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
847 echo "Tests run successful."
849 echo "To run all tests use 'tests/runtests.sh' where:"
850 echo " testRootDir = $__TestBinDir"
851 echo " coreClrBinDir = $__BinDir"
852 echo " coreFxBinDir = $CORE_ROOT"
853 echo " testNativeBinDir = $__testNativeBinDir"
854 echo " -------------------------------------------------- "
855 echo " Example runtest.sh command"
857 echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
858 echo " -------------------------------------------------- "
859 echo "To run single test use the following command:"
860 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"