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 # remove the last version digit
24 VERSION_ID=${VERSION_ID%.*}
29 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
31 elif [ "$__HostOS" == "FreeBSD" ]; then
32 __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
33 __HostDistroRid="freebsd.$__freebsd_version-$__HostArch"
36 # Portable builds target the base RID
37 if [ "$__PortableBuild" == 1 ]; then
38 if [ "$__BuildOS" == "OSX" ]; then
39 export __HostDistroRid="osx-$__BuildArch"
40 elif [ "$__BuildOS" == "Linux" ]; then
41 export __HostDistroRid="linux-$__BuildArch"
45 if [ "$__HostDistroRid" == "" ]; then
46 echo "WARNING: Cannot determine runtime id for current distro."
49 echo "Setting __HostDistroRid to $__HostDistroRid"
54 if [ $__CrossBuild == 1 ]; then
55 if [ "$__BuildOS" == "Linux" ]; then
56 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
57 if [ -e $ROOTFS_DIR/android_platform ]; then
58 source $ROOTFS_DIR/android_platform
59 export __DistroRid="$RID"
61 echo "WARNING: Cannot determine runtime id for current distro."
65 source $ROOTFS_DIR/etc/os-release
66 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
70 export __DistroRid="$__HostDistroRid"
73 if [ "$ID.$VERSION_ID" == "ubuntu.16.04" ]; then
74 export __DistroRid="ubuntu.14.04-$__BuildArch"
77 # Portable builds target the base RID
78 if [ "$__PortableBuild" == 1 ]; then
79 if [ "$__BuildOS" == "Linux" ]; then
80 export __DistroRid="linux-$__BuildArch"
81 export __RuntimeId="linux-$__BuildArch"
82 elif [ "$__BuildOS" == "OSX" ]; then
83 export __DistroRid="osx-$__BuildArch"
84 export __RuntimeId="osx-$__BuildArch"
88 echo "__DistroRid: " $__DistroRid
91 isMSBuildOnNETCoreSupported()
93 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
95 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
99 if [ "$__HostArch" == "x64" ]; then
100 if [ "$__HostOS" == "Linux" ]; then
101 __isMSBuildOnNETCoreSupported=1
102 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
103 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
105 if [ "$__HostDistroRid" == "$UNSUPPORTED_RID" ]; then
106 __isMSBuildOnNETCoreSupported=0
110 elif [ "$__HostOS" == "OSX" ]; then
111 __isMSBuildOnNETCoreSupported=1
118 __TestDir=$__ProjectDir/tests
119 __ProjectFilesDir=$__TestDir
120 __TestBinDir=$__TestWorkingDir
122 if [ $__RebuildTests -ne 0 ]; then
123 if [ -d "${__TestBinDir}" ]; then
124 echo "Removing tests build dir: ${__TestBinDir}"
129 __CMakeBinDir="${__TestBinDir}"
131 if [ -z "$__TestIntermediateDir" ]; then
132 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
135 echo "__BuildOS: ${__BuildOS}"
136 echo "__BuildArch: ${__BuildArch}"
137 echo "__BuildType: ${__BuildType}"
138 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
140 if [ ! -f "$__TestBinDir" ]; then
141 echo "Creating TestBinDir: ${__TestBinDir}"
142 mkdir -p $__TestBinDir
144 if [ ! -f "$__LogsDir" ]; then
145 echo "Creating LogsDir: ${__LogsDir}"
149 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
151 # =========================================================================================
153 # === Restore product binaries from packages
155 # =========================================================================================
157 build_Tests_internal "Restore_Packages" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
159 if [ -n "$__UpdateInvalidPackagesArg" ]; then
160 __up=-updateinvalidpackageversion
163 echo "${__MsgPrefix}Creating test overlay..."
165 if [ -z "$xUnitTestBinBase" ]; then
166 xUnitTestBinBase=$__TestWorkingDir
169 export CORE_ROOT=$xUnitTestBinBase/Tests/Core_Root
171 if [ -d "${CORE_ROOT}" ]; then
177 build_Tests_internal "Tests_Overlay_Managed" "${__ProjectDir}/tests/runtest.proj" "-testOverlay" "Creating test overlay"
179 chmod +x $__BinDir/corerun
180 chmod +x $__BinDir/crossgen
182 # Make sure to copy over the pulled down packages
183 cp -r $__BinDir/* $CORE_ROOT/ > /dev/null
185 # Work hardcoded path around
186 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets" ]; then
187 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Core.targets" "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets"
189 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.targets" ]; then
190 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Targets" "${__BuildToolsDir}/Microsoft.CSharp.targets"
196 __TestDir=$__ProjectDir/tests
197 __ProjectFilesDir=$__TestDir
198 __TestBinDir=$__TestWorkingDir
200 if [ $__RebuildTests -ne 0 ]; then
201 if [ -d "${__TestBinDir}" ]; then
202 echo "Removing tests build dir: ${__TestBinDir}"
207 __CMakeBinDir="${__TestBinDir}"
209 if [ -z "$__TestIntermediateDir" ]; then
210 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
213 echo "__BuildOS: ${__BuildOS}"
214 echo "__BuildArch: ${__BuildArch}"
215 echo "__BuildType: ${__BuildType}"
216 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
218 if [ ! -f "$__TestBinDir" ]; then
219 echo "Creating TestBinDir: ${__TestBinDir}"
220 mkdir -p $__TestBinDir
222 if [ ! -f "$__LogsDir" ]; then
223 echo "Creating LogsDir: ${__LogsDir}"
227 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
229 # =========================================================================================
231 # === Restore product binaries from packages
233 # =========================================================================================
235 build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
237 if [ -n "$__BuildAgainstPackagesArg" ]; then
238 build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "-BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct" "Restore product binaries (run tests)"
241 echo "Starting the Managed Tests Build..."
243 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
245 if [ $? -ne 0 ]; then
246 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
249 echo "Managed tests build success!"
252 if [ $__BuildTestWrappers -ne -0 ]; then
253 echo "${__MsgPrefix}Creating test wrappers..."
255 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
257 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
259 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
261 if [ $? -ne 0 ]; then
262 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
265 echo "XUnit Wrappers have been built."
266 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
267 touch $__XUnitWrapperBuiltMarker
270 echo "XUnit Wrappers had been built before."
274 if [ -n "$__UpdateInvalidPackagesArg" ]; then
275 __up=-updateinvalidpackageversion
278 echo "${__MsgPrefix}Creating test overlay..."
282 if [ $__ZipTests -ne 0 ]; then
283 echo "${__MsgPrefix}ZIP tests packages..."
284 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
288 build_Tests_internal()
292 extraBuildParameters=$3
295 # Set up directories and file names
296 __BuildLogRootName=$subDirectoryName
297 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
298 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
299 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
300 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
301 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
302 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
304 # Generate build command
305 buildCommand="$__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog=${__msbuildLog} -MsBuildWrn=${__msbuildWrn} -MsBuildErr=${__msbuildErr} -MsBuildEventLogging=\"/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log\" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs"
307 echo "Building step '$stepName' via $buildCommand"
313 # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
315 # Make sure everything is OK
316 if [ $? -ne 0 ]; then
317 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
327 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
328 echo "BuildArch can be: x64, x86, arm, armel, arm64"
329 echo "BuildType can be: debug, checked, release"
330 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
331 echo "ninja - target ninja instead of GNU make"
332 echo "clangx.y - optional argument to build using clang version x.y - supported version 3.5 - 6.0"
333 echo "cross - optional argument to signify cross compilation,"
334 echo " - will use ROOTFS_DIR environment variable if set."
335 echo "crosscomponent - optional argument to build cross-architecture component,"
336 echo " - will use CAC_ROOTFS_DIR environment variable if set."
337 echo "portableLinux - build for Portable Linux Distribution"
338 echo "portablebuild - Use portable build."
339 echo "verbose - optional argument to enable verbose build output."
340 echo "rebuild - if tests have already been built - rebuild them"
341 echo "generatelayoutonly - only pull down dependencies and build coreroot"
342 echo "buildagainstpackages - pull down and build using packages."
343 echo "runtests - run tests after building them"
344 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
345 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
346 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
351 # Obtain the location of the bash script to figure out where the root of the repo is.
352 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
354 # $__ProjectRoot/build.sh $1 $2
356 # Use uname to determine what the CPU is.
359 # Some Linux platforms report unknown for platform, but the arch for machine.
360 if [ "$CPUName" == "unknown" ]; then
366 echo "Unsupported CPU $CPUName detected, build might not succeed!"
377 echo "Unsupported CPU $CPUName detected, build might not succeed!"
388 echo "Unknown CPU $CPUName detected, configuring as if for x64"
394 # Use uname to determine what the OS is.
428 echo "Unsupported OS $OSName detected, configuring as if for Linux"
436 __IncludeTests=INCLUDE_TESTS
438 # Set the various build properties here so that CMake and MSBuild can pick them up
439 export __ProjectDir="$__ProjectRoot"
440 __SourceDir="$__ProjectDir/src"
441 __PackagesDir="$__ProjectDir/packages"
442 __RootBinDir="$__ProjectDir/bin"
443 __BuildToolsDir="$__ProjectDir/Tools"
444 __UnprocessedBuildArgs=
451 __ClangMajorVersion=0
452 __ClangMinorVersion=0
453 __NuGetPath="$__PackagesDir/NuGet.exe"
455 __BuildAgainstPackagesArg=
459 __msbuildonunsupportedplatform=0
461 __NativeTestIntermediatesDir=
464 __BuildTestWrappers=0
465 __GenerateLayoutOnly=
469 if [ $# -le 0 ]; then
473 lowerI="$(echo $1 | awk '{print tolower($0)}')"
513 __CodeCoverage=Coverage
525 if [ "$__BuildOS" == "Linux" ]; then
528 echo "ERROR: portableLinux not supported for non-Linux platforms."
538 __ClangMajorVersion=3
539 __ClangMinorVersion=5
543 __ClangMajorVersion=3
544 __ClangMinorVersion=6
548 __ClangMajorVersion=3
549 __ClangMinorVersion=7
553 __ClangMajorVersion=3
554 __ClangMinorVersion=8
558 __ClangMajorVersion=3
559 __ClangMinorVersion=9
563 __ClangMajorVersion=4
564 __ClangMinorVersion=0
568 __ClangMajorVersion=5
569 __ClangMinorVersion=0
573 __ClangMajorVersion=6
574 __ClangMinorVersion=0
594 __GenerateLayoutOnly=1
597 buildagainstpackages)
598 __BuildAgainstPackagesArg=1
604 if [ ! -d $__RootBinDir ]; then
607 __RootBinParent=$(dirname $__RootBinDir)
608 __RootBinName=${__RootBinDir##*/}
609 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
612 echo "ERROR: 'bindir' requires a non-empty option argument"
617 msbuildonunsupportedplatform)
618 __msbuildonunsupportedplatform=1
621 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
629 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
631 # Configure environment if we are doing a verbose build
632 if [ $__VerboseBuild == 1 ]; then
634 __RunArgs="$__RunArgs -verbose"
637 # Set default clang version
638 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
639 if [ $__CrossBuild == 1 ]; then
640 __ClangMajorVersion=3
641 __ClangMinorVersion=6
643 __ClangMajorVersion=3
644 __ClangMinorVersion=5
649 # Set dependent variables
650 __LogsDir="$__RootBinDir/Logs"
652 # init the host distro name
655 # Set the remaining variables based upon the determined build configuration
656 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
657 __PackagesBinDir="$__BinDir/.nuget"
658 __ToolsDir="$__RootBinDir/tools"
659 __TestDir="$__ProjectDir/tests"
660 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
661 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
662 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
663 __isMSBuildOnNETCoreSupported=0
664 __CrossComponentBinDir="$__BinDir"
665 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
667 __CrossArch="$__HostArch"
668 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
671 if [ $__CrossBuild == 1 ]; then
672 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
674 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
675 __CrossgenExe="$__CrossComponentBinDir/crossgen"
677 isMSBuildOnNETCoreSupported
679 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
680 # This is needed by CLI to function.
681 if [ -z "$HOME" ]; then
682 if [ ! -d "$__ProjectDir/temp_home" ]; then
685 export HOME=$__ProjectDir/temp_home
686 echo "HOME not defined; setting it to $HOME"
689 # Specify path to be set for CMAKE_INSTALL_PREFIX.
690 # This is where all built CoreClr libraries will copied to.
691 export __CMakeBinDir="$__BinDir"
693 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
695 echo "Cannot find build directory for the CoreCLR Product or native tests."
696 echo "Please make sure CoreCLR and native tests are built before building managed tests."
697 echo "Example use: './build.sh $__BuildArch $__BuildType' without -skiptests switch"
701 # Configure environment if we are doing a cross compile.
702 if [ $__CrossBuild == 1 ]; then
703 export CROSSCOMPILE=1
704 if ! [[ -n "$ROOTFS_DIR" ]]; then
705 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
709 # init the target distro name
712 # Override tool directory
714 __CoreClrVersion=1.1.0
715 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
717 echo "Building Tests..."
719 if [ -z "$__GenerateLayoutOnly" ]; then
725 if [ $? -ne 0 ]; then
726 echo "Failed to build tests"
730 echo "${__MsgPrefix}Test build successful."
731 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
733 __testNativeBinDir=$__IntermediatesDir/tests
735 if [ $__RunTests -ne 0 ]; then
739 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
741 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
743 echo "Tests run successful."
745 echo "To run all tests use 'tests/runtests.sh' where:"
746 echo " testRootDir = $__TestBinDir"
747 echo " coreClrBinDir = $__BinDir"
748 echo " coreFxBinDir = $CORE_ROOT"
749 echo " testNativeBinDir = $__testNativeBinDir"
750 echo " -------------------------------------------------- "
751 echo " Example runtest.sh command"
753 echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
754 echo " -------------------------------------------------- "
755 echo "To run single test use the following command:"
756 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"