From a34330249c325f3f309a7d9224a0a6904096b1f2 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Fri, 24 Apr 2020 14:38:51 -0700 Subject: [PATCH 1/6] Arch, OS, and Config no longer let random values through when building the repo. Also, removed the casing restrictions on the bash version. --- eng/build.ps1 | 6 ++-- eng/build.sh | 56 +++++++++++++++++++++++++++++++---- eng/native/init-distro-rid.sh | 20 ++++++------- 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index 1298a9ba6a2742..c51aa3bd1114b6 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -2,15 +2,15 @@ Param( [switch][Alias('h')]$help, [switch][Alias('t')]$test, - [string[]][Alias('c')]$configuration = @("Debug"), + [ValidateSet("Debug","Release","Checked")][string[]][Alias('c')]$configuration = @("Debug"), [string][Alias('f')]$framework, [string]$vs, - [string]$os, + [ValidateSet("Windows_NT","Unix")][string]$os, [switch]$allconfigurations, [switch]$coverage, [string]$testscope, [switch]$testnobuild, - [string[]][Alias('a')]$arch = @([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant()), + [ValidateSet("x86","x64","arm","arm64")][string[]][Alias('a')]$arch = @([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant()), [Parameter(Position=0)][string][Alias('s')]$subset, [ValidateSet("Debug","Release","Checked")][string][Alias('rc')]$runtimeConfiguration, [ValidateSet("Debug","Release")][string][Alias('lc')]$librariesConfiguration, diff --git a/eng/build.sh b/eng/build.sh index 911757dcefeb53..bfb445cf274b1a 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -107,71 +107,117 @@ while [[ $# > 0 ]]; do usage exit 0 ;; + -subset|-s) arguments="$arguments /p:Subset=$2" shift 2 ;; + -arch) - arch=$2 + declare -l passedArch=$2 + case "$passedArch" in + x64|x86|arm|armel|arm64|wasm) + arch=$passedArch + ;; + *) + echo "Unsupported target architecture '$2'." + echo "The allowed values are x86, x64, arm, armel, arm64, and wasm." + exit 1 + ;; + esac shift 2 ;; + -configuration|-c) - val="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}" - arguments="$arguments -configuration $val" + declare -l passedConfig=$2 + case "$passedConfig" in + debug|release|checked) + val="$(tr '[:lower:]' '[:upper:]' <<< ${passedConfig:0:1})${passedConfig:1}" + arguments="$arguments -configuration $val" + ;; + *) + echo "Unsupported target configuration '$2'." + echo "The allowed values are Debug, Release, and Checked." + exit 1 + ;; + esac shift 2 ;; + -framework|-f) val="$(echo "$2" | awk '{print tolower($0)}')" arguments="$arguments /p:BuildTargetFramework=$val" shift 2 ;; + -os) - os=$2 - arguments="$arguments /p:TargetOS=$2" + declare -l passedOS=$2 + case "$passedOS" in + windows_nt|linux|freebsd|osx|tvos|ios|android|browser) + os=$passedOS + arguments="$arguments /p:TargetOS=$2" + ;; + *) + echo "Unsupported target OS '$2'." + echo "The allowed values are Windows_NT, Linux, FreeBSD, OSX, tvOS, iOS, Android, and Browser." + exit 1 + ;; + esac shift 2 ;; + -allconfigurations) arguments="$arguments /p:BuildAllConfigurations=true" shift 1 ;; + -testscope) arguments="$arguments /p:TestScope=$2" shift 2 ;; + -testnobuild) arguments="$arguments /p:TestNoBuild=$2" shift 2 ;; + -coverage) arguments="$arguments /p:Coverage=true" shift 1 ;; + -runtimeconfiguration|-rc) val="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}" arguments="$arguments /p:RuntimeConfiguration=$val" shift 2 ;; + -librariesconfiguration|-lc) arguments="$arguments /p:LibrariesConfiguration=$2" shift 2 ;; + -cross) crossBuild=1 arguments="$arguments /p:CrossBuild=True" shift 1 ;; + -clang*) arguments="$arguments /p:Compiler=$opt" shift 1 ;; + -cmakeargs) cmakeargs="${cmakeargs} ${opt} $2" shift 2 ;; + -gcc*) arguments="$arguments /p:Compiler=$opt" shift 1 ;; + *) extraargs="$extraargs $1" shift 1 diff --git a/eng/native/init-distro-rid.sh b/eng/native/init-distro-rid.sh index 22efd8e8b5423f..f77cb1505c326a 100644 --- a/eng/native/init-distro-rid.sh +++ b/eng/native/init-distro-rid.sh @@ -34,7 +34,7 @@ initNonPortableDistroRid() local rootfsDir="$4" local nonPortableBuildID="" - if [ "$targetOs" = "Linux" ]; then + if [ "$targetOs" = "linux" ]; then if [ -e "${rootfsDir}/etc/os-release" ]; then source "${rootfsDir}/etc/os-release" @@ -61,7 +61,7 @@ initNonPortableDistroRid() fi fi - if [ "$targetOs" = "FreeBSD" ]; then + if [ "$targetOs" = "freebsd" ]; then if (( isPortable == 0 )); then # $rootfsDir can be empty. freebsd-version is shell script and it should always work. __freebsd_major_version=$($rootfsDir/bin/freebsd-version | { read v; echo "${v%%.*}"; }) @@ -155,21 +155,21 @@ initDistroRidGlobal() fi if [ -z "${distroRid}" ]; then - if [ "$targetOs" = "Linux" ]; then + if [ "$targetOs" = "linux" ]; then distroRid="linux-$buildArch" - elif [ "$targetOs" = "OSX" ]; then + elif [ "$targetOs" = "osx" ]; then distroRid="osx-$buildArch" - elif [ "$targetOs" = "tvOS" ]; then + elif [ "$targetOs" = "tvos" ]; then distroRid="tvos-$buildArch" - elif [ "$targetOs" = "iOS" ]; then + elif [ "$targetOs" = "ios" ]; then distroRid="ios-$buildArch" - elif [ "$targetOs" = "Android" ]; then + elif [ "$targetOs" = "android" ]; then distroRid="android-$buildArch" - elif [ "$targetOs" = "Browser" ]; then + elif [ "$targetOs" = "browser" ]; then distroRid="browser-$buildArch" - elif [ "$targetOs" = "FreeBSD" ]; then + elif [ "$targetOs" = "freebsd" ]; then distroRid="freebsd-$buildArch" - elif [ "$targetOs" = "SunOS" ]; then + elif [ "$targetOs" = "sunos" ]; then distroRid="sunos-$buildArch" fi fi From 50d21695f05e6b2d1c36ce8ab3d64a0edc0561c0 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Wed, 29 Apr 2020 13:43:24 -0700 Subject: [PATCH 2/6] Fixed the bash build script! Also, casing restrictions are gone! --- eng/build.sh | 69 +++++++++++++++++++++-------------- eng/native/init-distro-rid.sh | 20 +++++----- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/eng/build.sh b/eng/build.sh index bfb445cf274b1a..8fb10dbc5902a9 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -18,7 +18,7 @@ usage() { echo "Common settings:" echo " --subset Build a subset, print available subsets with -subset help (short: -s)" - echo " --os Build operating system: Windows_NT, Linux, FreeBSD, OSX, tvOS, iOS, Android or Browser" + echo " --os Build operating system: Windows_NT, Linux, FreeBSD, OSX, tvOS, iOS, Android, Browser, or SunOS" echo " --arch Build platform: x86, x64, arm, armel, arm64 or wasm" echo " --configuration Build configuration: Debug, Release or [CoreCLR]Checked (short: -c)" echo " --runtimeConfiguration Runtime build configuration: Debug, Release or [CoreCLR]Checked (short: -rc)" @@ -116,14 +116,14 @@ while [[ $# > 0 ]]; do -arch) declare -l passedArch=$2 case "$passedArch" in - x64|x86|arm|armel|arm64|wasm) - arch=$passedArch - ;; - *) - echo "Unsupported target architecture '$2'." - echo "The allowed values are x86, x64, arm, armel, arm64, and wasm." - exit 1 - ;; + x64|x86|arm|armel|arm64|wasm) + arch=$passedArch + ;; + *) + echo "Unsupported target architecture '$2'." + echo "The allowed values are x86, x64, arm, armel, arm64, and wasm." + exit 1 + ;; esac shift 2 ;; @@ -131,16 +131,16 @@ while [[ $# > 0 ]]; do -configuration|-c) declare -l passedConfig=$2 case "$passedConfig" in - debug|release|checked) - val="$(tr '[:lower:]' '[:upper:]' <<< ${passedConfig:0:1})${passedConfig:1}" - arguments="$arguments -configuration $val" - ;; - *) - echo "Unsupported target configuration '$2'." - echo "The allowed values are Debug, Release, and Checked." - exit 1 - ;; + debug|release|checked) + val="$(tr '[:lower:]' '[:upper:]' <<< ${passedConfig:0:1})${passedConfig:1}" + ;; + *) + echo "Unsupported target configuration '$2'." + echo "The allowed values are Debug, Release, and Checked." + exit 1 + ;; esac + arguments="$arguments -configuration $val" shift 2 ;; @@ -153,16 +153,31 @@ while [[ $# > 0 ]]; do -os) declare -l passedOS=$2 case "$passedOS" in - windows_nt|linux|freebsd|osx|tvos|ios|android|browser) - os=$passedOS - arguments="$arguments /p:TargetOS=$2" - ;; - *) - echo "Unsupported target OS '$2'." - echo "The allowed values are Windows_NT, Linux, FreeBSD, OSX, tvOS, iOS, Android, and Browser." - exit 1 - ;; + windows_nt) + os="Windows_NT" ;; + linux) + os="Linux" ;; + freebsd) + os="FreeBSD" ;; + osx) + os="OSX" ;; + tvos) + os="tvOS" ;; + ios) + os="iOS" ;; + android) + os="Android" ;; + browser) + os="Browser" ;; + sunos) + os="SunOS" ;; + *) + echo "Unsupported target OS '$2'." + echo "The allowed values are Windows_NT, Linux, FreeBSD, OSX, tvOS, iOS, Android, Browser, and SunOS." + exit 1 + ;; esac + arguments="$arguments /p:TargetOS=$os" shift 2 ;; diff --git a/eng/native/init-distro-rid.sh b/eng/native/init-distro-rid.sh index f77cb1505c326a..22efd8e8b5423f 100644 --- a/eng/native/init-distro-rid.sh +++ b/eng/native/init-distro-rid.sh @@ -34,7 +34,7 @@ initNonPortableDistroRid() local rootfsDir="$4" local nonPortableBuildID="" - if [ "$targetOs" = "linux" ]; then + if [ "$targetOs" = "Linux" ]; then if [ -e "${rootfsDir}/etc/os-release" ]; then source "${rootfsDir}/etc/os-release" @@ -61,7 +61,7 @@ initNonPortableDistroRid() fi fi - if [ "$targetOs" = "freebsd" ]; then + if [ "$targetOs" = "FreeBSD" ]; then if (( isPortable == 0 )); then # $rootfsDir can be empty. freebsd-version is shell script and it should always work. __freebsd_major_version=$($rootfsDir/bin/freebsd-version | { read v; echo "${v%%.*}"; }) @@ -155,21 +155,21 @@ initDistroRidGlobal() fi if [ -z "${distroRid}" ]; then - if [ "$targetOs" = "linux" ]; then + if [ "$targetOs" = "Linux" ]; then distroRid="linux-$buildArch" - elif [ "$targetOs" = "osx" ]; then + elif [ "$targetOs" = "OSX" ]; then distroRid="osx-$buildArch" - elif [ "$targetOs" = "tvos" ]; then + elif [ "$targetOs" = "tvOS" ]; then distroRid="tvos-$buildArch" - elif [ "$targetOs" = "ios" ]; then + elif [ "$targetOs" = "iOS" ]; then distroRid="ios-$buildArch" - elif [ "$targetOs" = "android" ]; then + elif [ "$targetOs" = "Android" ]; then distroRid="android-$buildArch" - elif [ "$targetOs" = "browser" ]; then + elif [ "$targetOs" = "Browser" ]; then distroRid="browser-$buildArch" - elif [ "$targetOs" = "freebsd" ]; then + elif [ "$targetOs" = "FreeBSD" ]; then distroRid="freebsd-$buildArch" - elif [ "$targetOs" = "sunos" ]; then + elif [ "$targetOs" = "SunOS" ]; then distroRid="sunos-$buildArch" fi fi From 6e0564eceb82182c46b96ff281ccd0f189e84144 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Wed, 29 Apr 2020 16:57:46 -0700 Subject: [PATCH 3/6] Added safeguards for bogus values on -rc and -lc on the sh build script. --- eng/build.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/eng/build.sh b/eng/build.sh index 8fb10dbc5902a9..bb540ad374a3d4 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -202,13 +202,34 @@ while [[ $# > 0 ]]; do ;; -runtimeconfiguration|-rc) - val="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}" + declare -l passedRuntimeConf=$2 + case "$passedRuntimeConf" in + debug|release|checked) + val="$(tr '[:lower:]' '[:upper:]' <<< ${passedRuntimeConf:0:1})${passedRuntimeConf:1}" + ;; + *) + echo "Unsupported runtime configuration '$2'." + echo "The allowed values are Debug, Release, and Checked." + exit 1 + ;; + esac arguments="$arguments /p:RuntimeConfiguration=$val" shift 2 ;; -librariesconfiguration|-lc) - arguments="$arguments /p:LibrariesConfiguration=$2" + declare -l passedLibConf=$2 + case "$passedLibConf" in + debug|release) + val="$(tr '[:lower:]' '[:upper:]' <<< ${passedLibConf:0:1})${passedLibConf:1}" + ;; + *) + echo "Unsupported libraries configuration '$2'." + echo "The allowed values are Debug and Release." + exit 1 + ;; + esac + arguments="$arguments /p:LibrariesConfiguration=$val" shift 2 ;; From e3a83394711c649951823abe250e187b3ef7bcb7 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Tue, 5 May 2020 18:18:16 -0700 Subject: [PATCH 4/6] Fixed the merge conflict on build.sh --- eng/build.sh | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/eng/build.sh b/eng/build.sh index bb540ad374a3d4..9ff2c30e4a6f3f 100644 --- a/eng/build.sh +++ b/eng/build.sh @@ -109,11 +109,20 @@ while [[ $# > 0 ]]; do ;; -subset|-s) - arguments="$arguments /p:Subset=$2" - shift 2 + if [ -z ${2+x} ]; then + arguments="$arguments /p:Subset=help" + shift 1 + else + arguments="$arguments /p:Subset=$2" + shift 2 + fi ;; -arch) + if [ -z ${2+x} ]; then + echo "No architecture supplied. See help (--help) for supported architectures." 1>&2 + exit 1 + fi declare -l passedArch=$2 case "$passedArch" in x64|x86|arm|armel|arm64|wasm) @@ -129,6 +138,10 @@ while [[ $# > 0 ]]; do ;; -configuration|-c) + if [ -z ${2+x} ]; then + echo "No configuration supplied. See help (--help) for supported configurations." 1>&2 + exit 1 + fi declare -l passedConfig=$2 case "$passedConfig" in debug|release|checked) @@ -145,12 +158,20 @@ while [[ $# > 0 ]]; do ;; -framework|-f) + if [ -z ${2+x} ]; then + echo "No framework supplied. See help (--help) for supported frameworks." 1>&2 + exit 1 + fi val="$(echo "$2" | awk '{print tolower($0)}')" arguments="$arguments /p:BuildTargetFramework=$val" shift 2 ;; -os) + if [ -z ${2+x} ]; then + echo "No target operating system supplied. See help (--help) for supported target operating systems." 1>&2 + exit 1 + fi declare -l passedOS=$2 case "$passedOS" in windows_nt) @@ -187,13 +208,17 @@ while [[ $# > 0 ]]; do ;; -testscope) + if [ -z ${2+x} ]; then + echo "No test scope supplied. See help (--help) for supported test scope values." 1>&2 + exit 1 + fi arguments="$arguments /p:TestScope=$2" shift 2 ;; -testnobuild) - arguments="$arguments /p:TestNoBuild=$2" - shift 2 + arguments="$arguments /p:TestNoBuild=true" + shift 1 ;; -coverage) @@ -202,6 +227,10 @@ while [[ $# > 0 ]]; do ;; -runtimeconfiguration|-rc) + if [ -z ${2+x} ]; then + echo "No runtime configuration supplied. See help (--help) for supported runtime configurations." 1>&2 + exit 1 + fi declare -l passedRuntimeConf=$2 case "$passedRuntimeConf" in debug|release|checked) @@ -218,6 +247,10 @@ while [[ $# > 0 ]]; do ;; -librariesconfiguration|-lc) + if [ -z ${2+x} ]; then + echo "No libraries configuration supplied. See help (--help) for supported libraries configurations." 1>&2 + exit 1 + fi declare -l passedLibConf=$2 case "$passedLibConf" in debug|release) @@ -245,6 +278,10 @@ while [[ $# > 0 ]]; do ;; -cmakeargs) + if [ -z ${2+x} ]; then + echo "No cmake args supplied." 1>&2 + exit 1 + fi cmakeargs="${cmakeargs} ${opt} $2" shift 2 ;; From 0ffb1d8af8f5bbcb6ccbe099f06db9be9726ed20 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Wed, 6 May 2020 13:34:06 -0700 Subject: [PATCH 5/6] Used awk instead of declare for increased compatibility on build.sh --- eng/build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/eng/build.sh b/eng/build.sh index 9ff2c30e4a6f3f..63365ea5102ddb 100644 --- a/eng/build.sh +++ b/eng/build.sh @@ -123,7 +123,7 @@ while [[ $# > 0 ]]; do echo "No architecture supplied. See help (--help) for supported architectures." 1>&2 exit 1 fi - declare -l passedArch=$2 + passedArch="$(echo "$2" | awk '{print tolower($0)}')" case "$passedArch" in x64|x86|arm|armel|arm64|wasm) arch=$passedArch @@ -142,7 +142,7 @@ while [[ $# > 0 ]]; do echo "No configuration supplied. See help (--help) for supported configurations." 1>&2 exit 1 fi - declare -l passedConfig=$2 + passedConfig="$(echo "$2" | awk '{print tolower($0)}')" case "$passedConfig" in debug|release|checked) val="$(tr '[:lower:]' '[:upper:]' <<< ${passedConfig:0:1})${passedConfig:1}" @@ -172,7 +172,7 @@ while [[ $# > 0 ]]; do echo "No target operating system supplied. See help (--help) for supported target operating systems." 1>&2 exit 1 fi - declare -l passedOS=$2 + passedOS="$(echo "$2" | awk '{print tolower($0)}')" case "$passedOS" in windows_nt) os="Windows_NT" ;; @@ -231,7 +231,7 @@ while [[ $# > 0 ]]; do echo "No runtime configuration supplied. See help (--help) for supported runtime configurations." 1>&2 exit 1 fi - declare -l passedRuntimeConf=$2 + passedRuntimeConf="$(echo "$2" | awk '{print tolower($0)}')" case "$passedRuntimeConf" in debug|release|checked) val="$(tr '[:lower:]' '[:upper:]' <<< ${passedRuntimeConf:0:1})${passedRuntimeConf:1}" @@ -251,7 +251,7 @@ while [[ $# > 0 ]]; do echo "No libraries configuration supplied. See help (--help) for supported libraries configurations." 1>&2 exit 1 fi - declare -l passedLibConf=$2 + passedLibConf="$(echo "$2" | awk '{print tolower($0)}')" case "$passedLibConf" in debug|release) val="$(tr '[:lower:]' '[:upper:]' <<< ${passedLibConf:0:1})${passedLibConf:1}" From f694241e1eef84806b1a5c5db29c29650ae82bd8 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Thu, 7 May 2020 13:14:01 -0700 Subject: [PATCH 6/6] Restored execute permissions to build.sh --- eng/build.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 eng/build.sh diff --git a/eng/build.sh b/eng/build.sh old mode 100644 new mode 100755