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" " -BatchRestorePackages" "Restore product binaries (build tests)"
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" "-testOverlay" "Creating test overlay"
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
183 # Work hardcoded path around
184 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets" ]; then
185 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Core.targets" "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets"
187 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.targets" ]; then
188 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Targets" "${__BuildToolsDir}/Microsoft.CSharp.targets"
194 __TestDir=$__ProjectDir/tests
195 __ProjectFilesDir=$__TestDir
196 __TestBinDir=$__TestWorkingDir
198 if [ $__RebuildTests -ne 0 ]; then
199 if [ -d "${__TestBinDir}" ]; then
200 echo "Removing tests build dir: ${__TestBinDir}"
205 __CMakeBinDir="${__TestBinDir}"
207 if [ -z "$__TestIntermediateDir" ]; then
208 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
211 echo "__BuildOS: ${__BuildOS}"
212 echo "__BuildArch: ${__BuildArch}"
213 echo "__BuildType: ${__BuildType}"
214 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
216 if [ ! -f "$__TestBinDir" ]; then
217 echo "Creating TestBinDir: ${__TestBinDir}"
218 mkdir -p $__TestBinDir
220 if [ ! -f "$__LogsDir" ]; then
221 echo "Creating LogsDir: ${__LogsDir}"
225 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
227 # =========================================================================================
229 # === Restore product binaries from packages
231 # =========================================================================================
233 build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
235 if [ -n "$__BuildAgainstPackagesArg" ]; then
236 build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "-BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct" "Restore product binaries (run tests)"
239 echo "Starting the Managed Tests Build..."
241 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
243 if [ $? -ne 0 ]; then
244 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
247 echo "Managed tests build success!"
250 if [ $__BuildTestWrappers -ne -0 ]; then
251 echo "${__MsgPrefix}Creating test wrappers..."
253 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
255 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
257 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
259 if [ $? -ne 0 ]; then
260 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
263 echo "XUnit Wrappers have been built."
264 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
265 touch $__XUnitWrapperBuiltMarker
268 echo "XUnit Wrappers had been built before."
272 if [ -n "$__UpdateInvalidPackagesArg" ]; then
273 __up=-updateinvalidpackageversion
276 echo "${__MsgPrefix}Creating test overlay..."
280 if [ $__ZipTests -ne 0 ]; then
281 echo "${__MsgPrefix}ZIP tests packages..."
282 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
286 build_Tests_internal()
290 extraBuildParameters=$3
293 # Set up directories and file names
294 __BuildLogRootName=$subDirectoryName
295 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
296 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
297 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
298 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
299 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
300 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
302 # Generate build command
303 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"
305 echo "Building step '$stepName' via $buildCommand"
311 # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
313 # Make sure everything is OK
314 if [ $? -ne 0 ]; then
315 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
325 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
326 echo "BuildArch can be: x64, x86, arm, armel, arm64"
327 echo "BuildType can be: debug, checked, release"
328 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
329 echo "ninja - target ninja instead of GNU make"
330 echo "clangx.y - optional argument to build using clang version x.y - supported version 3.5 - 6.0"
331 echo "cross - optional argument to signify cross compilation,"
332 echo " - will use ROOTFS_DIR environment variable if set."
333 echo "crosscomponent - optional argument to build cross-architecture component,"
334 echo " - will use CAC_ROOTFS_DIR environment variable if set."
335 echo "portableLinux - build for Portable Linux Distribution"
336 echo "portablebuild - Use portable build."
337 echo "verbose - optional argument to enable verbose build output."
338 echo "rebuild - if tests have already been built - rebuild them"
339 echo "generatelayoutonly - only pull down dependencies and build coreroot"
340 echo "buildagainstpackages - pull down and build using packages."
341 echo "runtests - run tests after building them"
342 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
343 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
344 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
349 # Obtain the location of the bash script to figure out where the root of the repo is.
350 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
352 # $__ProjectRoot/build.sh $1 $2
354 # Use uname to determine what the CPU is.
357 # Some Linux platforms report unknown for platform, but the arch for machine.
358 if [ "$CPUName" == "unknown" ]; then
364 echo "Unsupported CPU $CPUName detected, build might not succeed!"
375 echo "Unsupported CPU $CPUName detected, build might not succeed!"
386 echo "Unknown CPU $CPUName detected, configuring as if for x64"
392 # Use uname to determine what the OS is.
426 echo "Unsupported OS $OSName detected, configuring as if for Linux"
434 __IncludeTests=INCLUDE_TESTS
436 # Set the various build properties here so that CMake and MSBuild can pick them up
437 export __ProjectDir="$__ProjectRoot"
438 __SourceDir="$__ProjectDir/src"
439 __PackagesDir="$__ProjectDir/packages"
440 __RootBinDir="$__ProjectDir/bin"
441 __BuildToolsDir="$__ProjectDir/Tools"
442 __UnprocessedBuildArgs=
449 __ClangMajorVersion=0
450 __ClangMinorVersion=0
451 __NuGetPath="$__PackagesDir/NuGet.exe"
453 __BuildAgainstPackagesArg=
457 __msbuildonunsupportedplatform=0
459 __NativeTestIntermediatesDir=
462 __BuildTestWrappers=0
463 __GenerateLayoutOnly=
467 if [ $# -le 0 ]; then
471 lowerI="$(echo $1 | awk '{print tolower($0)}')"
511 __CodeCoverage=Coverage
523 if [ "$__BuildOS" == "Linux" ]; then
526 echo "ERROR: portableLinux not supported for non-Linux platforms."
536 __ClangMajorVersion=3
537 __ClangMinorVersion=5
541 __ClangMajorVersion=3
542 __ClangMinorVersion=6
546 __ClangMajorVersion=3
547 __ClangMinorVersion=7
551 __ClangMajorVersion=3
552 __ClangMinorVersion=8
556 __ClangMajorVersion=3
557 __ClangMinorVersion=9
561 __ClangMajorVersion=4
562 __ClangMinorVersion=0
566 __ClangMajorVersion=5
567 __ClangMinorVersion=0
571 __ClangMajorVersion=6
572 __ClangMinorVersion=0
592 __GenerateLayoutOnly=1
595 buildagainstpackages)
596 __BuildAgainstPackagesArg=1
602 if [ ! -d $__RootBinDir ]; then
605 __RootBinParent=$(dirname $__RootBinDir)
606 __RootBinName=${__RootBinDir##*/}
607 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
610 echo "ERROR: 'bindir' requires a non-empty option argument"
615 msbuildonunsupportedplatform)
616 __msbuildonunsupportedplatform=1
619 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
627 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
629 # Configure environment if we are doing a verbose build
630 if [ $__VerboseBuild == 1 ]; then
632 __RunArgs="$__RunArgs -verbose"
635 # Set default clang version
636 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
637 if [ $__CrossBuild == 1 ]; then
638 __ClangMajorVersion=3
639 __ClangMinorVersion=6
641 __ClangMajorVersion=3
642 __ClangMinorVersion=5
647 # Set dependent variables
648 __LogsDir="$__RootBinDir/Logs"
650 # init the host distro name
653 # Set the remaining variables based upon the determined build configuration
654 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
655 __PackagesBinDir="$__BinDir/.nuget"
656 __ToolsDir="$__RootBinDir/tools"
657 __TestDir="$__ProjectDir/tests"
658 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
659 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
660 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
661 __isMSBuildOnNETCoreSupported=0
662 __CrossComponentBinDir="$__BinDir"
663 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
665 __CrossArch="$__HostArch"
666 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
669 if [ $__CrossBuild == 1 ]; then
670 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
672 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
673 __CrossgenExe="$__CrossComponentBinDir/crossgen"
675 isMSBuildOnNETCoreSupported
677 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
678 # This is needed by CLI to function.
679 if [ -z "$HOME" ]; then
680 if [ ! -d "$__ProjectDir/temp_home" ]; then
683 export HOME=$__ProjectDir/temp_home
684 echo "HOME not defined; setting it to $HOME"
687 # Specify path to be set for CMAKE_INSTALL_PREFIX.
688 # This is where all built CoreClr libraries will copied to.
689 export __CMakeBinDir="$__BinDir"
691 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
693 echo "Cannot find build directory for the CoreCLR Product or native tests."
694 echo "Please make sure CoreCLR and native tests are built before building managed tests."
695 echo "Example use: './build.sh $__BuildArch $__BuildType' without -skiptests switch"
699 # Configure environment if we are doing a cross compile.
700 if [ $__CrossBuild == 1 ]; then
701 export CROSSCOMPILE=1
702 if ! [[ -n "$ROOTFS_DIR" ]]; then
703 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
707 # init the target distro name
710 # Override tool directory
712 __CoreClrVersion=1.1.0
713 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
715 echo "Building Tests..."
717 if [ -z "$__GenerateLayoutOnly" ]; then
723 if [ $? -ne 0 ]; then
724 echo "Failed to build tests"
728 echo "${__MsgPrefix}Test build successful."
729 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
731 __testNativeBinDir=$__IntermediatesDir/tests
733 if [ $__RunTests -ne 0 ]; then
737 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
739 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
741 echo "Tests run successful."
743 echo "To run all tests use 'tests/runtests.sh' where:"
744 echo " testRootDir = $__TestBinDir"
745 echo " coreClrBinDir = $__BinDir"
746 echo " coreFxBinDir = $CORE_ROOT"
747 echo " testNativeBinDir = $__testNativeBinDir"
748 echo " -------------------------------------------------- "
749 echo " Example runtest.sh command"
751 echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
752 echo " -------------------------------------------------- "
753 echo "To run single test use the following command:"
754 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"