7cb4c02fac8d121b6c570fecc2b0c938fee7dcc1
[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 - supported version 3.5 - 6.0"
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|-clang3.5)
547             __ClangMajorVersion=3
548             __ClangMinorVersion=5
549             ;;
550
551         clang3.6|-clang3.6)
552             __ClangMajorVersion=3
553             __ClangMinorVersion=6
554             ;;
555
556         clang3.7|-clang3.7)
557             __ClangMajorVersion=3
558             __ClangMinorVersion=7
559             ;;
560
561         clang3.8|-clang3.8)
562             __ClangMajorVersion=3
563             __ClangMinorVersion=8
564             ;;
565
566         clang3.9|-clang3.9)
567             __ClangMajorVersion=3
568             __ClangMinorVersion=9
569             ;;
570
571         clang4.0|-clang4.0)
572             __ClangMajorVersion=4
573             __ClangMinorVersion=0
574             ;;
575
576         clang5.0|-clang5.0)
577             __ClangMajorVersion=5
578             __ClangMinorVersion=0
579             ;;
580
581         clang6.0|-clang6.0)
582             __ClangMajorVersion=6
583             __ClangMinorVersion=0
584             ;;
585
586         ninja)
587             __UseNinja=1
588             ;;
589
590         runtests)
591             __RunTests=1
592             ;;
593
594         rebuild)
595             __RebuildTests=1
596             ;;
597
598         ziptests)
599             __ZipTests=1
600             ;;
601
602         generatelayoutonly)
603             __GenerateLayoutOnly=1
604             ;;
605
606         buildagainstpackages)
607             __BuildAgainstPackagesArg=1
608             ;;
609
610         bindir)
611             if [ -n "$2" ]; then
612                 __RootBinDir="$2"
613                 if [ ! -d $__RootBinDir ]; then
614                     mkdir $__RootBinDir
615                 fi
616                 __RootBinParent=$(dirname $__RootBinDir)
617                 __RootBinName=${__RootBinDir##*/}
618                 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
619                 shift
620             else
621                 echo "ERROR: 'bindir' requires a non-empty option argument"
622                 exit 1
623             fi
624             ;;
625
626         msbuildonunsupportedplatform)
627             __msbuildonunsupportedplatform=1
628             ;;
629         *)
630             __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
631             ;;
632     esac
633
634     shift
635 done
636
637
638 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
639
640 # Configure environment if we are doing a verbose build
641 if [ $__VerboseBuild == 1 ]; then
642     export VERBOSE=1
643     __RunArgs="$__RunArgs -verbose"
644 fi
645
646 # Set default clang version
647 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
648     if [ $__CrossBuild == 1 ]; then
649         __ClangMajorVersion=3
650         __ClangMinorVersion=6
651     else
652         __ClangMajorVersion=3
653         __ClangMinorVersion=5
654     fi
655 fi
656
657
658 # Set dependent variables
659 __LogsDir="$__RootBinDir/Logs"
660
661 # init the host distro name
662 initHostDistroRid
663
664 # Set the remaining variables based upon the determined build configuration
665 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
666 __PackagesBinDir="$__BinDir/.nuget"
667 __ToolsDir="$__RootBinDir/tools"
668 __TestDir="$__ProjectDir/tests"
669 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
670 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
671 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
672 __isMSBuildOnNETCoreSupported=0
673 __CrossComponentBinDir="$__BinDir"
674 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
675
676 __CrossArch="$__HostArch"
677 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
678     __CrossArch="x86"
679 fi
680 if [ $__CrossBuild == 1 ]; then
681     __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
682 fi
683 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
684 __CrossgenExe="$__CrossComponentBinDir/crossgen"
685
686 isMSBuildOnNETCoreSupported
687
688 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
689 # This is needed by CLI to function.
690 if [ -z "$HOME" ]; then
691     if [ ! -d "$__ProjectDir/temp_home" ]; then
692         mkdir temp_home
693     fi
694     export HOME=$__ProjectDir/temp_home
695     echo "HOME not defined; setting it to $HOME"
696 fi
697
698 # Specify path to be set for CMAKE_INSTALL_PREFIX.
699 # This is where all built CoreClr libraries will copied to.
700 export __CMakeBinDir="$__BinDir"
701
702 if [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ]; then
703
704     echo "Cannot find build directory for the CoreCLR Product or native tests."
705     echo "Please make sure CoreCLR and native tests are built before building managed tests."
706     echo "Example use: './build.sh $__BuildArch $__BuildType' without -skiptests switch"
707     exit 1
708 fi
709
710 # Configure environment if we are doing a cross compile.
711 if [ $__CrossBuild == 1 ]; then
712     export CROSSCOMPILE=1
713     if ! [[ -n "$ROOTFS_DIR" ]]; then
714         export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
715     fi
716 fi
717
718 # init the target distro name
719 initTargetDistroRid
720
721 # Override tool directory
722
723 __CoreClrVersion=1.1.0
724 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
725
726 echo "Building Tests..."
727
728 if [ -z "$__GenerateLayoutOnly" ]; then
729     build_Tests
730 else
731     generate_layout
732 fi
733
734 if [ $? -ne 0 ]; then
735     echo "Failed to build tests"
736     exit 1
737 fi
738
739 echo "${__MsgPrefix}Test build successful."
740 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
741
742 __testNativeBinDir=$__IntermediatesDir/tests
743
744 if [ $__RunTests -ne 0 ]; then
745
746     echo "Run Tests..."
747
748     echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
749
750     $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
751
752     echo "Tests run successful."
753 else
754     echo "To run all tests use 'tests/runtests.sh' where:"
755     echo "    testRootDir      = $__TestBinDir"
756     echo "    coreClrBinDir    = $__BinDir"
757     echo "    coreFxBinDir     = $CORE_ROOT"
758     echo "    testNativeBinDir = $__testNativeBinDir"
759     echo " -------------------------------------------------- "
760     echo " Example runtest.sh command"
761     echo ""
762     echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
763     echo " -------------------------------------------------- "
764     echo "To run single test use the following command:"
765     echo "    bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"
766 fi
767