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