Merge pull request #17697 from mikedn/vec-hnd
[platform/upstream/coreclr.git] / build-test.sh
1 #!/usr/bin/env bash
2
3 initHostDistroRid()
4 {
5     __HostDistroRid=""
6
7     # Some OS groups should default to use the portable packages
8     if [ "$__BuildOS" == "OSX" ]; then
9         __PortableBuild=1
10     fi
11
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"
17             else
18                 __PortableBuild=1
19             fi
20         elif [ -e /etc/os-release ]; then
21             source /etc/os-release
22             if [[ $ID == "alpine" ]]; then
23                 # remove the last version digit
24                 VERSION_ID=${VERSION_ID%.*}
25             else
26                 __PortableBuild=1
27             fi
28
29             __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
30         fi        
31     elif [ "$__HostOS" == "FreeBSD" ]; then
32         __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
33         __HostDistroRid="freebsd.$__freebsd_version-$__HostArch"
34     fi
35
36     # Portable builds target the base RID
37     if [ "$__PortableBuild" == 1 ]; then
38         if [ "$__BuildOS" == "OSX" ]; then
39             export __HostDistroRid="osx-$__BuildArch"
40         elif [ "$__BuildOS" == "Linux" ]; then
41             export __HostDistroRid="linux-$__BuildArch"
42         fi
43     fi
44
45     if [ "$__HostDistroRid" == "" ]; then
46         echo "WARNING: Cannot determine runtime id for current distro."
47     fi
48
49     echo "Setting __HostDistroRid to $__HostDistroRid"
50 }
51
52 initTargetDistroRid()
53 {
54     if [ $__CrossBuild == 1 ]; then
55         if [ "$__BuildOS" == "Linux" ]; then
56             if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
57                 if [ -e $ROOTFS_DIR/android_platform ]; then
58                     source $ROOTFS_DIR/android_platform
59                     export __DistroRid="$RID"
60                 else
61                     echo "WARNING: Cannot determine runtime id for current distro."
62                     export __DistroRid=""
63                 fi
64             else
65                 source $ROOTFS_DIR/etc/os-release
66                 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
67             fi
68         fi
69     else
70         export __DistroRid="$__HostDistroRid"
71     fi
72
73     if [ "$ID.$VERSION_ID" == "ubuntu.16.04" ]; then
74      export __DistroRid="ubuntu.14.04-$__BuildArch"
75     fi
76
77     # Portable builds target the base RID
78     if [ "$__PortableBuild" == 1 ]; then
79         if [ "$__BuildOS" == "Linux" ]; then
80             export __DistroRid="linux-$__BuildArch"
81             export __RuntimeId="linux-$__BuildArch"
82         elif [ "$__BuildOS" == "OSX" ]; then
83             export __DistroRid="osx-$__BuildArch"
84             export __RuntimeId="osx-$__BuildArch"
85         fi
86     fi
87
88     echo "__DistroRid: " $__DistroRid
89 }
90
91 isMSBuildOnNETCoreSupported()
92 {
93     __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
94
95     if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
96         return
97     fi
98
99     if [ "$__HostArch" == "x64" ]; then
100         if [ "$__HostOS" == "Linux" ]; then
101             __isMSBuildOnNETCoreSupported=1
102             UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
103             for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
104             do
105                 if [ "$__HostDistroRid" == "$UNSUPPORTED_RID" ]; then
106                     __isMSBuildOnNETCoreSupported=0
107                     break
108                 fi
109             done
110         elif [ "$__HostOS" == "OSX" ]; then
111             __isMSBuildOnNETCoreSupported=1
112         fi
113     fi
114 }
115
116 generate_layout()
117 {
118     __TestDir=$__ProjectDir/tests
119     __ProjectFilesDir=$__TestDir
120     __TestBinDir=$__TestWorkingDir
121
122     if [ $__RebuildTests -ne 0 ]; then
123         if [ -d "${__TestBinDir}" ]; then
124             echo "Removing tests build dir: ${__TestBinDir}"
125             rm -rf $__TestBinDir
126         fi
127     fi
128
129     __CMakeBinDir="${__TestBinDir}"
130
131     if [ -z "$__TestIntermediateDir" ]; then
132         __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
133     fi
134
135     echo "__BuildOS: ${__BuildOS}"
136     echo "__BuildArch: ${__BuildArch}"
137     echo "__BuildType: ${__BuildType}"
138     echo "__TestIntermediateDir: ${__TestIntermediateDir}"
139
140     if [ ! -f "$__TestBinDir" ]; then
141         echo "Creating TestBinDir: ${__TestBinDir}"
142         mkdir -p $__TestBinDir
143     fi
144     if [ ! -f "$__LogsDir" ]; then
145         echo "Creating LogsDir: ${__LogsDir}"
146         mkdir -p $__LogsDir
147     fi
148
149     __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
150
151     # =========================================================================================
152     # ===
153     # === Restore product binaries from packages
154     # ===
155     # =========================================================================================
156
157     build_Tests_internal "Restore_Packages" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
158
159     if [ -n "$__UpdateInvalidPackagesArg" ]; then
160         __up=-updateinvalidpackageversion
161     fi
162
163     echo "${__MsgPrefix}Creating test overlay..."
164
165     if [ -z "$xUnitTestBinBase" ]; then
166       xUnitTestBinBase=$__TestWorkingDir
167     fi
168
169     export CORE_ROOT=$xUnitTestBinBase/Tests/Core_Root
170
171     if [ -d "${CORE_ROOT}" ]; then
172       rm -rf $CORE_ROOT
173     fi
174
175     mkdir -p $CORE_ROOT
176
177     build_Tests_internal "Tests_Overlay_Managed" "${__ProjectDir}/tests/runtest.proj" "-testOverlay" "Creating test overlay"
178
179     chmod +x $__BinDir/corerun
180     chmod +x $__BinDir/crossgen
181
182     # Make sure to copy over the pulled down packages
183     cp -r $__BinDir/* $CORE_ROOT/ > /dev/null
184
185     # Work hardcoded path around
186     if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets" ]; then
187         ln -s "${__BuildToolsDir}/Microsoft.CSharp.Core.targets" "${__BuildToolsDir}/Microsoft.CSharp.Core.Targets"
188     fi
189     if [ ! -f "${__BuildToolsDir}/Microsoft.CSharp.targets" ]; then
190         ln -s "${__BuildToolsDir}/Microsoft.CSharp.Targets" "${__BuildToolsDir}/Microsoft.CSharp.targets"
191     fi
192 }
193
194 build_Tests()
195 {
196     __TestDir=$__ProjectDir/tests
197     __ProjectFilesDir=$__TestDir
198     __TestBinDir=$__TestWorkingDir
199
200     if [ $__RebuildTests -ne 0 ]; then
201         if [ -d "${__TestBinDir}" ]; then
202             echo "Removing tests build dir: ${__TestBinDir}"
203             rm -rf $__TestBinDir
204         fi
205     fi
206
207     __CMakeBinDir="${__TestBinDir}"
208
209     if [ -z "$__TestIntermediateDir" ]; then
210         __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
211     fi
212
213     echo "__BuildOS: ${__BuildOS}"
214     echo "__BuildArch: ${__BuildArch}"
215     echo "__BuildType: ${__BuildType}"
216     echo "__TestIntermediateDir: ${__TestIntermediateDir}"
217
218     if [ ! -f "$__TestBinDir" ]; then
219         echo "Creating TestBinDir: ${__TestBinDir}"
220         mkdir -p $__TestBinDir
221     fi
222     if [ ! -f "$__LogsDir" ]; then
223         echo "Creating LogsDir: ${__LogsDir}"
224         mkdir -p $__LogsDir
225     fi
226
227     __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
228
229     # =========================================================================================
230     # ===
231     # === Restore product binaries from packages
232     # ===
233     # =========================================================================================
234
235     build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" " -BatchRestorePackages" "Restore product binaries (build tests)"
236
237     if [ -n "$__BuildAgainstPackagesArg" ]; then
238         build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "-BinPlaceRef -BinPlaceProduct -CopyCrossgenToProduct" "Restore product binaries (run tests)"
239     fi
240
241     echo "Starting the Managed Tests Build..."
242
243     build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
244
245     if [ $? -ne 0 ]; then
246         echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
247         exit 1
248     else
249         echo "Managed tests build success!"
250     fi
251
252     if [ $__BuildTestWrappers -ne -0 ]; then
253         echo "${__MsgPrefix}Creating test wrappers..."
254
255         __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
256
257         if [ ! -f $__XUnitWrapperBuiltMarker ]; then
258
259             build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
260
261             if [ $? -ne 0 ]; then
262                 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
263                 exit 1
264             else
265                 echo "XUnit Wrappers have been built."
266                 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
267                 touch $__XUnitWrapperBuiltMarker
268             fi
269         else
270             echo "XUnit Wrappers had been built before."
271         fi
272     fi
273
274     if [ -n "$__UpdateInvalidPackagesArg" ]; then
275         __up=-updateinvalidpackageversion
276     fi
277
278     echo "${__MsgPrefix}Creating test overlay..."
279
280     generate_layout
281
282     if [ $__ZipTests -ne 0 ]; then
283         echo "${__MsgPrefix}ZIP tests packages..."
284         build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
285     fi
286 }
287
288 build_Tests_internal()
289 {
290     subDirectoryName=$1
291     projectName=$2
292     extraBuildParameters=$3
293     stepName="$4"
294
295     # Set up directories and file names
296     __BuildLogRootName=$subDirectoryName
297     __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
298     __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
299     __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
300     __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
301     __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
302     __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
303
304     # Generate build command
305     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"
306
307     echo "Building step '$stepName' via $buildCommand"
308
309     # Invoke MSBuild
310     eval $buildCommand
311
312     # Invoke MSBuild
313     # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
314
315     # Make sure everything is OK
316     if [ $? -ne 0 ]; then
317         echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
318         echo "    $__BuildLog"
319         echo "    $__BuildWrn"
320         echo "    $__BuildErr"
321         exit 1
322     fi
323 }
324
325 usage()
326 {
327     echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
328     echo "BuildArch can be: x64, x86, arm, armel, arm64"
329     echo "BuildType can be: debug, checked, release"
330     echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
331     echo "ninja - target ninja instead of GNU make"
332     echo "clangx.y - optional argument to build using clang version x.y - supported version 3.5 - 6.0"
333     echo "cross - optional argument to signify cross compilation,"
334     echo "      - will use ROOTFS_DIR environment variable if set."
335     echo "crosscomponent - optional argument to build cross-architecture component,"
336     echo "               - will use CAC_ROOTFS_DIR environment variable if set."
337     echo "portableLinux - build for Portable Linux Distribution"
338     echo "portablebuild - Use portable build."
339     echo "verbose - optional argument to enable verbose build output."
340     echo "rebuild - if tests have already been built - rebuild them"
341     echo "generatelayoutonly - only pull down dependencies and build coreroot"
342     echo "buildagainstpackages - pull down and build using packages."
343     echo "runtests - run tests after building them"
344     echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
345     echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
346     echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
347     exit 1
348 }
349
350
351 # Obtain the location of the bash script to figure out where the root of the repo is.
352 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
353
354 # $__ProjectRoot/build.sh $1 $2
355
356 # Use uname to determine what the CPU is.
357 CPUName=$(uname -p)
358
359 # Some Linux platforms report unknown for platform, but the arch for machine.
360 if [ "$CPUName" == "unknown" ]; then
361     CPUName=$(uname -m)
362 fi
363
364 case $CPUName in
365     i686)
366         echo "Unsupported CPU $CPUName detected, build might not succeed!"
367         __BuildArch=x86
368         __HostArch=x86
369         ;;
370
371     x86_64)
372         __BuildArch=x64
373         __HostArch=x64
374         ;;
375
376     armv7l)
377         echo "Unsupported CPU $CPUName detected, build might not succeed!"
378         __BuildArch=arm
379         __HostArch=arm
380         ;;
381
382     aarch64)
383         __BuildArch=arm64
384         __HostArch=arm64
385         ;;
386
387     *)
388         echo "Unknown CPU $CPUName detected, configuring as if for x64"
389         __BuildArch=x64
390         __HostArch=x64
391         ;;
392 esac
393
394 # Use uname to determine what the OS is.
395 OSName=$(uname -s)
396 case $OSName in
397     Linux)
398         __BuildOS=Linux
399         __HostOS=Linux
400         ;;
401
402     Darwin)
403         __BuildOS=OSX
404         __HostOS=OSX
405         ;;
406
407     FreeBSD)
408         __BuildOS=FreeBSD
409         __HostOS=FreeBSD
410         ;;
411
412     OpenBSD)
413         __BuildOS=OpenBSD
414         __HostOS=OpenBSD
415         ;;
416
417     NetBSD)
418         __BuildOS=NetBSD
419         __HostOS=NetBSD
420         ;;
421
422     SunOS)
423         __BuildOS=SunOS
424         __HostOS=SunOS
425         ;;
426
427     *)
428         echo "Unsupported OS $OSName detected, configuring as if for Linux"
429         __BuildOS=Linux
430         __HostOS=Linux
431         ;;
432 esac
433
434 __BuildType=Debug
435 __CodeCoverage=
436 __IncludeTests=INCLUDE_TESTS
437
438 # Set the various build properties here so that CMake and MSBuild can pick them up
439 export __ProjectDir="$__ProjectRoot"
440 __SourceDir="$__ProjectDir/src"
441 __PackagesDir="$__ProjectDir/packages"
442 __RootBinDir="$__ProjectDir/bin"
443 __BuildToolsDir="$__ProjectDir/Tools"
444 __UnprocessedBuildArgs=
445 __RunArgs=
446 __MSBCleanBuildArgs=
447 __UseNinja=0
448 __VerboseBuild=0
449 __SkipRestore=""
450 __CrossBuild=0
451 __ClangMajorVersion=0
452 __ClangMinorVersion=0
453 __NuGetPath="$__PackagesDir/NuGet.exe"
454 __HostDistroRid=""
455 __BuildAgainstPackagesArg=
456 __DistroRid=""
457 __cmakeargs=""
458 __PortableLinux=0
459 __msbuildonunsupportedplatform=0
460 __ZipTests=0
461 __NativeTestIntermediatesDir=
462 __RunTests=0
463 __RebuildTests=0
464 __BuildTestWrappers=0
465 __GenerateLayoutOnly=
466 CORE_ROOT=
467
468 while :; do
469     if [ $# -le 0 ]; then
470         break
471     fi
472
473     lowerI="$(echo $1 | awk '{print tolower($0)}')"
474     case $lowerI in
475         -\?|-h|--help)
476             usage
477             exit 1
478             ;;
479
480         x86)
481             __BuildArch=x86
482             ;;
483
484         x64)
485             __BuildArch=x64
486             ;;
487
488         arm)
489             __BuildArch=arm
490             ;;
491
492         armel)
493             __BuildArch=armel
494             ;;
495
496         arm64)
497             __BuildArch=arm64
498             ;;
499
500         debug)
501             __BuildType=Debug
502             ;;
503
504         checked)
505             __BuildType=Checked
506             ;;
507
508         release)
509             __BuildType=Release
510             ;;
511
512         coverage)
513             __CodeCoverage=Coverage
514             ;;
515
516         cross)
517             __CrossBuild=1
518             ;;
519
520         portableBuild)
521             __PortableBuild=1
522             ;;
523
524         portablelinux)
525             if [ "$__BuildOS" == "Linux" ]; then
526                 __PortableLinux=1
527             else
528                 echo "ERROR: portableLinux not supported for non-Linux platforms."
529                 exit 1
530             fi
531             ;;
532
533         verbose)
534         __VerboseBuild=1
535         ;;
536
537         clang3.5|-clang3.5)
538             __ClangMajorVersion=3
539             __ClangMinorVersion=5
540             ;;
541
542         clang3.6|-clang3.6)
543             __ClangMajorVersion=3
544             __ClangMinorVersion=6
545             ;;
546
547         clang3.7|-clang3.7)
548             __ClangMajorVersion=3
549             __ClangMinorVersion=7
550             ;;
551
552         clang3.8|-clang3.8)
553             __ClangMajorVersion=3
554             __ClangMinorVersion=8
555             ;;
556
557         clang3.9|-clang3.9)
558             __ClangMajorVersion=3
559             __ClangMinorVersion=9
560             ;;
561
562         clang4.0|-clang4.0)
563             __ClangMajorVersion=4
564             __ClangMinorVersion=0
565             ;;
566
567         clang5.0|-clang5.0)
568             __ClangMajorVersion=5
569             __ClangMinorVersion=0
570             ;;
571
572         clang6.0|-clang6.0)
573             __ClangMajorVersion=6
574             __ClangMinorVersion=0
575             ;;
576
577         ninja)
578             __UseNinja=1
579             ;;
580
581         runtests)
582             __RunTests=1
583             ;;
584
585         rebuild)
586             __RebuildTests=1
587             ;;
588
589         ziptests)
590             __ZipTests=1
591             ;;
592
593         generatelayoutonly)
594             __GenerateLayoutOnly=1
595             ;;
596
597         buildagainstpackages)
598             __BuildAgainstPackagesArg=1
599             ;;
600
601         bindir)
602             if [ -n "$2" ]; then
603                 __RootBinDir="$2"
604                 if [ ! -d $__RootBinDir ]; then
605                     mkdir $__RootBinDir
606                 fi
607                 __RootBinParent=$(dirname $__RootBinDir)
608                 __RootBinName=${__RootBinDir##*/}
609                 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
610                 shift
611             else
612                 echo "ERROR: 'bindir' requires a non-empty option argument"
613                 exit 1
614             fi
615             ;;
616
617         msbuildonunsupportedplatform)
618             __msbuildonunsupportedplatform=1
619             ;;
620         *)
621             __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
622             ;;
623     esac
624
625     shift
626 done
627
628
629 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
630
631 # Configure environment if we are doing a verbose build
632 if [ $__VerboseBuild == 1 ]; then
633     export VERBOSE=1
634     __RunArgs="$__RunArgs -verbose"
635 fi
636
637 # Set default clang version
638 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
639     if [ $__CrossBuild == 1 ]; then
640         __ClangMajorVersion=3
641         __ClangMinorVersion=6
642     else
643         __ClangMajorVersion=3
644         __ClangMinorVersion=5
645     fi
646 fi
647
648
649 # Set dependent variables
650 __LogsDir="$__RootBinDir/Logs"
651
652 # init the host distro name
653 initHostDistroRid
654
655 # Set the remaining variables based upon the determined build configuration
656 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
657 __PackagesBinDir="$__BinDir/.nuget"
658 __ToolsDir="$__RootBinDir/tools"
659 __TestDir="$__ProjectDir/tests"
660 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
661 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
662 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
663 __isMSBuildOnNETCoreSupported=0
664 __CrossComponentBinDir="$__BinDir"
665 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
666
667 __CrossArch="$__HostArch"
668 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
669     __CrossArch="x86"
670 fi
671 if [ $__CrossBuild == 1 ]; then
672     __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
673 fi
674 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
675 __CrossgenExe="$__CrossComponentBinDir/crossgen"
676
677 isMSBuildOnNETCoreSupported
678
679 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
680 # This is needed by CLI to function.
681 if [ -z "$HOME" ]; then
682     if [ ! -d "$__ProjectDir/temp_home" ]; then
683         mkdir temp_home
684     fi
685     export HOME=$__ProjectDir/temp_home
686     echo "HOME not defined; setting it to $HOME"
687 fi
688
689 # Specify path to be set for CMAKE_INSTALL_PREFIX.
690 # This is where all built CoreClr libraries will copied to.
691 export __CMakeBinDir="$__BinDir"
692
693 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
694
695     echo "Cannot find build directory for the CoreCLR Product or native tests."
696     echo "Please make sure CoreCLR and native tests are built before building managed tests."
697     echo "Example use: './build.sh $__BuildArch $__BuildType' without -skiptests switch"
698     exit 1
699 fi
700
701 # Configure environment if we are doing a cross compile.
702 if [ $__CrossBuild == 1 ]; then
703     export CROSSCOMPILE=1
704     if ! [[ -n "$ROOTFS_DIR" ]]; then
705         export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
706     fi
707 fi
708
709 # init the target distro name
710 initTargetDistroRid
711
712 # Override tool directory
713
714 __CoreClrVersion=1.1.0
715 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
716
717 echo "Building Tests..."
718
719 if [ -z "$__GenerateLayoutOnly" ]; then
720     build_Tests
721 else
722     generate_layout
723 fi
724
725 if [ $? -ne 0 ]; then
726     echo "Failed to build tests"
727     exit 1
728 fi
729
730 echo "${__MsgPrefix}Test build successful."
731 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
732
733 __testNativeBinDir=$__IntermediatesDir/tests
734
735 if [ $__RunTests -ne 0 ]; then
736
737     echo "Run Tests..."
738
739     echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
740
741     $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
742
743     echo "Tests run successful."
744 else
745     echo "To run all tests use 'tests/runtests.sh' where:"
746     echo "    testRootDir      = $__TestBinDir"
747     echo "    coreClrBinDir    = $__BinDir"
748     echo "    coreFxBinDir     = $CORE_ROOT"
749     echo "    testNativeBinDir = $__testNativeBinDir"
750     echo " -------------------------------------------------- "
751     echo " Example runtest.sh command"
752     echo ""
753     echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
754     echo " -------------------------------------------------- "
755     echo "To run single test use the following command:"
756     echo "    bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"
757 fi
758