One more reverted change in PR
[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     __ManagedTestBuiltMarker=${__TestBinDir}/managed_test_build
244
245     if [ ! -f $__ManagedTestBuiltMarker ]; then
246
247         build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "$__up" "Managed tests build (build tests)"
248
249         if [ $? -ne 0 ]; then
250             echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
251             exit 1
252         else
253             echo "Tests have been built."
254             echo "Create marker \"${__ManagedTestBuiltMarker}\""
255             touch $__ManagedTestBuiltMarker
256         fi
257     else
258         echo "Managed Tests had been built before."
259     fi
260
261     if [ $__BuildTestWrappers -ne -0 ]; then
262         echo "${__MsgPrefix}Creating test wrappers..."
263
264         __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
265
266         if [ ! -f $__XUnitWrapperBuiltMarker ]; then
267
268             build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "-BuildWrappers -MsBuildEventLogging=\" \" " "Test Xunit Wrapper"
269
270             if [ $? -ne 0 ]; then
271                 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
272                 exit 1
273             else
274                 echo "XUnit Wrappers have been built."
275                 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
276                 touch $__XUnitWrapperBuiltMarker
277             fi
278         else
279             echo "XUnit Wrappers had been built before."
280         fi
281     fi
282
283     if [ -n "$__UpdateInvalidPackagesArg" ]; then
284         __up=-updateinvalidpackageversion
285     fi
286
287     echo "${__MsgPrefix}Creating test overlay..."
288
289     generate_layout
290
291     if [ $__ZipTests -ne 0 ]; then
292         echo "${__MsgPrefix}ZIP tests packages..."
293         build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" " " "Prep test binaries for Helix publishing"
294     fi
295 }
296
297 build_Tests_internal()
298 {
299     subDirectoryName=$1
300     projectName=$2
301     extraBuildParameters=$3
302     stepName="$4"
303
304     # Set up directories and file names
305     __BuildLogRootName=$subDirectoryName
306     __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
307     __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
308     __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
309     __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
310     __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
311     __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
312
313     # Generate build command
314     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"
315
316     echo "Building step '$stepName' via $buildCommand"
317
318     # Invoke MSBuild
319     eval $buildCommand
320
321     # Invoke MSBuild
322     # $__ProjectRoot/run.sh build -Project=$projectName -MsBuildLog="$__msbuildLog" -MsBuildWrn="$__msbuildWrn" -MsBuildErr="$__msbuildErr" $extraBuildParameters $__RunArgs $__UnprocessedBuildArgs
323
324     # Make sure everything is OK
325     if [ $? -ne 0 ]; then
326         echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
327         echo "    $__BuildLog"
328         echo "    $__BuildWrn"
329         echo "    $__BuildErr"
330         exit 1
331     fi
332 }
333
334 usage()
335 {
336     echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
337     echo "BuildArch can be: x64, x86, arm, armel, arm64"
338     echo "BuildType can be: debug, checked, release"
339     echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
340     echo "ninja - target ninja instead of GNU make"
341     echo "clangx.y - optional argument to build using clang version x.y."
342     echo "cross - optional argument to signify cross compilation,"
343     echo "      - will use ROOTFS_DIR environment variable if set."
344     echo "crosscomponent - optional argument to build cross-architecture component,"
345     echo "               - will use CAC_ROOTFS_DIR environment variable if set."
346     echo "portableLinux - build for Portable Linux Distribution"
347     echo "portablebuild - Use portable build."
348     echo "verbose - optional argument to enable verbose build output."
349     echo "rebuild - if tests have already been built - rebuild them"
350     echo "generatelayoutonly - only pull down dependencies and build coreroot"
351     echo "buildagainstpackages - pull down and build using packages."
352     echo "runtests - run tests after building them"
353     echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
354     echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
355     echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
356     exit 1
357 }
358
359
360 # Obtain the location of the bash script to figure out where the root of the repo is.
361 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
362
363 # $__ProjectRoot/build.sh $1 $2
364
365 # Use uname to determine what the CPU is.
366 CPUName=$(uname -p)
367
368 # Some Linux platforms report unknown for platform, but the arch for machine.
369 if [ "$CPUName" == "unknown" ]; then
370     CPUName=$(uname -m)
371 fi
372
373 case $CPUName in
374     i686)
375         echo "Unsupported CPU $CPUName detected, build might not succeed!"
376         __BuildArch=x86
377         __HostArch=x86
378         ;;
379
380     x86_64)
381         __BuildArch=x64
382         __HostArch=x64
383         ;;
384
385     armv7l)
386         echo "Unsupported CPU $CPUName detected, build might not succeed!"
387         __BuildArch=arm
388         __HostArch=arm
389         ;;
390
391     aarch64)
392         __BuildArch=arm64
393         __HostArch=arm64
394         ;;
395
396     *)
397         echo "Unknown CPU $CPUName detected, configuring as if for x64"
398         __BuildArch=x64
399         __HostArch=x64
400         ;;
401 esac
402
403 # Use uname to determine what the OS is.
404 OSName=$(uname -s)
405 case $OSName in
406     Linux)
407         __BuildOS=Linux
408         __HostOS=Linux
409         ;;
410
411     Darwin)
412         __BuildOS=OSX
413         __HostOS=OSX
414         ;;
415
416     FreeBSD)
417         __BuildOS=FreeBSD
418         __HostOS=FreeBSD
419         ;;
420
421     OpenBSD)
422         __BuildOS=OpenBSD
423         __HostOS=OpenBSD
424         ;;
425
426     NetBSD)
427         __BuildOS=NetBSD
428         __HostOS=NetBSD
429         ;;
430
431     SunOS)
432         __BuildOS=SunOS
433         __HostOS=SunOS
434         ;;
435
436     *)
437         echo "Unsupported OS $OSName detected, configuring as if for Linux"
438         __BuildOS=Linux
439         __HostOS=Linux
440         ;;
441 esac
442
443 __BuildType=Debug
444 __CodeCoverage=
445 __IncludeTests=INCLUDE_TESTS
446
447 # Set the various build properties here so that CMake and MSBuild can pick them up
448 export __ProjectDir="$__ProjectRoot"
449 __SourceDir="$__ProjectDir/src"
450 __PackagesDir="$__ProjectDir/packages"
451 __RootBinDir="$__ProjectDir/bin"
452 __BuildToolsDir="$__ProjectDir/Tools"
453 __UnprocessedBuildArgs=
454 __RunArgs=
455 __MSBCleanBuildArgs=
456 __UseNinja=0
457 __VerboseBuild=0
458 __SkipRestore=""
459 __CrossBuild=0
460 __ClangMajorVersion=0
461 __ClangMinorVersion=0
462 __NuGetPath="$__PackagesDir/NuGet.exe"
463 __HostDistroRid=""
464 __BuildAgainstPackagesArg=
465 __DistroRid=""
466 __cmakeargs=""
467 __PortableLinux=0
468 __msbuildonunsupportedplatform=0
469 __ZipTests=0
470 __NativeTestIntermediatesDir=
471 __RunTests=0
472 __RebuildTests=0
473 __BuildTestWrappers=0
474 __GenerateLayoutOnly=
475 CORE_ROOT=
476
477 while :; do
478     if [ $# -le 0 ]; then
479         break
480     fi
481
482     lowerI="$(echo $1 | awk '{print tolower($0)}')"
483     case $lowerI in
484         -\?|-h|--help)
485             usage
486             exit 1
487             ;;
488
489         x86)
490             __BuildArch=x86
491             ;;
492
493         x64)
494             __BuildArch=x64
495             ;;
496
497         arm)
498             __BuildArch=arm
499             ;;
500
501         armel)
502             __BuildArch=armel
503             ;;
504
505         arm64)
506             __BuildArch=arm64
507             ;;
508
509         debug)
510             __BuildType=Debug
511             ;;
512
513         checked)
514             __BuildType=Checked
515             ;;
516
517         release)
518             __BuildType=Release
519             ;;
520
521         coverage)
522             __CodeCoverage=Coverage
523             ;;
524
525         cross)
526             __CrossBuild=1
527             ;;
528
529         portableBuild)
530             __PortableBuild=1
531             ;;
532
533         portablelinux)
534             if [ "$__BuildOS" == "Linux" ]; then
535                 __PortableLinux=1
536             else
537                 echo "ERROR: portableLinux not supported for non-Linux platforms."
538                 exit 1
539             fi
540             ;;
541
542         verbose)
543         __VerboseBuild=1
544         ;;
545
546         clang3.5)
547             __ClangMajorVersion=3
548             __ClangMinorVersion=5
549             ;;
550
551         clang3.6)
552             __ClangMajorVersion=3
553             __ClangMinorVersion=6
554             ;;
555
556         clang3.7)
557             __ClangMajorVersion=3
558             __ClangMinorVersion=7
559             ;;
560
561         clang3.8)
562             __ClangMajorVersion=3
563             __ClangMinorVersion=8
564             ;;
565
566         clang3.9)
567             __ClangMajorVersion=3
568             __ClangMinorVersion=9
569             ;;
570
571         ninja)
572             __UseNinja=1
573             ;;
574
575         runtests)
576             __RunTests=1
577             ;;
578
579         rebuild)
580             __RebuildTests=1
581             ;;
582
583         ziptests)
584             __ZipTests=1
585             ;;
586
587         generatelayoutonly)
588             __GenerateLayoutOnly=1
589             ;;
590
591         buildagainstpackages)
592             __BuildAgainstPackagesArg=1
593             ;;
594
595         bindir)
596             if [ -n "$2" ]; then
597                 __RootBinDir="$2"
598                 if [ ! -d $__RootBinDir ]; then
599                     mkdir $__RootBinDir
600                 fi
601                 __RootBinParent=$(dirname $__RootBinDir)
602                 __RootBinName=${__RootBinDir##*/}
603                 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
604                 shift
605             else
606                 echo "ERROR: 'bindir' requires a non-empty option argument"
607                 exit 1
608             fi
609             ;;
610
611         msbuildonunsupportedplatform)
612             __msbuildonunsupportedplatform=1
613             ;;
614         *)
615             __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
616             ;;
617     esac
618
619     shift
620 done
621
622
623 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
624
625 # Configure environment if we are doing a verbose build
626 if [ $__VerboseBuild == 1 ]; then
627     export VERBOSE=1
628     __RunArgs="$__RunArgs -verbose"
629 fi
630
631 # Set default clang version
632 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
633     if [ $__CrossBuild == 1 ]; then
634         __ClangMajorVersion=3
635         __ClangMinorVersion=6
636     else
637         __ClangMajorVersion=3
638         __ClangMinorVersion=5
639     fi
640 fi
641
642
643 # Set dependent variables
644 __LogsDir="$__RootBinDir/Logs"
645
646 # init the host distro name
647 initHostDistroRid
648
649 # Set the remaining variables based upon the determined build configuration
650 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
651 __PackagesBinDir="$__BinDir/.nuget"
652 __ToolsDir="$__RootBinDir/tools"
653 __TestDir="$__ProjectDir/tests"
654 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
655 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
656 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
657 __isMSBuildOnNETCoreSupported=0
658 __CrossComponentBinDir="$__BinDir"
659 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
660
661 __CrossArch="$__HostArch"
662 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
663     __CrossArch="x86"
664 fi
665 if [ $__CrossBuild == 1 ]; then
666     __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
667 fi
668 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
669 __CrossgenExe="$__CrossComponentBinDir/crossgen"
670
671 isMSBuildOnNETCoreSupported
672
673 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
674 # This is needed by CLI to function.
675 if [ -z "$HOME" ]; then
676     if [ ! -d "$__ProjectDir/temp_home" ]; then
677         mkdir temp_home
678     fi
679     export HOME=$__ProjectDir/temp_home
680     echo "HOME not defined; setting it to $HOME"
681 fi
682
683 # Specify path to be set for CMAKE_INSTALL_PREFIX.
684 # This is where all built CoreClr libraries will copied to.
685 export __CMakeBinDir="$__BinDir"
686
687 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
688
689     echo "Cannot find build directory for the CoreCLR Product."
690     echo "Please make sure CoreCLR is built before building tests."
691     echo "Example use: './build.sh $__BuildArch $__BuildType'"
692     exit 1
693 fi
694
695 # Configure environment if we are doing a cross compile.
696 if [ $__CrossBuild == 1 ]; then
697     export CROSSCOMPILE=1
698     if ! [[ -n "$ROOTFS_DIR" ]]; then
699         export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
700     fi
701 fi
702
703 # init the target distro name
704 initTargetDistroRid
705
706 # Override tool directory
707
708 __CoreClrVersion=1.1.0
709 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
710
711 echo "Building Tests..."
712
713 if [ -z "$__GenerateLayoutOnly" ]; then
714     build_Tests
715 else
716     generate_layout
717 fi
718
719 if [ $? -ne 0 ]; then
720     echo "Failed to build tests"
721     exit 1
722 fi
723
724 echo "${__MsgPrefix}Test build successful."
725 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
726
727 __testNativeBinDir=$__IntermediatesDir/tests
728
729 if [ $__RunTests -ne 0 ]; then
730
731     echo "Run Tests..."
732
733     echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
734
735     $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
736
737     echo "Tests run successful."
738 else
739     echo "To run all tests use 'tests/runtests.sh' where:"
740     echo "    testRootDir      = $__TestBinDir"
741     echo "    coreClrBinDir    = $__BinDir"
742     echo "    coreFxBinDir     = $CORE_ROOT"
743     echo "    testNativeBinDir = $__testNativeBinDir"
744     echo " -------------------------------------------------- "
745     echo " Example runtest.sh command"
746     echo ""
747     echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
748     echo " -------------------------------------------------- "
749     echo "To run single test use the following command:"
750     echo "    bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"
751 fi
752