Merge pull request #19344 from adityamandaleeka/aa64_vm_callconv_changes
[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" "Restore product binaries (build tests)" "-BatchRestorePackages"
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" "Creating test overlay" "-testOverlay" 
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 }
184
185 generate_testhost()
186 {
187     export TEST_HOST=$xUnitTestBinBase/testhost
188
189     if [ -d "${TEST_HOST}" ]; then
190         rm -rf $TEST_HOST
191     fi
192
193     echo "${__MsgPrefix}Creating test overlay..."    
194     mkdir -p $TEST_HOST
195
196     build_Tests_internal "Tests_Generate_TestHost" "${__ProjectDir}/tests/runtest.proj" "Creating test host" "-testHost"
197 }
198
199
200 build_Tests()
201 {
202     __TestDir=$__ProjectDir/tests
203     __ProjectFilesDir=$__TestDir
204     __TestBinDir=$__TestWorkingDir
205
206     if [ $__RebuildTests -ne 0 ]; then
207         if [ -d "${__TestBinDir}" ]; then
208             echo "Removing tests build dir: ${__TestBinDir}"
209             rm -rf $__TestBinDir
210         fi
211     fi
212
213     __CMakeBinDir="${__TestBinDir}"
214
215     if [ -z "$__TestIntermediateDir" ]; then
216         __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}"
217     fi
218
219     echo "__BuildOS: ${__BuildOS}"
220     echo "__BuildArch: ${__BuildArch}"
221     echo "__BuildType: ${__BuildType}"
222     echo "__TestIntermediateDir: ${__TestIntermediateDir}"
223
224     if [ ! -f "$__TestBinDir" ]; then
225         echo "Creating TestBinDir: ${__TestBinDir}"
226         mkdir -p $__TestBinDir
227     fi
228     if [ ! -f "$__LogsDir" ]; then
229         echo "Creating LogsDir: ${__LogsDir}"
230         mkdir -p $__LogsDir
231     fi
232
233     __BuildProperties="-p:OSGroup=${__BuildOS} -p:BuildOS=${__BuildOS} -p:BuildArch=${__BuildArch} -p:BuildType=${__BuildType}"
234
235     # =========================================================================================
236     # ===
237     # === Restore product binaries from packages
238     # ===
239     # =========================================================================================
240
241     build_Tests_internal "Restore_Product" "${__ProjectDir}/tests/build.proj" "Restore product binaries (build tests)" "-BatchRestorePackages"
242
243     if [ -n "$__BuildAgainstPackagesArg" ]; then
244         build_Tests_internal "Tests_GenerateRuntimeLayout" "${__ProjectDir}/tests/runtest.proj" "Restore product binaries (run tests)" "-BinPlaceRef" "-BinPlaceProduct" "-CopyCrossgenToProduct"
245     fi
246
247     echo "Starting the Managed Tests Build..."
248
249     build_Tests_internal "Tests_Managed" "$__ProjectDir/tests/build.proj" "Managed tests build (build tests)" "$__up"
250
251     if [ $? -ne 0 ]; then
252         echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
253         exit 1
254     else
255         echo "Checking the Managed Tests Build..."
256
257         if [ -n __priority1 ]; then
258             __Priority=1
259         else
260             __Priority=0
261         fi
262         build_Tests_internal "Check_Test_Build" "${__ProjectDir}/tests/runtest.proj" "Check Test Build" "/t:CheckTestBuild /p:CLRTestPriorityToBuild=$__Priority"
263
264         if [ $? -ne 0 ]; then
265             echo "${__MsgPrefix}Error: Check Test Build failed."
266             exit 1
267         fi
268
269         echo "Managed tests build success!"
270     fi
271
272     if [ $__BuildTestWrappers -ne -0 ]; then
273         echo "${__MsgPrefix}Creating test wrappers..."
274
275         __XUnitWrapperBuiltMarker=${__TestBinDir}/xunit_wrapper_build
276
277         if [ ! -f $__XUnitWrapperBuiltMarker ]; then
278
279             build_Tests_internal "Tests_XunitWrapper" "$__ProjectDir/tests/runtest.proj" "Test Xunit Wrapper" "-BuildWrappers" "-MsBuildEventLogging= " "-TargetsWindows=false"
280
281             if [ $? -ne 0 ]; then
282                 echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
283                 exit 1
284             else
285                 echo "XUnit Wrappers have been built."
286                 echo "Create marker \"${__XUnitWrapperBuiltMarker}\""
287                 touch $__XUnitWrapperBuiltMarker
288             fi
289         else
290             echo "XUnit Wrappers had been built before."
291         fi
292     fi
293
294     if [ -n "$__UpdateInvalidPackagesArg" ]; then
295         __up=-updateinvalidpackageversion
296     fi
297
298     echo "${__MsgPrefix}Creating test overlay..."
299
300     generate_layout
301
302     if [ $__ZipTests -ne 0 ]; then
303         echo "${__MsgPrefix}ZIP tests packages..."
304         build_Tests_internal "Helix_Prep" "$__ProjectDir/tests/helixprep.proj" "Prep test binaries for Helix publishing" " "
305     fi
306 }
307
308 build_Tests_internal()
309 {
310     subDirectoryName=$1
311     shift
312     projectName=$1
313     shift
314     stepName="$1"
315     shift
316     extraBuildParameters=("$@")
317
318     # Set up directories and file names
319     __BuildLogRootName=$subDirectoryName
320     __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log"
321     __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn"
322     __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err"
323
324     # Use binclashlogger by default if no other logger is specified
325     if [[ "${extraBuildParameters[*]}" == *"-MsBuildEventLogging"* ]]; then
326         msbuildEventLogging=""
327     else
328         msbuildEventLogging="-MsBuildEventLogging=\"/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log\""
329     fi
330
331     if [[ "$subDirectoryName" == "Tests_Managed" ]]; then
332         # Execute msbuild managed test build in stages - workaround for excessive data retention in MSBuild ConfigCache
333         # See https://github.com/Microsoft/msbuild/issues/2993
334
335         # __SkipPackageRestore and __SkipTargetingPackBuild used  to control build by tests/src/dirs.proj
336         export __SkipPackageRestore=false
337         export __SkipTargetingPackBuild=false
338         export __BuildLoopCount=2
339         export __TestGroupToBuild=1
340         __AppendToLog=false
341
342         if [ -n __priority1 ]; then
343             export __BuildLoopCount=16
344             export __TestGroupToBuild=2
345         fi
346
347         for (( slice=1 ; slice <= __BuildLoopCount; slice = slice + 1 ))
348         do
349             __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog};Append=${__AppendToLog}\""
350             __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn};Append=${__AppendToLog}\""
351             __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr};Append=${__AppendToLog}\""
352
353             export TestBuildSlice=$slice
354
355             # Generate build command
356             buildArgs=("-Project=$projectName" "-MsBuildLog=${__msbuildLog}" "-MsBuildWrn=${__msbuildWrn}" "-MsBuildErr=${__msbuildErr}")
357             buildArgs+=("$msbuildEventLogging")
358             buildArgs+=("${extraBuildParameters[@]}")
359             buildArgs+=("${__RunArgs[@]}")
360             buildArgs+=("${__UnprocessedBuildArgs[@]}")
361
362             echo "Building step '$stepName' slice=$slice via $buildCommand"
363
364             # Invoke MSBuild
365             "$__ProjectRoot/run.sh" build "${buildArgs[@]}"
366
367             # Make sure everything is OK
368             if [ $? -ne 0 ]; then
369                 echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
370                 echo "    $__BuildLog"
371                 echo "    $__BuildWrn"
372                 echo "    $__BuildErr"
373                 exit 1
374             fi
375             export __SkipPackageRestore=true
376             export __SkipTargetingPackBuild=true
377             __AppendToLog=true
378         done
379     else
380         __msbuildLog="\"/flp:Verbosity=normal;LogFile=${__BuildLog}\""
381         __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn}\""
382         __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr}\""
383
384         # Generate build command
385         buildArgs=("-Project=$projectName" "-MsBuildLog=${__msbuildLog}" "-MsBuildWrn=${__msbuildWrn}" "-MsBuildErr=${__msbuildErr}")
386         buildArgs+=("$msbuildEventLogging")
387         buildArgs+=("${extraBuildParameters[@]}")
388         buildArgs+=("${__RunArgs[@]}")
389         buildArgs+=("${__UnprocessedBuildArgs[@]}")
390
391         echo "Building step '$stepName' via $buildCommand"
392
393         # Invoke MSBuild
394         "$__ProjectRoot/run.sh" build "${buildArgs[@]}"
395
396         # Make sure everything is OK
397         if [ $? -ne 0 ]; then
398             echo "${__MsgPrefix}Failed to build $stepName. See the build logs:"
399             echo "    $__BuildLog"
400             echo "    $__BuildWrn"
401             echo "    $__BuildErr"
402             exit 1
403         fi
404     fi
405 }
406
407 usage()
408 {
409     echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [bindir]"
410     echo "BuildArch can be: x64, x86, arm, armel, arm64"
411     echo "BuildType can be: debug, checked, release"
412     echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
413     echo "ninja - target ninja instead of GNU make"
414     echo "clangx.y - optional argument to build using clang version x.y - supported version 3.5 - 6.0"
415     echo "cross - optional argument to signify cross compilation,"
416     echo "      - will use ROOTFS_DIR environment variable if set."
417     echo "crosscomponent - optional argument to build cross-architecture component,"
418     echo "               - will use CAC_ROOTFS_DIR environment variable if set."
419     echo "portableLinux - build for Portable Linux Distribution"
420     echo "portablebuild - Use portable build."
421     echo "verbose - optional argument to enable verbose build output."
422     echo "rebuild - if tests have already been built - rebuild them"
423     echo "generatelayoutonly - only pull down dependencies and build coreroot"
424     echo "generatetesthostonly - only pull down dependencies and build coreroot and the CoreFX testhost"
425     echo "buildagainstpackages - pull down and build using packages."
426     echo "runtests - run tests after building them"
427     echo "ziptests - zips CoreCLR tests & Core_Root for a Helix run"
428     echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
429     echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
430     echo "priority1 - include priority=1 tests in the build"
431     exit 1
432 }
433
434
435 # Obtain the location of the bash script to figure out where the root of the repo is.
436 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
437
438 # $__ProjectRoot/build.sh $1 $2
439
440 # Use uname to determine what the CPU is.
441 CPUName=$(uname -p)
442
443 # Some Linux platforms report unknown for platform, but the arch for machine.
444 if [ "$CPUName" == "unknown" ]; then
445     CPUName=$(uname -m)
446 fi
447
448 case $CPUName in
449     i686)
450         echo "Unsupported CPU $CPUName detected, build might not succeed!"
451         __BuildArch=x86
452         __HostArch=x86
453         ;;
454
455     x86_64)
456         __BuildArch=x64
457         __HostArch=x64
458         ;;
459
460     armv7l)
461         echo "Unsupported CPU $CPUName detected, build might not succeed!"
462         __BuildArch=arm
463         __HostArch=arm
464         ;;
465
466     aarch64)
467         __BuildArch=arm64
468         __HostArch=arm64
469         ;;
470
471     *)
472         echo "Unknown CPU $CPUName detected, configuring as if for x64"
473         __BuildArch=x64
474         __HostArch=x64
475         ;;
476 esac
477
478 # Use uname to determine what the OS is.
479 OSName=$(uname -s)
480 case $OSName in
481     Linux)
482         __BuildOS=Linux
483         __HostOS=Linux
484         ;;
485
486     Darwin)
487         __BuildOS=OSX
488         __HostOS=OSX
489         ;;
490
491     FreeBSD)
492         __BuildOS=FreeBSD
493         __HostOS=FreeBSD
494         ;;
495
496     OpenBSD)
497         __BuildOS=OpenBSD
498         __HostOS=OpenBSD
499         ;;
500
501     NetBSD)
502         __BuildOS=NetBSD
503         __HostOS=NetBSD
504         ;;
505
506     SunOS)
507         __BuildOS=SunOS
508         __HostOS=SunOS
509         ;;
510
511     *)
512         echo "Unsupported OS $OSName detected, configuring as if for Linux"
513         __BuildOS=Linux
514         __HostOS=Linux
515         ;;
516 esac
517
518 __BuildType=Debug
519 __CodeCoverage=
520 __IncludeTests=INCLUDE_TESTS
521
522 # Set the various build properties here so that CMake and MSBuild can pick them up
523 export __ProjectDir="$__ProjectRoot"
524 __SourceDir="$__ProjectDir/src"
525 __PackagesDir="$__ProjectDir/packages"
526 __RootBinDir="$__ProjectDir/bin"
527 __BuildToolsDir="$__ProjectDir/Tools"
528 __UnprocessedBuildArgs=
529 __RunArgs=
530 __MSBCleanBuildArgs=
531 __UseNinja=0
532 __VerboseBuild=0
533 __SkipRestore=""
534 __CrossBuild=0
535 __ClangMajorVersion=0
536 __ClangMinorVersion=0
537 __NuGetPath="$__PackagesDir/NuGet.exe"
538 __HostDistroRid=""
539 __BuildAgainstPackagesArg=
540 __DistroRid=""
541 __cmakeargs=""
542 __PortableLinux=0
543 __msbuildonunsupportedplatform=0
544 __ZipTests=0
545 __NativeTestIntermediatesDir=
546 __RunTests=0
547 __RebuildTests=0
548 __BuildTestWrappers=1
549 __GenerateLayoutOnly=
550 __GenerateTestHostOnly=
551 __priority1=
552 CORE_ROOT=
553
554 while :; do
555     if [ $# -le 0 ]; then
556         break
557     fi
558
559     lowerI="$(echo $1 | awk '{print tolower($0)}')"
560     case $lowerI in
561         -\?|-h|--help)
562             usage
563             exit 1
564             ;;
565
566         x86)
567             __BuildArch=x86
568             ;;
569
570         x64)
571             __BuildArch=x64
572             ;;
573
574         arm)
575             __BuildArch=arm
576             ;;
577
578         armel)
579             __BuildArch=armel
580             ;;
581
582         arm64)
583             __BuildArch=arm64
584             ;;
585
586         debug)
587             __BuildType=Debug
588             ;;
589
590         checked)
591             __BuildType=Checked
592             ;;
593
594         release)
595             __BuildType=Release
596             ;;
597
598         coverage)
599             __CodeCoverage=Coverage
600             ;;
601
602         cross)
603             __CrossBuild=1
604             ;;
605
606         portableBuild)
607             __PortableBuild=1
608             ;;
609
610         portablelinux)
611             if [ "$__BuildOS" == "Linux" ]; then
612                 __PortableLinux=1
613             else
614                 echo "ERROR: portableLinux not supported for non-Linux platforms."
615                 exit 1
616             fi
617             ;;
618
619         verbose)
620         __VerboseBuild=1
621         ;;
622
623         clang3.5|-clang3.5)
624             __ClangMajorVersion=3
625             __ClangMinorVersion=5
626             ;;
627
628         clang3.6|-clang3.6)
629             __ClangMajorVersion=3
630             __ClangMinorVersion=6
631             ;;
632
633         clang3.7|-clang3.7)
634             __ClangMajorVersion=3
635             __ClangMinorVersion=7
636             ;;
637
638         clang3.8|-clang3.8)
639             __ClangMajorVersion=3
640             __ClangMinorVersion=8
641             ;;
642
643         clang3.9|-clang3.9)
644             __ClangMajorVersion=3
645             __ClangMinorVersion=9
646             ;;
647
648         clang4.0|-clang4.0)
649             __ClangMajorVersion=4
650             __ClangMinorVersion=0
651             ;;
652
653         clang5.0|-clang5.0)
654             __ClangMajorVersion=5
655             __ClangMinorVersion=0
656             ;;
657
658         clang6.0|-clang6.0)
659             __ClangMajorVersion=6
660             __ClangMinorVersion=0
661             ;;
662
663         ninja)
664             __UseNinja=1
665             ;;
666
667         runtests)
668             __RunTests=1
669             ;;
670
671         rebuild)
672             __RebuildTests=1
673             ;;
674
675         ziptests)
676             __ZipTests=1
677             ;;
678
679         generatelayoutonly)
680             __GenerateLayoutOnly=1
681             ;;
682         generatetesthostonly)
683             __GenerateTestHostOnly=1
684             ;;
685         buildagainstpackages)
686             __BuildAgainstPackagesArg=1
687             ;;
688
689         bindir)
690             if [ -n "$2" ]; then
691                 __RootBinDir="$2"
692                 if [ ! -d $__RootBinDir ]; then
693                     mkdir $__RootBinDir
694                 fi
695                 __RootBinParent=$(dirname $__RootBinDir)
696                 __RootBinName=${__RootBinDir##*/}
697                 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
698                 shift
699             else
700                 echo "ERROR: 'bindir' requires a non-empty option argument"
701                 exit 1
702             fi
703             ;;
704
705         msbuildonunsupportedplatform)
706             __msbuildonunsupportedplatform=1
707             ;;
708         priority1)
709             __priority1=1
710             __UnprocessedBuildArgs+=("-priority=1")
711             ;;
712         *)
713             __UnprocessedBuildArgs+=("$1")
714             ;;
715     esac
716
717     shift
718 done
719
720
721 __RunArgs=("-BuildArch=$__BuildArch" "-BuildType=$__BuildType" "-BuildOS=$__BuildOS")
722
723 # Configure environment if we are doing a verbose build
724 if [ $__VerboseBuild == 1 ]; then
725     export VERBOSE=1
726     __RunArgs+=("-verbose")
727 fi
728
729 # Set default clang version
730 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
731     if [ $__CrossBuild == 1 ]; then
732         __ClangMajorVersion=3
733         __ClangMinorVersion=6
734     else
735         __ClangMajorVersion=3
736         __ClangMinorVersion=5
737     fi
738 fi
739
740
741 # Set dependent variables
742 __LogsDir="$__RootBinDir/Logs"
743
744 # init the host distro name
745 initHostDistroRid
746
747 # Set the remaining variables based upon the determined build configuration
748 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
749 __PackagesBinDir="$__BinDir/.nuget"
750 __ToolsDir="$__RootBinDir/tools"
751 __TestDir="$__ProjectDir/tests"
752 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
753 __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
754 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
755 __isMSBuildOnNETCoreSupported=0
756 __CrossComponentBinDir="$__BinDir"
757 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
758
759 __CrossArch="$__HostArch"
760 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
761     __CrossArch="x86"
762 fi
763 if [ $__CrossBuild == 1 ]; then
764     __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
765 fi
766 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
767 __CrossgenExe="$__CrossComponentBinDir/crossgen"
768
769 isMSBuildOnNETCoreSupported
770
771 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to it.
772 # This is needed by CLI to function.
773 if [ -z "$HOME" ]; then
774     if [ ! -d "$__ProjectDir/temp_home" ]; then
775         mkdir temp_home
776     fi
777     export HOME=$__ProjectDir/temp_home
778     echo "HOME not defined; setting it to $HOME"
779 fi
780
781 # Specify path to be set for CMAKE_INSTALL_PREFIX.
782 # This is where all built CoreClr libraries will copied to.
783 export __CMakeBinDir="$__BinDir"
784 if [ [ ! -d "$__BinDir" ] || [ ! -d "$__BinDir/bin" ] ]; then
785     if [ [ -z "$__GenerateLayoutOnly" ] && [ -z "$__GenerateTestHostOnly" ] ]; then
786
787         echo "Cannot find build directory for the CoreCLR native tests."
788         echo "Please make sure native tests are built before building managed tests."
789         echo "Example use: './build.sh $__BuildArch $__BuildType' without -skiptests switch"
790     else
791         echo "Cannot find build directory for the CoreCLR Product."
792         echo "Please make sure CoreCLR and native tests are built before building managed tests."
793         echo "Example use: './build.sh $__BuildArch $__BuildType' "
794         fi
795     exit 1
796 fi
797
798
799
800 # Configure environment if we are doing a cross compile.
801 if [ $__CrossBuild == 1 ]; then
802     export CROSSCOMPILE=1
803     if ! [[ -n "$ROOTFS_DIR" ]]; then
804         export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
805     fi
806 fi
807
808 # init the target distro name
809 initTargetDistroRid
810
811 # Override tool directory
812
813 __CoreClrVersion=1.1.0
814 __sharedFxDir=$__BuildToolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__CoreClrVersion/
815
816
817 if [[ (-z "$__GenerateLayoutOnly") && (-z "$__GenerateTestHostOnly") ]]; then
818     echo "Building Tests..."
819     build_Tests
820 else
821     echo "Generating test layout..."
822     generate_layout
823     if [ ! -z "$__GenerateTestHostOnly" ]; then
824         echo "Generating test host..."        
825         generate_testhost
826     fi
827 fi
828
829 if [ $? -ne 0 ]; then
830     echo "Failed to build tests"
831     exit 1
832 fi
833
834 echo "${__MsgPrefix}Test build successful."
835 echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}"
836
837 __testNativeBinDir=$__IntermediatesDir/tests
838
839 if [ $__RunTests -ne 0 ]; then
840
841     echo "Run Tests..."
842
843     echo "${__TestDir}/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$__sharedFxDir --testNativeBinDir=$__testNativeBinDir"
844
845     $__TestDir/runtest.sh --testRootDir=$__TestBinDir --coreClrBinDir=$__BinDir --coreFxBinDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir
846
847     echo "Tests run successful."
848 else
849     echo "To run all tests use 'tests/runtests.sh' where:"
850     echo "    testRootDir      = $__TestBinDir"
851     echo "    coreClrBinDir    = $__BinDir"
852     echo "    coreFxBinDir     = $CORE_ROOT"
853     echo "    testNativeBinDir = $__testNativeBinDir"
854     echo " -------------------------------------------------- "
855     echo " Example runtest.sh command"
856     echo ""
857     echo " ./tests/runtest.sh --coreOverlayDir=$CORE_ROOT --testNativeBinDir=$__testNativeBinDir --testRootDir=$__TestBinDir --copyNativeTestBin"
858     echo " -------------------------------------------------- "
859     echo "To run single test use the following command:"
860     echo "    bash ${__TestBinDir}/__TEST_PATH__/__TEST_NAME__.sh -coreroot=${CORE_ROOT}"
861 fi
862