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"
41 if [ "$ID.$VERSION_ID" == "ubuntu.16.04" ]; then
42 export __DistroRid="ubuntu.14.04-$__BuildArch"
46 isMSBuildOnNETCoreSupported()
48 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
50 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
54 if [ "$__HostArch" == "x64" ]; then
55 if [ "$__HostOS" == "Linux" ]; then
56 __isMSBuildOnNETCoreSupported=1
57 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
58 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
60 if [ "$__HostDistroRid" == "$UNSUPPORTED_RID" ]; then
61 __isMSBuildOnNETCoreSupported=0
65 elif [ "$__HostOS" == "OSX" ]; then
66 __isMSBuildOnNETCoreSupported=1
73 __TestDir=$__ProjectDir/tests
74 __ProjectFilesDir=$__TestDir
75 __TestBinDir=$__TestWorkingDir
77 if [ $__RebuildTests -ne 0 ]; then
78 if [ -d "${__TestBinDir}" ]; then
79 echo "Removing tests build dir: ${__TestBinDir}"
84 __CMakeBinDir="${__TestBinDir}"
86 if [ -z "$__TestIntermediateDir" ]; then
87 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
90 echo "__BuildOS: ${__BuildOS}"
91 echo "__BuildArch: ${__BuildArch}"
92 echo "__BuildType: ${__BuildType}"
93 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
95 if [ ! -f "$__TestBinDir" ]; then
96 echo "Creating TestBinDir: ${__TestBinDir}"
97 mkdir -p $__TestBinDir
99 if [ ! -f "$__LogsDir" ]; then
100 echo "Creating LogsDir: ${__LogsDir}"
104 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
106 # =========================================================================================
108 # === Restore product binaries from packages
110 # =========================================================================================
112 build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
114 build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "-BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct" "Restore product binaries (run tests)"
116 if [ -n "$__UpdateInvalidPackagesArg" ]; then
117 __up=-updateinvalidpackageversion
120 # Work hardcoded path around
121 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets" ]; then
122 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Core.targets" "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets"
124 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.targets" ]; then
125 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Targets" "${__BuildToolsDir}/Microsoft.CSharp.targets"
128 echo "Starting the Managed Tests Build..."
130 __ManagedTestBuiltMarker=${__TestBinDir}/managed_test_build
132 if [ ! -f $__ManagedTestBuiltMarker ]; then
134 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
136 if [ $? -ne 0 ]; then
137 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
140 echo "Tests have been built."
141 echo "Create marker \"${__ManagedTestBuiltMarker}\""
142 touch $__ManagedTestBuiltMarker
145 echo "Managed Tests had been built before."
148 if [ $__BuildTestWrappers -ne -0 ]; then
149 echo "${__MsgPrefix}Creating test wrappers..."
151 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
153 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
155 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
157 if [ $? -ne 0 ]; then
158 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
161 echo "XUnit Wrappers have been built."
162 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
163 touch $__XUnitWrapperBuiltMarker
166 echo "XUnit Wrappers had been built before."
170 echo "${__MsgPrefix}Creating test overlay..."
172 if [ -z "$XuintTestBinBase" ]; then
173 XuintTestBinBase=$__TestWorkingDir
176 export CORE_ROOT=$XuintTestBinBase/Tests/Core_Root
178 if [ ! -f "${CORE_ROOT}" ]; then
184 cp -r $__BinDir/* $CORE_ROOT/ > /dev/null
186 build_Tests_internal "Tests_Overlay_Managed" "$__ProjectDir/tests/runtest.proj" "-testOverlay" "Creating test overlay"
188 if [ $__ZipTests -ne 0 ]; then
189 echo "${__MsgPrefix}ZIP tests packages..."
190 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
194 build_Tests_internal()
198 extraBuildParameters=$3
201 # Set up directories and file names
202 __BuildLogRootName=$subDirectoryName
203 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
204 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
205 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
206 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
207 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
208 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
210 # Generate build command
211 buildCommand="$__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog=${__msbuildLog} -MsBuildWrn=${__msbuildWrn} -MsBuildErr=${__msbuildErr} $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs"
213 echo "Building step '$stepName' via $buildCommand"
219 # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
221 # Make sure everything is OK
222 if [ $? -ne 0 ]; then
223 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
233 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
234 echo "BuildArch can be: x64, x86, arm, armel, arm64"
235 echo "BuildType can be: debug, checked, release"
236 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
237 echo "ninja - target ninja instead of GNU make"
238 echo "clangx.y - optional argument to build using clang version x.y."
239 echo "cross - optional argument to signify cross compilation,"
240 echo " - will use ROOTFS_DIR environment variable if set."
241 echo "crosscomponent - optional argument to build cross-architecture component,"
242 echo " - will use CAC_ROOTFS_DIR environment variable if set."
243 echo "portableLinux - build for Portable Linux Distribution"
244 echo "verbose - optional argument to enable verbose build output."
245 echo "rebuild - if tests have already been built - rebuild them"
246 echo "runtests - run tests after building them"
247 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
248 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
249 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
254 # Obtain the location of the bash script to figure out where the root of the repo is.
255 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
257 # $__ProjectRoot/build.sh $1 $2
259 # Use uname to determine what the CPU is.
262 # Some Linux platforms report unknown for platform, but the arch for machine.
263 if [ "$CPUName" == "unknown" ]; then
269 echo "Unsupported CPU $CPUName detected, build might not succeed!"
280 echo "Unsupported CPU $CPUName detected, build might not succeed!"
291 echo "Unknown CPU $CPUName detected, configuring as if for x64"
297 # Use uname to determine what the OS is.
331 echo "Unsupported OS $OSName detected, configuring as if for Linux"
339 __IncludeTests=INCLUDE_TESTS
341 # Set the various build properties here so that CMake and MSBuild can pick them up
342 export __ProjectDir="$__ProjectRoot"
343 __SourceDir="$__ProjectDir/src"
344 __PackagesDir="$__ProjectDir/packages"
345 __RootBinDir="$__ProjectDir/bin"
346 __BuildToolsDir="$__ProjectDir/Tools"
347 __UnprocessedBuildArgs=
354 __ClangMajorVersion=0
355 __ClangMinorVersion=0
356 __NuGetPath="$__PackagesDir/NuGet.exe"
361 __msbuildonunsupportedplatform=0
363 __NativeTestIntermediatesDir=
366 __BuildTestWrappers=0
371 if [ $# -le 0 ]; then
375 lowerI="$(echo $1 | awk '{print tolower($0)}')"
415 __CodeCoverage=Coverage
423 if [ "$__BuildOS" == "Linux" ]; then
426 echo "ERROR: portableLinux not supported for non-Linux platforms."
436 __ClangMajorVersion=3
437 __ClangMinorVersion=5
441 __ClangMajorVersion=3
442 __ClangMinorVersion=6
446 __ClangMajorVersion=3
447 __ClangMinorVersion=7
451 __ClangMajorVersion=3
452 __ClangMinorVersion=8
456 __ClangMajorVersion=3
457 __ClangMinorVersion=9
479 if [ ! -d $__RootBinDir ]; then
482 __RootBinParent=$(dirname $__RootBinDir)
483 __RootBinName=${__RootBinDir##*/}
484 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
487 echo "ERROR: 'bindir' requires a non-empty option argument"
492 msbuildonunsupportedplatform)
493 __msbuildonunsupportedplatform=1
496 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
504 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
506 # Configure environment if we are doing a verbose build
507 if [ $__VerboseBuild == 1 ]; then
509 __RunArgs="$__RunArgs -verbose"
512 # Set default clang version
513 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
514 if [ $__CrossBuild == 1 ]; then
515 __ClangMajorVersion=3
516 __ClangMinorVersion=6
518 __ClangMajorVersion=3
519 __ClangMinorVersion=5
524 # Set dependent variables
525 __LogsDir="$__RootBinDir/Logs"
527 # init the host distro name
530 # Set the remaining variables based upon the determined build configuration
531 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
532 __PackagesBinDir="$__BinDir/.nuget"
533 __ToolsDir="$__RootBinDir/tools"
534 __TestDir="$__ProjectDir/tests"
535 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
536 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
537 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
538 __isMSBuildOnNETCoreSupported=0
539 __CrossComponentBinDir="$__BinDir"
540 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
542 __CrossArch="$__HostArch"
543 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
546 if [ $__CrossBuild == 1 ]; then
547 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
549 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
550 __CrossgenExe="$__CrossComponentBinDir/crossgen"
552 isMSBuildOnNETCoreSupported
554 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
555 # This is needed by CLI to function.
556 if [ -z "$HOME" ]; then
557 if [ ! -d "$__ProjectDir/temp_home" ]; then
560 export HOME=$__ProjectDir/temp_home
561 echo "HOME not defined; setting it to $HOME"
564 # Specify path to be set for CMAKE_INSTALL_PREFIX.
565 # This is where all built CoreClr libraries will copied to.
566 export __CMakeBinDir="$__BinDir"
568 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
570 echo "Has not been found built CoreCLR instance"
571 echo "Please build it before tests using './build.sh $__BuildArch $__BuildType'"
575 # Configure environment if we are doing a cross compile.
576 if [ $__CrossBuild == 1 ]; then
577 export CROSSCOMPILE=1
578 if ! [[ -n "$ROOTFS_DIR" ]]; then
579 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
583 # init the target distro name
586 # Override tool directory
588 __CoreClrVersion=1.1.0
589 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
591 echo "Building Tests..."
595 if [ $? -ne 0 ]; then
596 echo "Failed to build tests"
600 echo "${__MsgPrefix}Test build successful."
601 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
603 __testNativeBinDir=$__IntermediatesDir/tests
605 if [ $__RunTests -ne 0 ]; then
609 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
611 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
613 echo "Tests run successful."
615 echo "To run all tests use 'tests/runtests.sh' where:"
616 echo " testRootDir = $__TestBinDir"
617 echo " coreClrBinDir = $__BinDir"
618 echo " coreFxBinDir = $CORE_ROOT"
619 echo " testNativeBinDir = $__testNativeBinDir"
620 echo " -------------------------------------------------- "
621 echo "To run single test use the following command:"
622 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"