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 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
46 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
50 if [ "$__HostArch" == "x64" ]; then
51 if [ "$__HostOS" == "Linux" ]; then
52 __isMSBuildOnNETCoreSupported=1
53 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
54 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
56 if [ "$__HostDistroRid" == "$UNSUPPORTED_RID" ]; then
57 __isMSBuildOnNETCoreSupported=0
61 elif [ "$__HostOS" == "OSX" ]; then
62 __isMSBuildOnNETCoreSupported=1
69 __TestDir=$__ProjectDir/tests
70 __ProjectFilesDir=$__TestDir
71 __TestBinDir=$__TestWorkingDir
73 if [ $__RebuildTests -ne 0 ]; then
74 if [ -d "${__TestBinDir}" ]; then
75 echo "Removing tests build dir: ${__TestBinDir}"
80 __CMakeBinDir="${__TestBinDir}"
82 if [ -z "$__TestIntermediateDir" ]; then
83 __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
86 echo "__BuildOS: ${__BuildOS}"
87 echo "__BuildArch: ${__BuildArch}"
88 echo "__BuildType: ${__BuildType}"
89 echo "__TestIntermediateDir: ${__TestIntermediateDir}"
91 if [ ! -f "$__TestBinDir" ]; then
92 echo "Creating TestBinDir: ${__TestBinDir}"
93 mkdir -p $__TestBinDir
95 if [ ! -f "$__LogsDir" ]; then
96 echo "Creating LogsDir: ${__LogsDir}"
100 __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
102 # =========================================================================================
104 # === Restore product binaries from packages
106 # =========================================================================================
108 build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
110 build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "-BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct" "Restore product binaries (run tests)"
112 if [ -n "$__UpdateInvalidPackagesArg" ]; then
113 __up=-updateinvalidpackageversion
116 # Work hardcoded path around
117 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets" ]; then
118 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Core.targets" "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets"
120 if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.targets" ]; then
121 ln -s "${__BuildToolsDir}/Microsoft.CSharp.Targets" "${__BuildToolsDir}/Microsoft.CSharp.targets"
124 echo "Starting the Managed Tests Build..."
126 __ManagedTestBuiltMarker=${__TestBinDir}/managed_test_build
128 if [ ! -f $__ManagedTestBuiltMarker ]; then
130 build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
132 if [ $? -ne 0 ]; then
133 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
136 echo "Tests have been built."
137 echo "Create marker \"${__ManagedTestBuiltMarker}\""
138 touch $__ManagedTestBuiltMarker
141 echo "Managed Tests had been built before."
144 if [ $__BuildTestWrappers -ne -0 ]; then
145 echo "${__MsgPrefix}Creating test wrappers..."
147 __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
149 if [ ! -f $__XUnitWrapperBuiltMarker ]; then
151 build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
153 if [ $? -ne 0 ]; then
154 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
157 echo "XUnit Wrappers have been built."
158 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
159 touch $__XUnitWrapperBuiltMarker
162 echo "XUnit Wrappers had been built before."
166 echo "${__MsgPrefix}Creating test overlay..."
168 if [ -z "$XuintTestBinBase" ]; then
169 XuintTestBinBase=$__TestWorkingDir
172 export CORE_ROOT=$XuintTestBinBase/Tests/Core_Root
174 if [ ! -f "${CORE_ROOT}" ]; then
180 cp -r $__BinDir/* $CORE_ROOT/ > /dev/null
182 build_Tests_internal "Tests_Overlay_Managed" "$__ProjectDir/tests/runtest.proj" "-testOverlay" "Creating test overlay"
184 if [ $__ZipTests -ne 0 ]; then
185 echo "${__MsgPrefix}ZIP tests packages..."
186 build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
190 build_Tests_internal()
194 extraBuildParameters=$3
197 # Set up directories and file names
198 __BuildLogRootName=$subDirectoryName
199 __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
200 __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
201 __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
202 __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
203 __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
204 __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
206 # Generate build command
207 buildCommand="$__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog=${__msbuildLog} -MsBuildWrn=${__msbuildWrn} -MsBuildErr=${__msbuildErr} $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs"
209 echo "Building step '$stepName' via $buildCommand"
215 # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
217 # Make sure everything is OK
218 if [ $? -ne 0 ]; then
219 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
229 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
230 echo "BuildArch can be: x64, x86, arm, armel, arm64"
231 echo "BuildType can be: debug, checked, release"
232 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
233 echo "ninja - target ninja instead of GNU make"
234 echo "clangx.y - optional argument to build using clang version x.y."
235 echo "cross - optional argument to signify cross compilation,"
236 echo " - will use ROOTFS_DIR environment variable if set."
237 echo "crosscomponent - optional argument to build cross-architecture component,"
238 echo " - will use CAC_ROOTFS_DIR environment variable if set."
239 echo "portableLinux - build for Portable Linux Distribution"
240 echo "verbose - optional argument to enable verbose build output."
241 echo "rebuild - if tests have already been built - rebuild them"
242 echo "runtests - run tests after building them"
243 echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
244 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
245 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
250 # Obtain the location of the bash script to figure out where the root of the repo is.
251 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
253 # $__ProjectRoot/build.sh $1 $2
255 # Use uname to determine what the CPU is.
258 # Some Linux platforms report unknown for platform, but the arch for machine.
259 if [ "$CPUName" == "unknown" ]; then
265 echo "Unsupported CPU $CPUName detected, build might not succeed!"
276 echo "Unsupported CPU $CPUName detected, build might not succeed!"
287 echo "Unknown CPU $CPUName detected, configuring as if for x64"
293 # Use uname to determine what the OS is.
327 echo "Unsupported OS $OSName detected, configuring as if for Linux"
335 __IncludeTests=INCLUDE_TESTS
337 # Set the various build properties here so that CMake and MSBuild can pick them up
338 export __ProjectDir="$__ProjectRoot"
339 __SourceDir="$__ProjectDir/src"
340 __PackagesDir="$__ProjectDir/packages"
341 __RootBinDir="$__ProjectDir/bin"
342 __BuildToolsDir="$__ProjectDir/Tools"
343 __UnprocessedBuildArgs=
350 __ClangMajorVersion=0
351 __ClangMinorVersion=0
352 __NuGetPath="$__PackagesDir/NuGet.exe"
357 __msbuildonunsupportedplatform=0
359 __NativeTestIntermediatesDir=
362 __BuildTestWrappers=0
367 if [ $# -le 0 ]; then
371 lowerI="$(echo $1 | awk '{print tolower($0)}')"
411 __CodeCoverage=Coverage
419 if [ "$__BuildOS" == "Linux" ]; then
422 echo "ERROR: portableLinux not supported for non-Linux platforms."
432 __ClangMajorVersion=3
433 __ClangMinorVersion=5
437 __ClangMajorVersion=3
438 __ClangMinorVersion=6
442 __ClangMajorVersion=3
443 __ClangMinorVersion=7
447 __ClangMajorVersion=3
448 __ClangMinorVersion=8
452 __ClangMajorVersion=3
453 __ClangMinorVersion=9
475 if [ ! -d $__RootBinDir ]; then
478 __RootBinParent=$(dirname $__RootBinDir)
479 __RootBinName=${__RootBinDir##*/}
480 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
483 echo "ERROR: 'bindir' requires a non-empty option argument"
488 msbuildonunsupportedplatform)
489 __msbuildonunsupportedplatform=1
492 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
500 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
502 # Configure environment if we are doing a verbose build
503 if [ $__VerboseBuild == 1 ]; then
505 __RunArgs="$__RunArgs -verbose"
508 # Set default clang version
509 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
510 if [ $__CrossBuild == 1 ]; then
511 __ClangMajorVersion=3
512 __ClangMinorVersion=6
514 __ClangMajorVersion=3
515 __ClangMinorVersion=5
520 # Set dependent variables
521 __LogsDir="$__RootBinDir/Logs"
523 # init the host distro name
526 # Set the remaining variables based upon the determined build configuration
527 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
528 __PackagesBinDir="$__BinDir/.nuget"
529 __ToolsDir="$__RootBinDir/tools"
530 __TestDir="$__ProjectDir/tests"
531 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
532 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
533 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
534 __isMSBuildOnNETCoreSupported=0
535 __CrossComponentBinDir="$__BinDir"
536 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
538 __CrossArch="$__HostArch"
539 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
542 if [ $__CrossBuild == 1 ]; then
543 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
545 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
546 __CrossgenExe="$__CrossComponentBinDir/crossgen"
548 isMSBuildOnNETCoreSupported
550 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
551 # This is needed by CLI to function.
552 if [ -z "$HOME" ]; then
553 if [ ! -d "$__ProjectDir/temp_home" ]; then
556 export HOME=$__ProjectDir/temp_home
557 echo "HOME not defined; setting it to $HOME"
560 # Specify path to be set for CMAKE_INSTALL_PREFIX.
561 # This is where all built CoreClr libraries will copied to.
562 export __CMakeBinDir="$__BinDir"
564 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
566 echo "Has not been found built CoreCLR instance"
567 echo "Please build it before tests using './build.sh $__BuildArch $__BuildType'"
571 # Configure environment if we are doing a cross compile.
572 if [ $__CrossBuild == 1 ]; then
573 export CROSSCOMPILE=1
574 if ! [[ -n "$ROOTFS_DIR" ]]; then
575 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
579 # init the target distro name
582 # Override tool directory
584 __CoreClrVersion=1.1.0
585 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
587 echo "Building Tests..."
591 if [ $? -ne 0 ]; then
592 echo "Failed to build tests"
596 echo "${__MsgPrefix}Test build successful."
597 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
599 __testNativeBinDir=$__IntermediatesDir/tests
601 if [ $__RunTests -ne 0 ]; then
605 echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
607 $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
609 echo "Tests run successful."
611 echo "To run all tests use 'tests/runtests.sh' where:"
612 echo " testRootDir = $__TestBinDir"
613 echo " coreClrBinDir = $__BinDir"
614 echo " coreFxBinDir = $CORE_ROOT"
615 echo " testNativeBinDir = $__testNativeBinDir"
616 echo " -------------------------------------------------- "
617 echo "To run single test use the following command:"
618 echo " bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"