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 __ManagedTestBuiltMarker=${__TestBinDir}/managed_test_build
245 if [ ! -f $__ManagedTestBuiltMarker ]; then
247 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
249 if [ $? -ne 0 ]; then
250 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
253 echo "Tests have been built."
254 echo "Create marker \"${__ManagedTestBuiltMarker}\""
255 touch $__ManagedTestBuiltMarker
258 echo "Managed Tests had been built before."
261 if [ $__BuildTestWrappers -ne -0 ]; then
262 echo "${__MsgPrefix}Creating test wrappers..."
264 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
266 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
268 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
270 if [ $? -ne 0 ]; then
271 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
274 echo "XUnit Wrappers have been built."
275 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
276 touch $__XUnitWrapperBuiltMarker
279 echo "XUnit Wrappers had been built before."
283 if [ -n "$__UpdateInvalidPackagesArg" ]; then
284 __up=-updateinvalidpackageversion
287 echo "${__MsgPrefix}Creating test overlay..."
291 if [ $__ZipTests -ne 0 ]; then
292 echo "${__MsgPrefix}ZIP tests packages..."
293 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
297 build_Tests_internal()
301 extraBuildParameters=$3
304 # Set up directories and file names
305 __BuildLogRootName=$subDirectoryName
306 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
307 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
308 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
309 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
310 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
311 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
313 # Generate build command
314 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"
316 echo "Building step '$stepName' via $buildCommand"
322 # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
324 # Make sure everything is OK
325 if [ $? -ne 0 ]; then
326 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
336 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
337 echo "BuildArch can be: x64, x86, arm, armel, arm64"
338 echo "BuildType can be: debug, checked, release"
339 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
340 echo "ninja - target ninja instead of GNU make"
341 echo "clangx.y - optional argument to build using clang version x.y - supported version 3.5 - 6.0"
342 echo "cross - optional argument to signify cross compilation,"
343 echo " - will use ROOTFS_DIR environment variable if set."
344 echo "crosscomponent - optional argument to build cross-architecture component,"
345 echo " - will use CAC_ROOTFS_DIR environment variable if set."
346 echo "portableLinux - build for Portable Linux Distribution"
347 echo "portablebuild - Use portable build."
348 echo "verbose - optional argument to enable verbose build output."
349 echo "rebuild - if tests have already been built - rebuild them"
350 echo "generatelayoutonly - only pull down dependencies and build coreroot"
351 echo "buildagainstpackages - pull down and build using packages."
352 echo "runtests - run tests after building them"
353 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
354 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
355 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
360 # Obtain the location of the bash script to figure out where the root of the repo is.
361 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
363 # $__ProjectRoot/build.sh $1 $2
365 # Use uname to determine what the CPU is.
368 # Some Linux platforms report unknown for platform, but the arch for machine.
369 if [ "$CPUName" == "unknown" ]; then
375 echo "Unsupported CPU $CPUName detected, build might not succeed!"
386 echo "Unsupported CPU $CPUName detected, build might not succeed!"
397 echo "Unknown CPU $CPUName detected, configuring as if for x64"
403 # Use uname to determine what the OS is.
437 echo "Unsupported OS $OSName detected, configuring as if for Linux"
445 __IncludeTests=INCLUDE_TESTS
447 # Set the various build properties here so that CMake and MSBuild can pick them up
448 export __ProjectDir="$__ProjectRoot"
449 __SourceDir="$__ProjectDir/src"
450 __PackagesDir="$__ProjectDir/packages"
451 __RootBinDir="$__ProjectDir/bin"
452 __BuildToolsDir="$__ProjectDir/Tools"
453 __UnprocessedBuildArgs=
460 __ClangMajorVersion=0
461 __ClangMinorVersion=0
462 __NuGetPath="$__PackagesDir/NuGet.exe"
464 __BuildAgainstPackagesArg=
468 __msbuildonunsupportedplatform=0
470 __NativeTestIntermediatesDir=
473 __BuildTestWrappers=0
474 __GenerateLayoutOnly=
478 if [ $# -le 0 ]; then
482 lowerI="$(echo $1 | awk '{print tolower($0)}')"
522 __CodeCoverage=Coverage
534 if [ "$__BuildOS" == "Linux" ]; then
537 echo "ERROR: portableLinux not supported for non-Linux platforms."
547 __ClangMajorVersion=3
548 __ClangMinorVersion=5
552 __ClangMajorVersion=3
553 __ClangMinorVersion=6
557 __ClangMajorVersion=3
558 __ClangMinorVersion=7
562 __ClangMajorVersion=3
563 __ClangMinorVersion=8
567 __ClangMajorVersion=3
568 __ClangMinorVersion=9
572 __ClangMajorVersion=4
573 __ClangMinorVersion=0
577 __ClangMajorVersion=5
578 __ClangMinorVersion=0
582 __ClangMajorVersion=6
583 __ClangMinorVersion=0
603 __GenerateLayoutOnly=1
606 buildagainstpackages)
607 __BuildAgainstPackagesArg=1
613 if [ ! -d $__RootBinDir ]; then
616 __RootBinParent=$(dirname $__RootBinDir)
617 __RootBinName=${__RootBinDir##*/}
618 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
621 echo "ERROR: 'bindir' requires a non-empty option argument"
626 msbuildonunsupportedplatform)
627 __msbuildonunsupportedplatform=1
630 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
638 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
640 # Configure environment if we are doing a verbose build
641 if [ $__VerboseBuild == 1 ]; then
643 __RunArgs="$__RunArgs -verbose"
646 # Set default clang version
647 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
648 if [ $__CrossBuild == 1 ]; then
649 __ClangMajorVersion=3
650 __ClangMinorVersion=6
652 __ClangMajorVersion=3
653 __ClangMinorVersion=5
658 # Set dependent variables
659 __LogsDir="$__RootBinDir/Logs"
661 # init the host distro name
664 # Set the remaining variables based upon the determined build configuration
665 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
666 __PackagesBinDir="$__BinDir/.nuget"
667 __ToolsDir="$__RootBinDir/tools"
668 __TestDir="$__ProjectDir/tests"
669 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
670 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
671 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
672 __isMSBuildOnNETCoreSupported=0
673 __CrossComponentBinDir="$__BinDir"
674 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
676 __CrossArch="$__HostArch"
677 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
680 if [ $__CrossBuild == 1 ]; then
681 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
683 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
684 __CrossgenExe="$__CrossComponentBinDir/crossgen"
686 isMSBuildOnNETCoreSupported
688 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
689 # This is needed by CLI to function.
690 if [ -z "$HOME" ]; then
691 if [ ! -d "$__ProjectDir/temp_home" ]; then
694 export HOME=$__ProjectDir/temp_home
695 echo "HOME not defined; setting it to $HOME"
698 # Specify path to be set for CMAKE_INSTALL_PREFIX.
699 # This is where all built CoreClr libraries will copied to.
700 export __CMakeBinDir="$__BinDir"
702 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
704 echo "Cannot find build directory for the CoreCLR Product or native tests."
705 echo "Please make sure CoreCLR and native tests are built before building managed tests."
706 echo "Example use: './build.sh $__BuildArch $__BuildType' without -skiptests switch"
710 # Configure environment if we are doing a cross compile.
711 if [ $__CrossBuild == 1 ]; then
712 export CROSSCOMPILE=1
713 if ! [[ -n "$ROOTFS_DIR" ]]; then
714 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
718 # init the target distro name
721 # Override tool directory
723 __CoreClrVersion=1.1.0
724 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
726 echo "Building Tests..."
728 if [ -z "$__GenerateLayoutOnly" ]; then
734 if [ $? -ne 0 ]; then
735 echo "Failed to build tests"
739 echo "${__MsgPrefix}Test build successful."
740 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
742 __testNativeBinDir=$__IntermediatesDir/tests
744 if [ $__RunTests -ne 0 ]; then
748 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
750 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
752 echo "Tests run successful."
754 echo "To run all tests use 'tests/runtests.sh' where:"
755 echo " testRootDir = $__TestBinDir"
756 echo " coreClrBinDir = $__BinDir"
757 echo " coreFxBinDir = $CORE_ROOT"
758 echo " testNativeBinDir = $__testNativeBinDir"
759 echo " -------------------------------------------------- "
760 echo " Example runtest.sh command"
762 echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
763 echo " -------------------------------------------------- "
764 echo "To run single test use the following command:"
765 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"