5 if [ "$__HostOS" == "Linux" ]; then
6 if [ ! -e /etc/os-release ]; then
7 echo "WARNING: Can not determine runtime id for current distro."
10 source /etc/os-release
11 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
18 if [ $__CrossBuild == 1 ]; then
19 if [ "$__BuildOS" == "Linux" ]; then
20 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
21 echo "WARNING: Can not determine runtime id for current distro."
24 source $ROOTFS_DIR/etc/os-release
25 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
29 export __DistroRid="$__HostDistroRid"
32 # Portable builds target the base RID
33 if [ "$__PortableBuild" == 1 ]; then
34 if [ "$__BuildOS" == "Linux" ]; then
35 export __DistroRid="linux-$__BuildArch"
36 elif [ "$__BuildOS" == "OSX" ]; then
37 export __DistroRid="osx-$__BuildArch"
42 isMSBuildOnNETCoreSupported()
44 # This needs to be updated alongwith corresponding changes to netci.groovy.
45 __isMSBuildOnNETCoreSupported=0
47 if [ "$__HostArch" == "x64" ]; then
48 if [ "$__HostOS" == "Linux" ]; then
49 case "$__HostDistroRid" in
51 __isMSBuildOnNETCoreSupported=1
54 __isMSBuildOnNETCoreSupported=1
57 __isMSBuildOnNETCoreSupported=1
60 __isMSBuildOnNETCoreSupported=1
63 __isMSBuildOnNETCoreSupported=1
66 __isMSBuildOnNETCoreSupported=1
69 __isMSBuildOnNETCoreSupported=1
72 __isMSBuildOnNETCoreSupported=1
75 __isMSBuildOnNETCoreSupported=1
78 __isMSBuildOnNETCoreSupported=1
81 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
83 elif [ "$__HostOS" == "OSX" ]; then
84 __isMSBuildOnNETCoreSupported=1
91 __TestDir=$__ProjectDir/tests
92 __ProjectFilesDir=$__TestDir
93 __TestBinDir=$__TestWorkingDir
95 if [ $__RebuildTests -ne 0 ]; then
96 if [ -d "${__TestBinDir}" ]; then
97 echo "Removing tests build dir: ${__TestBinDir}"
102 __CMakeBinDir="${__TestBinDir}"
104 if [ -z "$__TestIntermediateDir" ]; then
105 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
108 echo "__BuildOS: ${__BuildOS}"
109 echo "__BuildArch: ${__BuildArch}"
110 echo "__BuildType: ${__BuildType}"
111 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
113 if [ ! -f "$__TestBinDir" ]; then
114 echo "Creating TestBinDir: ${__TestBinDir}"
115 mkdir -p $__TestBinDir
117 if [ ! -f "$__LogsDir" ]; then
118 echo "Creating LogsDir: ${__LogsDir}"
122 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
124 # =========================================================================================
126 # === Restore product binaries from packages
128 # =========================================================================================
130 if [ -z "$XunitTestBinBase"]; then
131 XunitTestBinBase="$__TestWorkingDir"
134 export CORE_ROOT="$XunitTestBinBase/Tests/Core_Root"
136 if [ ! -f "${CORE_ROOT}" ]; then
137 mkdir -p ${CORE_ROOT}
142 cp -r $__BinDir/* $CORE_ROOT/ > /dev/null
144 # make sure the correct ilasm will be used
145 export CscToolPath="${CORE_ROOT}"
147 build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
149 build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "-BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct" "Restore product binaries (run tests)"
151 if [ -n "$__UpdateInvalidPackagesArg" ]; then
152 __up=-updateinvalidpackageversion
155 # Work hardcoded path around
156 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets" ]; then
157 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Core.targets" "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets"
159 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.targets" ]; then
160 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Targets" "${__BuildToolsDir}/Microsoft.CSharp.targets"
163 echo "Starting the Managed Tests Build..."
165 __ManagedTestBuiltMarker=${__TestBinDir}/managed_test_build
167 if [ ! -f $__ManagedTestBuiltMarker ]; then
169 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
171 if [ $? -ne 0 ]; then
172 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
175 echo "Tests have been built."
176 echo "Create marker \"${__ManagedTestBuiltMarker}\""
177 touch $__ManagedTestBuiltMarker
180 echo "Managed Tests had been built before."
183 if [ $__BuildTestWrappers -ne -0 ]; then
184 echo "${__MsgPrefix}Creating test wrappers..."
186 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
188 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
190 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
192 if [ $? -ne 0 ]; then
193 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
196 echo "XUnit Wrappers have been built."
197 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
198 touch $__XUnitWrapperBuiltMarker
201 echo "XUnit Wrappers had been built before."
205 echo "${__MsgPrefix}Creating test overlay..."
207 build_Tests_internal "Tests_Overlay_Managed" "$__ProjectDir/tests/runtest.proj" "-testOverlay" "Creating test overlay"
209 if [ $__ZipTests -ne 0 ]; then
210 echo "${__MsgPrefix}ZIP tests packages..."
211 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
215 build_Tests_internal()
219 extraBuildParameters=$3
222 # Set up directories and file names
223 __BuildLogRootName=$subDirectoryName
224 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
225 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
226 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
227 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
228 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
229 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
231 # Generate build command
232 buildCommand="$__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog=${__msbuildLog} -MsBuildWrn=${__msbuildWrn} -MsBuildErr=${__msbuildErr} $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs"
234 echo "Building step '$stepName' via $buildCommand"
240 # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
242 # Make sure everything is OK
243 if [ $? -ne 0 ]; then
244 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
254 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
255 echo "BuildArch can be: x64, x86, arm, armel, arm64"
256 echo "BuildType can be: debug, checked, release"
257 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
258 echo "ninja - target ninja instead of GNU make"
259 echo "clangx.y - optional argument to build using clang version x.y."
260 echo "cross - optional argument to signify cross compilation,"
261 echo " - will use ROOTFS_DIR environment variable if set."
262 echo "crosscomponent - optional argument to build cross-architecture component,"
263 echo " - will use CAC_ROOTFS_DIR environment variable if set."
264 echo "portableLinux - build for Portable Linux Distribution"
265 echo "verbose - optional argument to enable verbose build output."
266 echo "rebuild - if tests have already been built - rebuild them"
267 echo "runtests - run tests after building them"
268 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
269 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
270 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
275 # Obtain the location of the bash script to figure out where the root of the repo is.
276 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
278 # $__ProjectRoot/build.sh $1 $2
280 # Use uname to determine what the CPU is.
283 # Some Linux platforms report unknown for platform, but the arch for machine.
284 if [ "$CPUName" == "unknown" ]; then
290 echo "Unsupported CPU $CPUName detected, build might not succeed!"
301 echo "Unsupported CPU $CPUName detected, build might not succeed!"
312 echo "Unknown CPU $CPUName detected, configuring as if for x64"
318 # Use uname to determine what the OS is.
352 echo "Unsupported OS $OSName detected, configuring as if for Linux"
360 __IncludeTests=INCLUDE_TESTS
362 # Set the various build properties here so that CMake and MSBuild can pick them up
363 export __ProjectDir="$__ProjectRoot"
364 __SourceDir="$__ProjectDir/src"
365 __PackagesDir="$__ProjectDir/packages"
366 __RootBinDir="$__ProjectDir/bin"
367 __BuildToolsDir="$__ProjectDir/Tools"
368 __UnprocessedBuildArgs=
375 __ClangMajorVersion=0
376 __ClangMinorVersion=0
377 __NuGetPath="$__PackagesDir/NuGet.exe"
382 __msbuildonunsupportedplatform=0
384 __NativeTestIntermediatesDir=
387 __BuildTestWrappers=0
392 if [ $# -le 0 ]; then
396 lowerI="$(echo $1 | awk '{print tolower($0)}')"
436 __CodeCoverage=Coverage
444 if [ "$__BuildOS" == "Linux" ]; then
447 echo "ERROR: portableLinux not supported for non-Linux platforms."
457 __ClangMajorVersion=3
458 __ClangMinorVersion=5
462 __ClangMajorVersion=3
463 __ClangMinorVersion=6
467 __ClangMajorVersion=3
468 __ClangMinorVersion=7
472 __ClangMajorVersion=3
473 __ClangMinorVersion=8
477 __ClangMajorVersion=3
478 __ClangMinorVersion=9
500 if [ ! -d $__RootBinDir ]; then
503 __RootBinParent=$(dirname $__RootBinDir)
504 __RootBinName=${__RootBinDir##*/}
505 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
508 echo "ERROR: 'bindir' requires a non-empty option argument"
513 msbuildonunsupportedplatform)
514 __msbuildonunsupportedplatform=1
517 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
525 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
527 # Configure environment if we are doing a verbose build
528 if [ $__VerboseBuild == 1 ]; then
530 __RunArgs="$__RunArgs -verbose"
533 # Set default clang version
534 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
535 if [ $__CrossBuild == 1 ]; then
536 __ClangMajorVersion=3
537 __ClangMinorVersion=6
539 __ClangMajorVersion=3
540 __ClangMinorVersion=5
545 # Set dependent variables
546 __LogsDir="$__RootBinDir/Logs"
548 # init the host distro name
551 # Set the remaining variables based upon the determined build configuration
552 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
553 __PackagesBinDir="$__BinDir/.nuget"
554 __ToolsDir="$__RootBinDir/tools"
555 __TestDir="$__ProjectDir/tests"
556 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
557 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
558 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
559 __isMSBuildOnNETCoreSupported=0
560 __CrossComponentBinDir="$__BinDir"
561 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
563 __CrossArch="$__HostArch"
564 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
567 if [ $__CrossBuild == 1 ]; then
568 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
570 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
571 __CrossgenExe="$__CrossComponentBinDir/crossgen"
573 isMSBuildOnNETCoreSupported
575 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
576 # This is needed by CLI to function.
577 if [ -z "$HOME" ]; then
578 if [ ! -d "$__ProjectDir/temp_home" ]; then
581 export HOME=$__ProjectDir/temp_home
582 echo "HOME not defined; setting it to $HOME"
585 # Specify path to be set for CMAKE_INSTALL_PREFIX.
586 # This is where all built CoreClr libraries will copied to.
587 export __CMakeBinDir="$__BinDir"
589 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
591 echo "Has not been found built CoreCLR instance"
592 echo "Please build it before tests using './build.sh $__BuildArch $__BuildType'"
596 # Configure environment if we are doing a cross compile.
597 if [ $__CrossBuild == 1 ]; then
598 export CROSSCOMPILE=1
599 if ! [[ -n "$ROOTFS_DIR" ]]; then
600 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
604 # init the target distro name
607 # Override tool directory
609 __CoreClrVersion=1.1.0
610 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
612 echo "Building Tests..."
616 if [ $? -ne 0 ]; then
617 echo "Failed to build tests"
621 echo "${__MsgPrefix}Test build successful."
622 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
624 __testNativeBinDir=$__IntermediatesDir/tests
626 if [ $__RunTests -ne 0 ]; then
630 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
632 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
634 echo "Tests run successful."
636 echo "To run all tests use 'tests/runtests.sh' where:"
637 echo " testRootDir = $__TestBinDir"
638 echo " coreClrBinDir = $__BinDir"
639 echo " coreFxBinDir = $CORE_ROOT"
640 echo " testNativeBinDir = $__testNativeBinDir"
641 echo " -------------------------------------------------- "
642 echo "To run single test use the following command:"
643 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"