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 if [ "$__BuildOS" == "OSX" ]; then
36 # Portable builds target the base RID
37 if [ "$__PortableBuild" == 1 ]; then
38 if [ "$__BuildOS" == "Linux" ]; then
39 export __DistroRid="linux-$__BuildArch"
40 elif [ "$__BuildOS" == "OSX" ]; then
41 export __DistroRid="osx-$__BuildArch"
45 if [ "$ID.$VERSION_ID" == "ubuntu.16.04" ]; then
46 export __DistroRid="ubuntu.14.04-$__BuildArch"
49 echo "__DistroRid: " $__DistroRid
52 isMSBuildOnNETCoreSupported()
54 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
56 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
60 if [ "$__HostArch" == "x64" ]; then
61 if [ "$__HostOS" == "Linux" ]; then
62 __isMSBuildOnNETCoreSupported=1
63 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
64 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
66 if [ "$__HostDistroRid" == "$UNSUPPORTED_RID" ]; then
67 __isMSBuildOnNETCoreSupported=0
71 elif [ "$__HostOS" == "OSX" ]; then
72 __isMSBuildOnNETCoreSupported=1
79 __TestDir=$__ProjectDir/tests
80 __ProjectFilesDir=$__TestDir
81 __TestBinDir=$__TestWorkingDir
83 if [ $__RebuildTests -ne 0 ]; then
84 if [ -d "${__TestBinDir}" ]; then
85 echo "Removing tests build dir: ${__TestBinDir}"
90 __CMakeBinDir="${__TestBinDir}"
92 if [ -z "$__TestIntermediateDir" ]; then
93 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
96 echo "__BuildOS: ${__BuildOS}"
97 echo "__BuildArch: ${__BuildArch}"
98 echo "__BuildType: ${__BuildType}"
99 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
101 if [ ! -f "$__TestBinDir" ]; then
102 echo "Creating TestBinDir: ${__TestBinDir}"
103 mkdir -p $__TestBinDir
105 if [ ! -f "$__LogsDir" ]; then
106 echo "Creating LogsDir: ${__LogsDir}"
110 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
112 # =========================================================================================
114 # === Restore product binaries from packages
116 # =========================================================================================
118 build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
120 build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "-BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct" "Restore product binaries (run tests)"
122 if [ -n "$__UpdateInvalidPackagesArg" ]; then
123 __up=-updateinvalidpackageversion
126 # Work hardcoded path around
127 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets" ]; then
128 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Core.targets" "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets"
130 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.targets" ]; then
131 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Targets" "${__BuildToolsDir}/Microsoft.CSharp.targets"
134 echo "Starting the Managed Tests Build..."
136 __ManagedTestBuiltMarker=${__TestBinDir}/managed_test_build
138 if [ ! -f $__ManagedTestBuiltMarker ]; then
140 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
142 if [ $? -ne 0 ]; then
143 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
146 echo "Tests have been built."
147 echo "Create marker \"${__ManagedTestBuiltMarker}\""
148 touch $__ManagedTestBuiltMarker
151 echo "Managed Tests had been built before."
154 if [ $__BuildTestWrappers -ne -0 ]; then
155 echo "${__MsgPrefix}Creating test wrappers..."
157 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
159 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
161 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
163 if [ $? -ne 0 ]; then
164 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
167 echo "XUnit Wrappers have been built."
168 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
169 touch $__XUnitWrapperBuiltMarker
172 echo "XUnit Wrappers had been built before."
176 echo "${__MsgPrefix}Creating test overlay..."
178 if [ -z "$XuintTestBinBase" ]; then
179 XuintTestBinBase=$__TestWorkingDir
182 export CORE_ROOT=$XuintTestBinBase/Tests/Core_Root
184 if [ ! -f "${CORE_ROOT}" ]; then
190 cp -r $__BinDir/* $CORE_ROOT/ > /dev/null
192 build_Tests_internal "Tests_Overlay_Managed" "$__ProjectDir/tests/runtest.proj" "-testOverlay" "Creating test overlay"
194 if [ $__ZipTests -ne 0 ]; then
195 echo "${__MsgPrefix}ZIP tests packages..."
196 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
200 build_Tests_internal()
204 extraBuildParameters=$3
207 # Set up directories and file names
208 __BuildLogRootName=$subDirectoryName
209 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
210 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
211 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
212 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
213 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
214 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
216 # Generate build command
217 buildCommand="$__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog=${__msbuildLog} -MsBuildWrn=${__msbuildWrn} -MsBuildErr=${__msbuildErr} $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs"
219 echo "Building step '$stepName' via $buildCommand"
225 # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
227 # Make sure everything is OK
228 if [ $? -ne 0 ]; then
229 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
239 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
240 echo "BuildArch can be: x64, x86, arm, armel, arm64"
241 echo "BuildType can be: debug, checked, release"
242 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
243 echo "ninja - target ninja instead of GNU make"
244 echo "clangx.y - optional argument to build using clang version x.y."
245 echo "cross - optional argument to signify cross compilation,"
246 echo " - will use ROOTFS_DIR environment variable if set."
247 echo "crosscomponent - optional argument to build cross-architecture component,"
248 echo " - will use CAC_ROOTFS_DIR environment variable if set."
249 echo "portableLinux - build for Portable Linux Distribution"
250 echo "verbose - optional argument to enable verbose build output."
251 echo "rebuild - if tests have already been built - rebuild them"
252 echo "runtests - run tests after building them"
253 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
254 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
255 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
260 # Obtain the location of the bash script to figure out where the root of the repo is.
261 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
263 # $__ProjectRoot/build.sh $1 $2
265 # Use uname to determine what the CPU is.
268 # Some Linux platforms report unknown for platform, but the arch for machine.
269 if [ "$CPUName" == "unknown" ]; then
275 echo "Unsupported CPU $CPUName detected, build might not succeed!"
286 echo "Unsupported CPU $CPUName detected, build might not succeed!"
297 echo "Unknown CPU $CPUName detected, configuring as if for x64"
303 # Use uname to determine what the OS is.
337 echo "Unsupported OS $OSName detected, configuring as if for Linux"
345 __IncludeTests=INCLUDE_TESTS
347 # Set the various build properties here so that CMake and MSBuild can pick them up
348 export __ProjectDir="$__ProjectRoot"
349 __SourceDir="$__ProjectDir/src"
350 __PackagesDir="$__ProjectDir/packages"
351 __RootBinDir="$__ProjectDir/bin"
352 __BuildToolsDir="$__ProjectDir/Tools"
353 __UnprocessedBuildArgs=
360 __ClangMajorVersion=0
361 __ClangMinorVersion=0
362 __NuGetPath="$__PackagesDir/NuGet.exe"
367 __msbuildonunsupportedplatform=0
369 __NativeTestIntermediatesDir=
372 __BuildTestWrappers=0
377 if [ $# -le 0 ]; then
381 lowerI="$(echo $1 | awk '{print tolower($0)}')"
421 __CodeCoverage=Coverage
429 if [ "$__BuildOS" == "Linux" ]; then
432 echo "ERROR: portableLinux not supported for non-Linux platforms."
442 __ClangMajorVersion=3
443 __ClangMinorVersion=5
447 __ClangMajorVersion=3
448 __ClangMinorVersion=6
452 __ClangMajorVersion=3
453 __ClangMinorVersion=7
457 __ClangMajorVersion=3
458 __ClangMinorVersion=8
462 __ClangMajorVersion=3
463 __ClangMinorVersion=9
485 if [ ! -d $__RootBinDir ]; then
488 __RootBinParent=$(dirname $__RootBinDir)
489 __RootBinName=${__RootBinDir##*/}
490 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
493 echo "ERROR: 'bindir' requires a non-empty option argument"
498 msbuildonunsupportedplatform)
499 __msbuildonunsupportedplatform=1
502 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
510 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
512 # Configure environment if we are doing a verbose build
513 if [ $__VerboseBuild == 1 ]; then
515 __RunArgs="$__RunArgs -verbose"
518 # Set default clang version
519 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
520 if [ $__CrossBuild == 1 ]; then
521 __ClangMajorVersion=3
522 __ClangMinorVersion=6
524 __ClangMajorVersion=3
525 __ClangMinorVersion=5
530 # Set dependent variables
531 __LogsDir="$__RootBinDir/Logs"
533 # init the host distro name
536 # Set the remaining variables based upon the determined build configuration
537 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
538 __PackagesBinDir="$__BinDir/.nuget"
539 __ToolsDir="$__RootBinDir/tools"
540 __TestDir="$__ProjectDir/tests"
541 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
542 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
543 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
544 __isMSBuildOnNETCoreSupported=0
545 __CrossComponentBinDir="$__BinDir"
546 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
548 __CrossArch="$__HostArch"
549 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
552 if [ $__CrossBuild == 1 ]; then
553 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
555 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
556 __CrossgenExe="$__CrossComponentBinDir/crossgen"
558 isMSBuildOnNETCoreSupported
560 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
561 # This is needed by CLI to function.
562 if [ -z "$HOME" ]; then
563 if [ ! -d "$__ProjectDir/temp_home" ]; then
566 export HOME=$__ProjectDir/temp_home
567 echo "HOME not defined; setting it to $HOME"
570 # Specify path to be set for CMAKE_INSTALL_PREFIX.
571 # This is where all built CoreClr libraries will copied to.
572 export __CMakeBinDir="$__BinDir"
574 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
576 echo "Has not been found built CoreCLR instance"
577 echo "Please build it before tests using './build.sh $__BuildArch $__BuildType'"
581 # Configure environment if we are doing a cross compile.
582 if [ $__CrossBuild == 1 ]; then
583 export CROSSCOMPILE=1
584 if ! [[ -n "$ROOTFS_DIR" ]]; then
585 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
589 # init the target distro name
592 # Override tool directory
594 __CoreClrVersion=1.1.0
595 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
597 echo "Building Tests..."
601 if [ $? -ne 0 ]; then
602 echo "Failed to build tests"
606 echo "${__MsgPrefix}Test build successful."
607 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
609 __testNativeBinDir=$__IntermediatesDir/tests
611 if [ $__RunTests -ne 0 ]; then
615 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
617 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
619 echo "Tests run successful."
621 echo "To run all tests use 'tests/runtests.sh' where:"
622 echo " testRootDir = $__TestBinDir"
623 echo " coreClrBinDir = $__BinDir"
624 echo " coreFxBinDir = $CORE_ROOT"
625 echo " testNativeBinDir = $__testNativeBinDir"
626 echo " -------------------------------------------------- "
627 echo "To run single test use the following command:"
628 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"