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