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."
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
588 __GenerateLayoutOnly=1
591 buildagainstpackages)
592 __BuildAgainstPackagesArg=1
598 if [ ! -d $__RootBinDir ]; then
601 __RootBinParent=$(dirname $__RootBinDir)
602 __RootBinName=${__RootBinDir##*/}
603 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
606 echo "ERROR: 'bindir' requires a non-empty option argument"
611 msbuildonunsupportedplatform)
612 __msbuildonunsupportedplatform=1
615 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
623 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
625 # Configure environment if we are doing a verbose build
626 if [ $__VerboseBuild == 1 ]; then
628 __RunArgs="$__RunArgs -verbose"
631 # Set default clang version
632 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
633 if [ $__CrossBuild == 1 ]; then
634 __ClangMajorVersion=3
635 __ClangMinorVersion=6
637 __ClangMajorVersion=3
638 __ClangMinorVersion=5
643 # Set dependent variables
644 __LogsDir="$__RootBinDir/Logs"
646 # init the host distro name
649 # Set the remaining variables based upon the determined build configuration
650 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
651 __PackagesBinDir="$__BinDir/.nuget"
652 __ToolsDir="$__RootBinDir/tools"
653 __TestDir="$__ProjectDir/tests"
654 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
655 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
656 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
657 __isMSBuildOnNETCoreSupported=0
658 __CrossComponentBinDir="$__BinDir"
659 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
661 __CrossArch="$__HostArch"
662 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
665 if [ $__CrossBuild == 1 ]; then
666 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
668 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
669 __CrossgenExe="$__CrossComponentBinDir/crossgen"
671 isMSBuildOnNETCoreSupported
673 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
674 # This is needed by CLI to function.
675 if [ -z "$HOME" ]; then
676 if [ ! -d "$__ProjectDir/temp_home" ]; then
679 export HOME=$__ProjectDir/temp_home
680 echo "HOME not defined; setting it to $HOME"
683 # Specify path to be set for CMAKE_INSTALL_PREFIX.
684 # This is where all built CoreClr libraries will copied to.
685 export __CMakeBinDir="$__BinDir"
687 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
689 echo "Cannot find build directory for the CoreCLR Product."
690 echo "Please make sure CoreCLR is built before building tests."
691 echo "Example use: './build.sh $__BuildArch $__BuildType'"
695 # Configure environment if we are doing a cross compile.
696 if [ $__CrossBuild == 1 ]; then
697 export CROSSCOMPILE=1
698 if ! [[ -n "$ROOTFS_DIR" ]]; then
699 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
703 # init the target distro name
706 # Override tool directory
708 __CoreClrVersion=1.1.0
709 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
711 echo "Building Tests..."
713 if [ -z "$__GenerateLayoutOnly" ]; then
719 if [ $? -ne 0 ]; then
720 echo "Failed to build tests"
724 echo "${__MsgPrefix}Test build successful."
725 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
727 __testNativeBinDir=$__IntermediatesDir/tests
729 if [ $__RunTests -ne 0 ]; then
733 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
735 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
737 echo "Tests run successful."
739 echo "To run all tests use 'tests/runtests.sh' where:"
740 echo " testRootDir = $__TestBinDir"
741 echo " coreClrBinDir = $__BinDir"
742 echo " coreFxBinDir = $CORE_ROOT"
743 echo " testNativeBinDir = $__testNativeBinDir"
744 echo " -------------------------------------------------- "
745 echo " Example runtest.sh command"
747 echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
748 echo " -------------------------------------------------- "
749 echo "To run single test use the following command:"
750 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"