From 18bf9b799b2156ae541c83566c6c7639fb767d78 Mon Sep 17 00:00:00 2001 From: Adeel Date: Fri, 17 Jan 2020 21:12:32 +0000 Subject: [PATCH 1/4] Unify build_native via eng/native/build-commons In order to add new platform, architecture, compiler or its newer version, there are currently multiple places to update, which can be deduplicated. This patch unifies: * directories creation * prerequisites checking * `version.c` generation * native build invocation * common argument parsing * building help menu for various build scripts under coreclr, installer and libraries. The common entry-point script is now `eng/native/build-commons.sh` and rest of the scripts under `eng/native` are implementation detail. Also extracted CMake platform detection in `eng/native/configureplatform.cmake`, to share with coreclr and `installer/corehost`. --- eng/native/build-commons.sh | 479 ++++++++++++++++++ eng/native/configureplatform.cmake | 182 +++++++ {src/coreclr => eng/native}/functions.cmake | 0 eng/native/gen-buildsys.sh | 62 +-- .../coreclr => eng/native}/init-distro-rid.sh | 0 eng/pipelines/installer/jobs/base-job.yml | 2 + eng/pipelines/libraries/base-job.yml | 7 +- eng/pipelines/libraries/build-job.yml | 2 + src/coreclr/CMakeLists.txt | 2 +- src/coreclr/_build-commons.sh | 331 +----------- src/coreclr/build-packages.sh | 4 +- src/coreclr/build-test.sh | 145 +----- src/coreclr/build.cmd | 5 - src/coreclr/build.sh | 235 ++------- src/coreclr/configurecompiler.cmake | 186 +------ .../tests/setup-stress-dependencies.sh | 16 +- src/installer/corehost/CMakeLists.txt | 3 + .../corehost/Windows/gen-buildsys-win.bat | 20 +- src/installer/corehost/build.proj | 9 +- src/installer/corehost/build.sh | 327 +++--------- .../corehost/cli/apphost/CMakeLists.txt | 12 +- .../corehost/cli/comhost/CMakeLists.txt | 2 +- src/installer/corehost/cli/common.cmake | 2 +- .../corehost/cli/ijwhost/CMakeLists.txt | 8 +- .../cli/test/nativehost/CMakeLists.txt | 2 +- .../corehost/cli/test_fx_ver/CMakeLists.txt | 2 +- .../corehost/cli/winrthost/CMakeLists.txt | 4 +- src/installer/functions.cmake | 4 +- src/installer/settings.cmake | 58 +-- src/libraries/Native/Unix/CMakeLists.txt | 2 +- src/libraries/Native/build-native.cmd | 5 + src/libraries/Native/build-native.proj | 21 +- src/libraries/Native/build-native.sh | 424 +++------------- 33 files changed, 978 insertions(+), 1585 deletions(-) create mode 100755 eng/native/build-commons.sh create mode 100644 eng/native/configureplatform.cmake rename {src/coreclr => eng/native}/functions.cmake (100%) rename {src/coreclr => eng/native}/init-distro-rid.sh (100%) mode change 100755 => 100644 diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh new file mode 100755 index 00000000000000..63a6e6e8028f53 --- /dev/null +++ b/eng/native/build-commons.sh @@ -0,0 +1,479 @@ +#!/usr/bin/env bash + +initTargetDistroRid() +{ + source "$__RepoRootDir/eng/native/init-distro-rid.sh" + + local passedRootfsDir="" + + # Only pass ROOTFS_DIR if cross is specified. + if [ "$__CrossBuild" = 1 ]; then + passedRootfsDir="$ROOTFS_DIR" + fi + + initDistroRidGlobal "$__BuildOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir" +} + +isMSBuildOnNETCoreSupported() +{ + __IsMSBuildOnNETCoreSupported="$__msbuildonunsupportedplatform" + + if [ "$__IsMSBuildOnNETCoreSupported" = 1 ]; then + return + fi + + if [ "$__SkipManaged" = 1 ]; then + __IsMSBuildOnNETCoreSupported=0 + return + fi + + if [ "$__HostOS" = "Linux" ] && { [ "$__HostArch" = "x64" ] || [ "$__HostArch" = "arm" ] || [ "$__HostArch" = "arm64" ]; }; then + __IsMSBuildOnNETCoreSupported=1 + elif [ "$__HostArch" = "x64" ] && { [ "$__HostOS" = "OSX" ] || [ "$__HostOS" = "FreeBSD" ]; }; then + __IsMSBuildOnNETCoreSupported=1 + fi +} + +setup_dirs() +{ + echo Setting up directories for build + + mkdir -p "$__RootBinDir" + mkdir -p "$__BinDir" + mkdir -p "$__IntermediatesDir" +} + +# Check the system to ensure the right prereqs are in place +check_prereqs() +{ + echo "Checking prerequisites..." + + # Check presence of CMake on the path + command -v cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; } + + function version { echo "$@" | awk -F. '{ printf("%d%02d%02d\n", $1,$2,$3); }'; } + + local cmake_version="$(cmake --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")" + + if [ $(version "$cmake_version") -lt "$(version 3.14.2)" ]; then + echo "Please install CMake 3.14.2 or newer from http://www.cmake.org/download/ or https://apt.kitware.com and ensure it is on your path."; exit 1; + fi + + if [ "$__UseNinja" = 1 ]; then + command -v ninja 2>/dev/null || command -v ninja-build 2>/dev/null || { echo "Unable to locate ninja!"; exit 1; } + fi +} + +build_native() +{ + platformArch="$1" + cmakeDir="$2" + tryrunDir="$3" + intermediatesDir="$4" + message="$5" + + # All set to commence the build + echo "Commencing build of \"$message\" for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesDir" + + if [ "$__UseNinja" = 1 ]; then + generator="ninja" + buildTool="$(command -v ninja || command -v ninja-build)" + else + buildTool="make" + fi + + if [ "$__SkipConfigure" = 0 ]; then + # if msbuild is not supported, then set __SkipGenerateVersion to 1 + if [ "$__IsMSBuildOnNETCoreSupported" = 0 ]; then __SkipGenerateVersion=1; fi + # Drop version.c file + __versionSourceFile="$intermediatesDir/version.c" + if [ "$__SkipGenerateVersion" = 0 ]; then + "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary "$__ArcadeScriptArgs" "$__RepoRootDir"/eng/empty.csproj \ + /p:NativeVersionFile="$__versionSourceFile" \ + /t:GenerateNativeVersionFile /restore \ + $__CommonMSBuildArgs $__UnprocessedBuildArgs + local exit_code="$?" + if [ "$exit_code" != 0 ]; then + echo "${__ErrMsgPrefix}Failed to generate native version file." + exit "$exit_code" + fi + else + # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild + __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";" + if [ -e "$__versionSourceFile" ]; then + read existingVersionSourceLine < "$__versionSourceFile" + fi + if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then + echo "$__versionSourceLine" > "$__versionSourceFile" + fi + fi + + if [ "$__StaticAnalyzer" = 1 ]; then + scan_build=scan-build + fi + + engNativeDir="$__RepoRootDir/eng/native" + __CMakeArgs="-DCLR_ENG_NATIVE_DIR=\"$engNativeDir\" $__CMakeArgs" + nextCommand="\"$engNativeDir/gen-buildsys.sh\" \"$cmakeDir\" \"$tryrunDir\" \"$intermediatesDir\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType \"$generator\" $scan_build $__CMakeArgs" + echo "Invoking $nextCommand" + eval $nextCommand + + local exit_code="$?" + if [ "$exit_code" != 0 ]; then + echo "${__ErrMsgPrefix}Failed to generate \"$message\" build project!" + exit "$exit_code" + fi + fi + + # Check that the makefiles were created. + if [ ! -f "$intermediatesDir/CMakeCache.txt" ]; then + echo "${__ErrMsgPrefix}Unable to find generated build files for \"$message\" project!" + exit 1 + fi + + # Build + if [ "$__ConfigureOnly" = 1 ]; then + echo "Finish configuration & skipping \"$message\" build." + return + fi + + if [ "$__StaticAnalyzer" = 1 ]; then + pushd "$intermediatesDir" + + buildTool="$SCAN_BUILD_COMMAND -o $__BinDir/scan-build-log $buildTool" + echo "Executing $buildTool install -j $__NumProc" + "$buildTool" install -j "$__NumProc" + + popd + else + echo "Executing cmake --build \"$intermediatesDir\" --target install -j $__NumProc" + cmake --build "$intermediatesDir" --target install -j "$__NumProc" + fi + + local exit_code="$?" + if [ "$exit_code" != 0 ]; then + echo "${__ErrMsgPrefix}Failed to build \"$message\"." + exit "$exit_code" + fi +} + +usage() +{ + echo "Usage: $0 " + echo "" + echo "Common Options:" + echo "" + echo "BuildArch can be: -arm, -armel, -arm64, -armel, x64, x86, -wasm" + echo "BuildType can be: -debug, -checked, -release" + echo "-bindir: output directory (defaults to $__ProjectRoot/artifacts)" + echo "-ci: indicates if this is a CI build." + echo "-clang: optional argument to build using clang in PATH (default)." + echo "-clangx.y: optional argument to build using clang version x.y." + echo "-cmakeargs: user-settable additional arguments passed to CMake." + echo "-configureonly: do not perform any builds; just configure the build." + echo "-cross: optional argument to signify cross compilation," + echo " will use ROOTFS_DIR environment variable if set." + echo "-gcc: optional argument to build using gcc in PATH." + echo "-gccx.y: optional argument to build using gcc version x.y." + echo "-msbuildonunsupportedplatform: build managed binaries even if distro is not officially supported." + echo "-ninja: target ninja instead of GNU make" + echo "-numproc: set the number of build processes." + echo "-portablebuild: pass -portablebuild=false to force a non-portable build." + echo "-skipconfigure: skip build configuration." + echo "-skipgenerateversion: disable version generation even if MSBuild is supported." + echo "-stripsymbols: skip native image generation." + echo "-verbose: optional argument to enable verbose build output." + echo "" + echo "Additional Options:" + echo "" + for i in "${!usage_list[@]}"; do + echo "${usage_list[${i}]}" + done + echo "" + exit 1 +} + +# Use uname to determine what the CPU is. +CPUName=$(uname -p) + +# Some Linux platforms report unknown for platform, but the arch for machine. +if [ "$CPUName" = "unknown" ]; then + CPUName=$(uname -m) +fi + +case "$CPUName" in + aarch64) + __BuildArch=arm64 + __HostArch=arm64 + ;; + + amd64) + __BuildArch=x64 + __HostArch=x64 + ;; + + armv7l) + echo "Unsupported CPU $CPUName detected, build might not succeed!" + __BuildArch=arm + __HostArch=arm + ;; + + i686) + echo "Unsupported CPU $CPUName detected, build might not succeed!" + __BuildArch=x86 + __HostArch=x86 + ;; + + x86_64) + __BuildArch=x64 + __HostArch=x64 + ;; + + *) + echo "Unknown CPU $CPUName detected, configuring as if for x64" + __BuildArch=x64 + __HostArch=x64 + ;; +esac + +# Use uname to determine what the OS is. +OSName=$(uname -s) +case "$OSName" in + Darwin) + __BuildOS=OSX + __HostOS=OSX + ;; + + FreeBSD) + __BuildOS=FreeBSD + __HostOS=FreeBSD + ;; + + Linux) + __BuildOS=Linux + __HostOS=Linux + ;; + + NetBSD) + __BuildOS=NetBSD + __HostOS=NetBSD + ;; + + OpenBSD) + __BuildOS=OpenBSD + __HostOS=OpenBSD + ;; + + SunOS) + __BuildOS=SunOS + __HostOS=SunOS + ;; + + *) + echo "Unsupported OS $OSName detected, configuring as if for Linux" + __BuildOS=Linux + __HostOS=Linux + ;; +esac + +__msbuildonunsupportedplatform=0 + +while :; do + if [ "$#" -le 0 ]; then + break + fi + + lowerI="$(echo "$1" | awk '{print tolower($0)}')" + case "$lowerI" in + -\?|-h|--help) + usage + exit 1 + ;; + + arm|-arm) + __BuildArch=arm + ;; + + arm64|-arm64) + __BuildArch=arm64 + ;; + + armel|-armel) + __BuildArch=armel + ;; + + bindir|-bindir) + if [ -n "$2" ]; then + __RootBinDir="$2" + if [ ! -d "$__RootBinDir" ]; then + mkdir "$__RootBinDir" + fi + __RootBinParent=$(dirname "$__RootBinDir") + __RootBinName="${__RootBinDir##*/}" + __RootBinDir="$(cd "$__RootBinParent" &>/dev/null && printf %s/%s "$PWD" "$__RootBinName")" + shift + else + echo "ERROR: 'bindir' requires a non-empty option argument" + exit 1 + fi + ;; + + checked|-checked) + __BuildType=Checked + ;; + + ci|-ci) + __ArcadeScriptArgs="--ci" + __ErrMsgPrefix="##vso[task.logissue type=error]" + ;; + + clang*|-clang*) + __Compiler=clang + # clangx.y or clang-x.y + version="$(echo "$lowerI" | tr -d '[:alpha:]-=')" + parts=(${version//./ }) + __CompilerMajorVersion="${parts[0]}" + __CompilerMinorVersion="${parts[1]}" + if [ -z "$__CompilerMinorVersion" ] && [ "$__CompilerMajorVersion" -le 6 ]; then + __CompilerMinorVersion=0; + fi + ;; + + cmakeargs|-cmakeargs) + if [ -n "$2" ]; then + __CMakeArgs="$2 $__CMakeArgs" + shift + else + echo "ERROR: 'cmakeargs' requires a non-empty option argument" + exit 1 + fi + ;; + + configureonly|-configureonly) + __ConfigureOnly=1 + __SkipMSCorLib=1 + __SkipNuget=1 + ;; + + cross|-cross) + __CrossBuild=1 + ;; + + debug|-debug) + __BuildType=Debug + ;; + + gcc*|-gcc*) + __Compiler=gcc + # gccx.y or gcc-x.y + version="$(echo "$lowerI" | tr -d '[:alpha:]-=')" + parts=(${version//./ }) + __CompilerMajorVersion="${parts[0]}" + __CompilerMinorVersion="${parts[1]}" + ;; + + msbuildonunsupportedplatform|-msbuildonunsupportedplatform) + __msbuildonunsupportedplatform=1 + ;; + + ninja|-ninja) + __UseNinja=1 + ;; + + numproc|-numproc) + if [ -n "$2" ]; then + __NumProc="$2" + shift + else + echo "ERROR: 'numproc' requires a non-empty option argument" + exit 1 + fi + ;; + + portablebuild=false|-portablebuild=false) + __PortableBuild=0 + ;; + + release|-release) + __BuildType=Release + ;; + + skipconfigure|-skipconfigure) + __SkipConfigure=1 + ;; + + skipgenerateversion|-skipgenerateversion) + __SkipGenerateVersion=1 + ;; + + stripsymbols|-stripsymbols) + __CMakeArgs="-DSTRIP_SYMBOLS=true $__CMakeArgs" + ;; + + verbose|-verbose) + __VerboseBuild=1 + ;; + + x86|-x86) + __BuildArch=x86 + ;; + + x64|-x64) + __BuildArch=x64 + ;; + + wasm|-wasm) + __BuildArch=wasm + ;; + + *) + handle_arguments "$1" "$2" + if [ "$__ShiftArgs" = 1 ]; then + shift + __ShiftArgs=0 + fi + ;; + esac + + shift +done + +# Get the number of processors available to the scheduler +# Other techniques such as `nproc` only get the number of +# processors available to a single process. +platform=$(uname) +if [ "$platform" = "FreeBSD" ]; then + __NumProc=$(sysctl hw.ncpu | awk '{ print $2+1 }') +elif [ "$platform" = "NetBSD" ]; then + __NumProc=$(($(getconf NPROCESSORS_ONLN)+1)) +elif [ "$platform" = "Darwin" ]; then + __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1)) +else + __NumProc=$(nproc --all) +fi + +__CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg" + +# Configure environment if we are doing a verbose build +if [ "$__VerboseBuild" = 1 ]; then + export VERBOSE=1 + __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed" +fi + +if [ "$__PortableBuild" = 0 ]; then + __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false" +fi + +# Configure environment if we are doing a cross compile. +if [ "$__CrossBuild" = 1 ]; then + export CROSSCOMPILE=1 + if [ ! -n "$ROOTFS_DIR" ]; then + export ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__BuildArch" + fi +fi + +# init the target distro name +initTargetDistroRid + +# Init if MSBuild for .NET Core is supported for this platform +isMSBuildOnNETCoreSupported diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake new file mode 100644 index 00000000000000..1509c1012b158f --- /dev/null +++ b/eng/native/configureplatform.cmake @@ -0,0 +1,182 @@ +include(CheckPIESupported) + +# All code we build should be compiled as position independent +check_pie_supported(OUTPUT_VARIABLE PIE_SUPPORT_OUTPUT LANGUAGES CXX) +if(NOT MSVC AND NOT CMAKE_CXX_LINK_PIE_SUPPORTED) + message(WARNING "PIE is not supported at link time: ${PIE_SUPPORT_OUTPUT}.\n" + "PIE link options will not be passed to linker.") +endif() +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +#---------------------------------------- +# Detect and set platform variable names +# - for non-windows build platform & architecture is detected using inbuilt CMAKE variables and cross target component configure +# - for windows we use the passed in parameter to CMAKE to determine build arch +#---------------------------------------- +if(CMAKE_SYSTEM_NAME STREQUAL Linux) + set(CLR_CMAKE_PLATFORM_UNIX 1) + if(CLR_CROSS_COMPONENTS_BUILD) + # CMAKE_HOST_SYSTEM_PROCESSOR returns the value of `uname -p` on host. + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL amd64) + if(CLR_CMAKE_TARGET_ARCH STREQUAL "arm" OR CLR_CMAKE_TARGET_ARCH STREQUAL "armel") + if(CMAKE_CROSSCOMPILING) + set(CLR_CMAKE_PLATFORM_UNIX_X86 1) + else() + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + endif() + else() + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + endif() + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL i686) + set(CLR_CMAKE_PLATFORM_UNIX_X86 1) + else() + clr_unknown_arch() + endif() + else() + # CMAKE_SYSTEM_PROCESSOR returns the value of `uname -p` on target. + # For the AMD/Intel 64bit architecture two different strings are common. + # Linux and Darwin identify it as "x86_64" while FreeBSD and netbsd uses the + # "amd64" string. Accept either of the two here. + if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64) + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l) + set(CLR_CMAKE_PLATFORM_UNIX_ARM 1) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm) + set(CLR_CMAKE_PLATFORM_UNIX_ARM 1) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) + set(CLR_CMAKE_PLATFORM_UNIX_ARM64 1) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686) + set(CLR_CMAKE_PLATFORM_UNIX_X86 1) + else() + clr_unknown_arch() + endif() + endif() + set(CLR_CMAKE_PLATFORM_LINUX 1) + + # Detect Linux ID + set(LINUX_ID_FILE "/etc/os-release") + if(CMAKE_CROSSCOMPILING) + set(LINUX_ID_FILE "${CMAKE_SYSROOT}${LINUX_ID_FILE}") + endif() + + execute_process( + COMMAND bash -c "source ${LINUX_ID_FILE} && echo \$ID" + OUTPUT_VARIABLE CLR_CMAKE_LINUX_ID + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(DEFINED CLR_CMAKE_LINUX_ID) + if(CLR_CMAKE_LINUX_ID STREQUAL tizen) + set(CLR_CMAKE_TARGET_TIZEN_LINUX 1) + elseif(CLR_CMAKE_LINUX_ID STREQUAL alpine) + set(CLR_CMAKE_PLATFORM_ALPINE_LINUX 1) + endif() + endif(DEFINED CLR_CMAKE_LINUX_ID) +endif(CMAKE_SYSTEM_NAME STREQUAL Linux) + +if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(CLR_CMAKE_PLATFORM_UNIX 1) + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + set(CLR_CMAKE_PLATFORM_DARWIN 1) + set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} -o -c ") +endif(CMAKE_SYSTEM_NAME STREQUAL Darwin) + +if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + set(CLR_CMAKE_PLATFORM_UNIX 1) + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + set(CLR_CMAKE_PLATFORM_FREEBSD 1) +endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + +if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD) + set(CLR_CMAKE_PLATFORM_UNIX 1) + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + set(CLR_CMAKE_PLATFORM_OPENBSD 1) +endif(CMAKE_SYSTEM_NAME STREQUAL OpenBSD) + +if(CMAKE_SYSTEM_NAME STREQUAL NetBSD) + set(CLR_CMAKE_PLATFORM_UNIX 1) + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + set(CLR_CMAKE_PLATFORM_NETBSD 1) +endif(CMAKE_SYSTEM_NAME STREQUAL NetBSD) + +if(CMAKE_SYSTEM_NAME STREQUAL SunOS) + set(CLR_CMAKE_PLATFORM_UNIX 1) + EXECUTE_PROCESS( + COMMAND isainfo -n + OUTPUT_VARIABLE SUNOS_NATIVE_INSTRUCTION_SET + ) + if(SUNOS_NATIVE_INSTRUCTION_SET MATCHES "amd64") + set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) + set(CMAKE_SYSTEM_PROCESSOR "amd64") + else() + clr_unknown_arch() + endif() + set(CLR_CMAKE_PLATFORM_SUNOS 1) +endif(CMAKE_SYSTEM_NAME STREQUAL SunOS) + +#-------------------------------------------- +# This repo builds two set of binaries +# 1. binaries which execute on target arch machine +# - for such binaries host architecture & target architecture are same +# - eg. coreclr.dll +# 2. binaries which execute on host machine but target another architecture +# - host architecture is different from target architecture +# - eg. crossgen.exe - runs on x64 machine and generates nis targeting arm64 +# - for complete list of such binaries refer to file crosscomponents.cmake +#------------------------------------------------------------- +# Set HOST architecture variables +if(CLR_CMAKE_PLATFORM_UNIX_ARM) + set(CLR_CMAKE_PLATFORM_ARCH_ARM 1) + set(CLR_CMAKE_HOST_ARCH "arm") +elseif(CLR_CMAKE_PLATFORM_UNIX_ARM64) + set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1) + set(CLR_CMAKE_HOST_ARCH "arm64") +elseif(CLR_CMAKE_PLATFORM_UNIX_AMD64) + set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1) + set(CLR_CMAKE_HOST_ARCH "x64") +elseif(CLR_CMAKE_PLATFORM_UNIX_X86) + set(CLR_CMAKE_PLATFORM_ARCH_I386 1) + set(CLR_CMAKE_HOST_ARCH "x86") +elseif(WIN32) + # CLR_CMAKE_HOST_ARCH is passed in as param to cmake + if (CLR_CMAKE_HOST_ARCH STREQUAL x64) + set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1) + elseif(CLR_CMAKE_HOST_ARCH STREQUAL x86) + set(CLR_CMAKE_PLATFORM_ARCH_I386 1) + elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm) + set(CLR_CMAKE_PLATFORM_ARCH_ARM 1) + elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64) + set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1) + else() + clr_unknown_arch() + endif() +endif() + +# Set TARGET architecture variables +# Target arch will be a cmake param (optional) for both windows as well as non-windows build +# if target arch is not specified then host & target are same +if(NOT DEFINED CLR_CMAKE_TARGET_ARCH OR CLR_CMAKE_TARGET_ARCH STREQUAL "" ) + set(CLR_CMAKE_TARGET_ARCH ${CLR_CMAKE_HOST_ARCH}) +endif() + +# Set target architecture variables +if (CLR_CMAKE_TARGET_ARCH STREQUAL x64) + set(CLR_CMAKE_TARGET_ARCH_AMD64 1) + elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) + set(CLR_CMAKE_TARGET_ARCH_I386 1) + elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64) + set(CLR_CMAKE_TARGET_ARCH_ARM64 1) + elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm) + set(CLR_CMAKE_TARGET_ARCH_ARM 1) + elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armel) + set(CLR_CMAKE_TARGET_ARCH_ARM 1) + set(ARM_SOFTFP 1) + else() + clr_unknown_arch() +endif() + +# check if host & target arch combination are valid +if(NOT(CLR_CMAKE_TARGET_ARCH STREQUAL CLR_CMAKE_HOST_ARCH)) + if(NOT((CLR_CMAKE_PLATFORM_ARCH_AMD64 AND CLR_CMAKE_TARGET_ARCH_ARM64) OR (CLR_CMAKE_PLATFORM_ARCH_I386 AND CLR_CMAKE_TARGET_ARCH_ARM) OR (CLR_CMAKE_PLATFORM_ARCH_AMD64 AND CLR_CMAKE_TARGET_ARCH_ARM))) + message(FATAL_ERROR "Invalid host and target arch combination") + endif() +endif() diff --git a/src/coreclr/functions.cmake b/eng/native/functions.cmake similarity index 100% rename from src/coreclr/functions.cmake rename to eng/native/functions.cmake diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index 32e82f2fd05c5e..beb910087f5bc0 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -3,26 +3,15 @@ # This file invokes cmake and generates the build system for Clang. # -source="${BASH_SOURCE[0]}" +scriptroot="$( cd -P "$( dirname "$0" )" && pwd )" -# resolve $SOURCE until the file is no longer a symlink -while [[ -h $source ]]; do - scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" - source="$(readlink "$source")" - - # if $source was a relative symlink, we need to resolve it relative to the path where the - # symlink file was located - [[ $source != /* ]] && source="$scriptroot/$source" -done -scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" - -if [ $# -lt 4 ] +if [ "$#" -lt 4 ] then echo "Usage..." - echo "gen-buildsys.sh [build flavor] [ninja] [scan-build] [cmakeargs]" + echo "gen-buildsys.sh [build flavor] [ninja] [scan-build] [cmakeargs]" echo "Specify the path to the top level CMake file." - echo "Specify the path to the directory with tryrun.cmake file." echo "Specify the path that the build system files are generated in." + echo "Specify the path to the directory with tryrun.cmake file." echo "Specify the target architecture." echo "Specify the name of compiler (clang or gcc)." echo "Specify the major version of compiler." @@ -77,8 +66,8 @@ if [ -z "$CLR_CC" ]; then if [ "$(uname)" != "Darwin" ]; then echo "WARN: Specific version of $compiler not found, falling back to use the one in PATH." fi - export CC="$(command -v "$compiler")" - export CXX="$(command -v "$cxxCompiler")" + CC="$(command -v "$compiler")" + CXX="$(command -v "$cxxCompiler")" else echo "ERROR: No usable version of $compiler found." exit 1 @@ -88,8 +77,8 @@ if [ -z "$CLR_CC" ]; then if [ "$build_arch" = "arm" ] || [ "$build_arch" = "armel" ]; then if command -v "$compiler" > /dev/null; then echo "WARN: Found clang version $majorVersion which is not supported on arm/armel architectures, falling back to use clang from PATH." - export CC="$(command -v "$compiler")" - export CXX="$(command -v "$cxxCompiler")" + CC="$(command -v "$compiler")" + CXX="$(command -v "$cxxCompiler")" else echo "ERROR: Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH." exit 1 @@ -106,17 +95,17 @@ if [ -z "$CLR_CC" ]; then fi if [ -z "$CC" ]; then - export CC="$(command -v "$compiler$desired_version")" - export CXX="$(command -v "$cxxCompiler$desired_version")" - if [ -z "$CXX" ]; then export CXX="$(command -v "$cxxCompiler")"; fi + CC="$(command -v "$compiler$desired_version")" + CXX="$(command -v "$cxxCompiler$desired_version")" + if [ -z "$CXX" ]; then CXX="$(command -v "$cxxCompiler")"; fi fi else if [ ! -f "$CLR_CC" ]; then echo "ERROR: CLR_CC is set but path '$CLR_CC' does not exist" exit 1 fi - export CC="$CLR_CC" - export CXX="$CLR_CXX" + CC="$CLR_CC" + CXX="$CLR_CXX" fi if [ -z "$CC" ]; then @@ -124,9 +113,11 @@ if [ -z "$CC" ]; then exit 1 fi -export CCC_CC="$CC" -export CCC_CXX="$CXX" -export SCAN_BUILD_COMMAND="$(command -v "scan-build$desired_version")" +CCC_CC="$CC" +CCC_CXX="$CXX" +SCAN_BUILD_COMMAND="$(command -v "scan-build$desired_version")" + +export CC CCC_CC CXX CCC_CXX SCAN_BUILD_COMMAND buildtype=DEBUG code_coverage=OFF @@ -136,11 +127,11 @@ generator="Unix Makefiles" __UnprocessedCMakeArgs="" for i in "${@:8}"; do - upperI="$(echo $i | awk '{print toupper($0)}')" - case $upperI in + upperI="$(echo "$i" | awk '{print toupper($0)}')" + case "$upperI" in # Possible build types are DEBUG, CHECKED, RELEASE, RELWITHDEBINFO. DEBUG | CHECKED | RELEASE | RELWITHDEBINFO) - buildtype=$upperI + buildtype="$upperI" ;; NINJA) generator=Ninja @@ -154,16 +145,19 @@ for i in "${@:8}"; do esac done -OS=`uname` - cmake_extra_defines= if [ "$CROSSCOMPILE" == "1" ]; then if ! [[ -n "$ROOTFS_DIR" ]]; then echo "ROOTFS_DIR not set for crosscompile" exit 1 fi - export TARGET_BUILD_ARCH=$build_arch - cmake_extra_defines="$cmake_extra_defines -C $tryrun_dir/tryrun.cmake" + + TARGET_BUILD_ARCH="$build_arch" + export TARGET_BUILD_ARCH + + if [ -n "$tryrun_dir" ]; then + cmake_extra_defines="$cmake_extra_defines -C $tryrun_dir/tryrun.cmake" + fi cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$scriptroot/../common/cross/toolchain.cmake" fi diff --git a/src/coreclr/init-distro-rid.sh b/eng/native/init-distro-rid.sh old mode 100755 new mode 100644 similarity index 100% rename from src/coreclr/init-distro-rid.sh rename to eng/native/init-distro-rid.sh diff --git a/eng/pipelines/installer/jobs/base-job.yml b/eng/pipelines/installer/jobs/base-job.yml index bdd5680c1989eb..e751eed2bc313d 100644 --- a/eng/pipelines/installer/jobs/base-job.yml +++ b/eng/pipelines/installer/jobs/base-job.yml @@ -182,6 +182,8 @@ jobs: # lowercase for RID format. (Detection normally converts, but we're preventing it.) - name: OutputRidArg value: /p:OutputRid=linux-musl-${{ parameters.archType }} + - name: _PortableBuild + value: true - name: BuildArguments value: >- diff --git a/eng/pipelines/libraries/base-job.yml b/eng/pipelines/libraries/base-job.yml index 45380e41c308e7..d6006d2f99be86 100644 --- a/eng/pipelines/libraries/base-job.yml +++ b/eng/pipelines/libraries/base-job.yml @@ -3,6 +3,7 @@ parameters: osGroup: '' archType: '' osSubgroup: '' + crossrootfsDir: '' framework: '' isOfficialBuild: false isOfficialAllConfigurations: false @@ -49,6 +50,9 @@ jobs: - ${{ if ne(parameters.testScope, '') }}: - _testScopeArg: -testscope ${{ parameters.testScope }} + - ${{ if eq(parameters.osGroup, 'Linux') }}: + - _crossBuildPropertyArg: /p:CrossBuild=${{ ne(parameters.crossrootfsDir, '') }} + - ${{ if and(eq(parameters.osGroup, 'Linux'), eq(parameters.osSubGroup, '_musl')) }}: - _runtimeOSArg: /p:RuntimeOS=linux-musl @@ -94,7 +98,8 @@ jobs: - ${{ if eq(parameters.isOfficialBuild, 'true') }}: - _stripSymbolsArg: -stripSymbols - - _buildArguments: -configuration ${{ parameters.buildConfig }} -ci -arch ${{ parameters.archType }} $(_finalFrameworkArg) $(_stripSymbolsArg) $(_testScopeArg) $(_warnAsErrorArg) $(_runtimeOSArg) $(_msbuildCommonParameters) $(_coreClrArtifactsPathArg) + - _buildArguments: -configuration ${{ parameters.buildConfig }} -ci -arch ${{ parameters.archType }} $(_finalFrameworkArg) $(_stripSymbolsArg) $(_testScopeArg) $(_warnAsErrorArg) $(_runtimeOSArg) $(_msbuildCommonParameters) $(_coreClrArtifactsPathArg) $(_crossBuildPropertyArg) + - ${{ parameters.variables }} dependsOn: diff --git a/eng/pipelines/libraries/build-job.yml b/eng/pipelines/libraries/build-job.yml index 01a4594ef804ad..817b5f018defbd 100644 --- a/eng/pipelines/libraries/build-job.yml +++ b/eng/pipelines/libraries/build-job.yml @@ -3,6 +3,7 @@ parameters: osGroup: '' osSubgroup: '' archType: '' + crossrootfsDir: '' framework: netcoreapp isOfficialBuild: false isOfficialAllConfigurations: false @@ -30,6 +31,7 @@ jobs: osGroup: ${{ parameters.osGroup }} osSubgroup: ${{ parameters.osSubgroup }} archType: ${{ parameters.archType }} + crossrootfsDir: ${{ parameters.crossrootfsDir }} framework: ${{ parameters.framework }} isOfficialBuild: ${{ parameters.isOfficialBuild }} isOfficialAllConfigurations: ${{ parameters.isOfficialAllConfigurations }} diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 2929f7eda5bdde..de99bf55766ee5 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_policy(SET CMP0042 NEW) project(CoreCLR) # Include cmake functions -include(functions.cmake) +include(${CLR_ENG_NATIVE_DIR}/functions.cmake) if (WIN32) message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}") diff --git a/src/coreclr/_build-commons.sh b/src/coreclr/_build-commons.sh index b60118444889f7..8bac206f28ff4d 100755 --- a/src/coreclr/_build-commons.sh +++ b/src/coreclr/_build-commons.sh @@ -1,293 +1,14 @@ #!/usr/bin/env bash -initTargetDistroRid() -{ - source "${__ProjectDir}/init-distro-rid.sh" +usage_list+=("-coverage: optional argument to enable code coverage build (currently supported only for Linux and OSX).") +usage_list+=("-skipmanaged: do not build managed components.") +usage_list+=("-skipnative: do not build native components.") - local passedRootfsDir="" - - # Only pass ROOTFS_DIR if cross is specified. - if [ "$__CrossBuild" = 1 ]; then - passedRootfsDir="${ROOTFS_DIR}" - fi - - initDistroRidGlobal "$__BuildOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir" -} - -isMSBuildOnNETCoreSupported() -{ - __isMSBuildOnNETCoreSupported="$__msbuildonunsupportedplatform" - - if [ "$__isMSBuildOnNETCoreSupported" = 1 ]; then - return - fi - - if [ "$__SkipManaged" = 1 ]; then - __isMSBuildOnNETCoreSupported=0 - return - fi - - if [ "$__HostOS" = "Linux" ] && { [ "$__HostArch" = "x64" ] || [ "$__HostArch" = "arm" ] || [ "$__HostArch" = "arm64" ]; }; then - __isMSBuildOnNETCoreSupported=1 - elif [ "$__HostArch" = "x64" ] && { [ "$__HostOS" = "OSX" ] || [ "$__HostOS" = "FreeBSD" ]; }; then - __isMSBuildOnNETCoreSupported=1 - fi -} - -usage() -{ - echo "Usage: $0 " - echo "" - echo "Common Options:" - echo "" - echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64" - echo "BuildType can be: -debug, -checked, -release" - echo "-bindir - output directory (defaults to $__ProjectRoot/artifacts)" - echo "-clang - optional argument to build using clang in PATH (default)." - echo "-clangx.y - optional argument to build using clang version x.y." - echo "-cmakeargs - user-settable additional arguments passed to CMake." - echo "-configureonly - do not perform any builds; just configure the build." - echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)." - echo "-cross - optional argument to signify cross compilation," - echo " - will use ROOTFS_DIR environment variable if set." - echo "-gcc - optional argument to build using gcc in PATH." - echo "-gccx.y - optional argument to build using gcc version x.y." - echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported." - echo "-ninja - target ninja instead of GNU make" - echo "-numproc - set the number of build processes." - echo "-portablebuild - pass -portablebuild=false to force a non-portable build." - echo "-skipconfigure - skip build configuration." - echo "-skipmanaged - do not build managed components." - echo "-skipnative - do not build native components." - echo "-skipgenerateversion - disable version generation even if MSBuild is supported." - echo "-verbose - optional argument to enable verbose build output." - echo "" - echo "Additional Options:" - echo "" - for i in "${!usage_list[@]}"; do - echo "${usage_list[${i}]}" - done - echo "" - exit 1 -} - -# Use uname to determine what the CPU is. -CPUName=$(uname -p) - -# Some Linux platforms report unknown for platform, but the arch for machine. -if [ "$CPUName" = "unknown" ]; then - CPUName=$(uname -m) -fi - -case "$CPUName" in - aarch64) - __BuildArch=arm64 - __HostArch=arm64 - ;; - - amd64) - __BuildArch=x64 - __HostArch=x64 - ;; - - armv7l) - echo "Unsupported CPU $CPUName detected, build might not succeed!" - __BuildArch=arm - __HostArch=arm - ;; - - i686) - echo "Unsupported CPU $CPUName detected, build might not succeed!" - __BuildArch=x86 - __HostArch=x86 - ;; - - x86_64) - __BuildArch=x64 - __HostArch=x64 - ;; - - *) - echo "Unknown CPU $CPUName detected, configuring as if for x64" - __BuildArch=x64 - __HostArch=x64 - ;; -esac - -# Use uname to determine what the OS is. -OSName=$(uname -s) -case "$OSName" in - Darwin) - __BuildOS=OSX - __HostOS=OSX - ;; - - FreeBSD) - __BuildOS=FreeBSD - __HostOS=FreeBSD - ;; - - Linux) - __BuildOS=Linux - __HostOS=Linux - ;; - - NetBSD) - __BuildOS=NetBSD - __HostOS=NetBSD - ;; - - OpenBSD) - __BuildOS=OpenBSD - __HostOS=OpenBSD - ;; - - SunOS) - __BuildOS=SunOS - __HostOS=SunOS - ;; - - *) - echo "Unsupported OS $OSName detected, configuring as if for Linux" - __BuildOS=Linux - __HostOS=Linux - ;; -esac - -while :; do - if [ "$#" -le 0 ]; then - break - fi - - lowerI="$(echo "$1" | awk '{print tolower($0)}')" - case "$lowerI" in - -\?|-h|--help) - usage - exit 1 - ;; - - arm|-arm) - __BuildArch=arm - ;; - - arm64|-arm64) - __BuildArch=arm64 - ;; - - armel|-armel) - __BuildArch=armel - ;; - - bindir|-bindir) - if [ -n "$2" ]; then - __RootBinDir="$2" - if [ ! -d "$__RootBinDir" ]; then - mkdir "$__RootBinDir" - fi - __RootBinParent=$(dirname "$__RootBinDir") - __RootBinName="${__RootBinDir##*/}" - __RootBinDir="$(cd "$__RootBinParent" &>/dev/null && printf %s/%s "$PWD" "$__RootBinName")" - shift - else - echo "ERROR: 'bindir' requires a non-empty option argument" - exit 1 - fi - ;; - - checked|-checked) - __BuildType=Checked - ;; - - ci|-ci) - __ArcadeScriptArgs="--ci" - __ErrMsgPrefix="##vso[task.logissue type=error]" - ;; - - clang*|-clang*) - __Compiler=clang - # clangx.y or clang-x.y - version="$(echo "$lowerI" | tr -d '[:alpha:]-=')" - parts=(${version//./ }) - __CompilerMajorVersion="${parts[0]}" - __CompilerMinorVersion="${parts[1]}" - if [ -z "$__CompilerMinorVersion" ] && [ "$__CompilerMajorVersion" -le 6 ]; then - __CompilerMinorVersion=0; - fi - ;; - - cmakeargs|-cmakeargs) - if [ -n "$2" ]; then - __cmakeargs="$__cmakeargs $2" - shift - else - echo "ERROR: 'cmakeargs' requires a non-empty option argument" - exit 1 - fi - ;; - - configureonly|-configureonly) - __ConfigureOnly=1 - __SkipMSCorLib=1 - __SkipNuget=1 - ;; +handle_arguments() { + case "$1" in coverage|-coverage) - __CodeCoverage=Coverage - ;; - - cross|-cross) - __CrossBuild=1 - ;; - - debug|-debug) - __BuildType=Debug - ;; - - gcc*|-gcc*) - __Compiler=gcc - # gccx.y or gcc-x.y - version="$(echo "$lowerI" | tr -d '[:alpha:]-=')" - parts=(${version//./ }) - __CompilerMajorVersion="${parts[0]}" - __CompilerMinorVersion="${parts[1]}" - ;; - - msbuildonunsupportedplatform|-msbuildonunsupportedplatform) - __msbuildonunsupportedplatform=1 - ;; - - ninja|-ninja) - __UseNinja=1 - ;; - - numproc|-numproc) - if [ -n "$2" ]; then - __NumProc="$2" - shift - else - echo "ERROR: 'numproc' requires a non-empty option argument" - exit 1 - fi - ;; - - portablebuild=false|-portablebuild=false) - __PortableBuild=0 - ;; - - rebuild|-rebuild) - __RebuildTests=1 - ;; - - release|-release) - __BuildType=Release - ;; - - skipconfigure|-skipconfigure) - __SkipConfigure=1 - ;; - - skipgenerateversion|-skipgenerateversion) - __SkipGenerateVersion=1 + __CodeCoverage=1 ;; skipmanaged|-skipmanaged) @@ -301,44 +22,10 @@ while :; do __CopyNativeProjectsAfterCombinedTestBuild=false ;; - verbose|-verbose) - __VerboseBuild=1 - ;; - - x86|-x86) - __BuildArch=x86 - ;; - - x64|-x64) - __BuildArch=x64 - ;; - *) - handle_arguments "$1" + handle_arguments_local "$1" ;; esac +} - shift -done - -# Get the number of processors available to the scheduler -# Other techniques such as `nproc` only get the number of -# processors available to a single process. -platform=$(uname) -if [ "$platform" = "FreeBSD" ]; then - __NumProc=$(sysctl hw.ncpu | awk '{ print $2+1 }') -elif [ "$platform" = "NetBSD" ]; then - __NumProc=$(($(getconf NPROCESSORS_ONLN)+1)) -elif [ "$platform" = "Darwin" ]; then - __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1)) -else - __NumProc=$(nproc --all) -fi - -__CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg" - -# Configure environment if we are doing a verbose build -if [ "$__VerboseBuild" = 1 ]; then - export VERBOSE=1 - __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed" -fi +source "$__RepoRootDir"/eng/native/build-commons.sh diff --git a/src/coreclr/build-packages.sh b/src/coreclr/build-packages.sh index a0c7b1fce00e30..9617440e44bee6 100755 --- a/src/coreclr/build-packages.sh +++ b/src/coreclr/build-packages.sh @@ -12,12 +12,12 @@ usage() initDistroRid() { - source ${__ProjectRoot}/init-distro-rid.sh + source $__RepoRootDir/eng/native/init-distro-rid.sh local passedRootfsDir="" # Only pass ROOTFS_DIR if __DoCrossArchBuild is specified. - if (( ${__CrossBuild} == 1 )); then + if (( __CrossBuild == 1 )); then passedRootfsDir=${ROOTFS_DIR} fi diff --git a/src/coreclr/build-test.sh b/src/coreclr/build-test.sh index 37d9154bb311ab..d3dff1af213756 100755 --- a/src/coreclr/build-test.sh +++ b/src/coreclr/build-test.sh @@ -2,7 +2,7 @@ build_test_wrappers() { - if [ $__BuildTestWrappers -ne -0 ]; then + if [ "$__BuildTestWrappers" -ne -0 ]; then echo "${__MsgPrefix}Creating test wrappers..." export __Exclude="${__ProjectDir}/tests/issues.targets" @@ -10,12 +10,12 @@ build_test_wrappers() buildVerbosity="Summary" - if [ $__VerboseBuild == 1 ]; then + if [ "$__VerboseBuild" = 1 ]; then buildVerbosity="Diag" fi # Set up directories and file names - __BuildLogRootName=$subDirectoryName + __BuildLogRootName="$subDirectoryName" __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log" __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn" __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err" @@ -308,7 +308,7 @@ build_Tests() fi if [ $__SkipNative != 1 ]; then - build_native_projects "$__BuildArch" "${__NativeTestIntermediatesDir}" + build_native "$__BuildArch" "$__TestDir" "$__ProjectRoot" "$__NativeTestIntermediatesDir" "CoreCLR test component" if [ $? -ne 0 ]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: native test build failed. Refer to the build log files for details (above)" @@ -459,107 +459,22 @@ build_MSBuild_projects() fi } -build_native_projects() -{ - platformArch="$1" - intermediatesForBuild="$2" - - extraCmakeArguments="" - message="native tests assets" - - # All set to commence the build - echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild" - - generator="" - if [ $__UseNinja == 1 ]; then - generator="ninja" - if ! buildTool=$(command -v ninja || command -v ninja-build); then - echo "Unable to locate ninja!" 1>&2 - exit 1 - fi - fi - - if [ $__SkipConfigure == 0 ]; then - # if msbuild is not supported, then set __SkipGenerateVersion to 1 - if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi - # Drop version.c file - __versionSourceFile="$intermediatesForBuild/version.c" - if [ $__SkipGenerateVersion == 0 ]; then - pwd - $__RepoRootDir/eng/common/msbuild.sh $__RepoRootDir/eng/empty.csproj \ - /p:NativeVersionFile=$__versionSourceFile \ - /t:GenerateNativeVersionFile /restore \ - $__CommonMSBuildArgs $__UnprocessedBuildArgs - if [ $? -ne 0 ]; then - echo "${__ErrMsgPrefix}Failed to generate native version file." - exit $? - fi - else - # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild - __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";" - if [ -e $__versionSourceFile ]; then - read existingVersionSourceLine < $__versionSourceFile - fi - if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then - echo $__versionSourceLine > $__versionSourceFile - fi - fi - - if [[ -n "$__CodeCoverage" ]]; then - extraCmakeArguments="$extraCmakeArguments -DCLR_CMAKE_ENABLE_CODE_COVERAGE=1" - fi - - engNativeDir="$__RepoRootDir/eng/native" - __cmakeargs="$__cmakeargs -DCLR_ENG_NATIVE_DIR=\"$engNativeDir\"" - nextCommand="\"$engNativeDir/gen-buildsys.sh\" \"$__TestDir\" \"$__ProjectRoot\" \"$intermediatesForBuild\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType $generator $extraCmakeArguments $__cmakeargs" - echo "Invoking $nextCommand" - eval $nextCommand - - if [ $? != 0 ]; then - echo "${__ErrMsgPrefix}Failed to generate $message build project!" - exit 1 - fi - fi - - if [ ! -f "$intermediatesForBuild/CMakeCache.txt" ]; then - echo "${__ErrMsgPrefix}Unable to find generated build files for $message project!" - exit 1 - fi - - # Build - if [ $__ConfigureOnly == 1 ]; then - echo "Finish configuration & skipping $message build." - return - fi - - echo "Executing cmake --build \"$intermediatesForBuild\" --target install -j $__NumProc" - - cmake --build "$intermediatesForBuild" --target install -j $__NumProc - - local exit_code=$? - if [ $exit_code != 0 ]; then - echo "${__ErrMsgPrefix}Failed to build $message." - exit $exit_code - fi - - echo "Native tests build success!" -} - -usage_list=("-buildtestwrappersonly - only build the test wrappers.") +usage_list=("-buildtestwrappersonly: only build the test wrappers.") usage_list+=("-copynativeonly: Only copy the native test binaries to the managed output. Do not build the native or managed tests.") -usage_list+=("-crossgen - Precompiles the framework managed assemblies in coreroot.") -usage_list+=("-generatelayoutonly - only pull down dependencies and build coreroot.") -usage_list+=("-priority1 - include priority=1 tests in the build.") -usage_list+=("-runtests - run tests after building them.") +usage_list+=("-crossgen: Precompiles the framework managed assemblies in coreroot.") +usage_list+=("-generatelayoutonly: only pull down dependencies and build coreroot.") +usage_list+=("-priority1: include priority=1 tests in the build.") +usage_list+=("-rebuild: if tests have already been built - rebuild them.") +usage_list+=("-runtests: run tests after building them.") usage_list+=("-skipgeneratelayout: Do not generate the Core_Root layout.") -usage_list+=("-skiprestorepackages - skip package restore.") +usage_list+=("-skiprestorepackages: skip package restore.") # Obtain the location of the bash script to figure out where the root of the repo is. __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -__RepoRootDir=${__ProjectRoot}/../.. +__RepoRootDir="${__ProjectRoot}/../.." -handle_arguments() { - case $1 in +handle_arguments_local() { + case "$1" in buildtestwrappersonly|-buildtestwrappersonly) __BuildTestWrappersOnly=1 ;; @@ -592,6 +507,10 @@ handle_arguments() { __UnprocessedBuildArgs+=("/p:CLRTestPriorityToBuild=1") ;; + rebuild|-rebuild) + __RebuildTests=1 + ;; + runtests|-runtests) __RunTests=1 ;; @@ -633,6 +552,7 @@ __DoCrossgen2=0 __DotNetCli="$__RepoRootDir/dotnet.sh" __GenerateLayoutOnly= __GenerateTestHostOnly= +__IsMSBuildOnNETCoreSupported=0 __MSBCleanBuildArgs= __NativeTestIntermediatesDir= __PortableBuild=1 @@ -651,8 +571,7 @@ __UnprocessedBuildArgs= __LocalCoreFXConfig=${__BuildType} __UseNinja=0 __VerboseBuild=0 -__cmakeargs="" -__msbuildonunsupportedplatform=0 +__CMakeArgs="" __priority1= CORE_ROOT= @@ -673,42 +592,26 @@ __TestDir="$__ProjectDir/tests" __TestWorkingDir="$__RootBinDir/tests/coreclr/$__BuildOS.$__BuildArch.$__BuildType" __IntermediatesDir="$__RootBinDir/obj/coreclr/$__BuildOS.$__BuildArch.$__BuildType" __TestIntermediatesDir="$__RootBinDir/tests/coreclr/obj/$__BuildOS.$__BuildArch.$__BuildType" -__isMSBuildOnNETCoreSupported=0 __CrossComponentBinDir="$__BinDir" __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen" __CrossArch="$__HostArch" -if [ $__CrossBuild == 1 ]; then +if [ "$__CrossBuild" = 1 ]; then __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch" fi __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log" __CrossgenExe="$__CrossComponentBinDir/crossgen" -isMSBuildOnNETCoreSupported - # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to it. # This is needed by CLI to function. if [ -z "$HOME" ]; then if [ ! -d "$__ProjectDir/temp_home" ]; then mkdir temp_home fi - export HOME=$__ProjectDir/temp_home - echo "HOME not defined; setting it to $HOME" -fi - -# Configure environment if we are doing a cross compile. -if [ $__CrossBuild == 1 ]; then - export CROSSCOMPILE=1 - if ! [[ -n "$ROOTFS_DIR" ]]; then - export ROOTFS_DIR="$__RepoRootDir/eng/common/cross/rootfs/$__BuildArch" - fi -fi -# init the target distro name -initTargetDistroRid - -if [ $__PortableBuild == 0 ]; then - __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false" + HOME="$__ProjectDir"/temp_home + export HOME + echo "HOME not defined; setting it to $HOME" fi if [[ (-z "$__GenerateLayoutOnly") && (-z "$__GenerateTestHostOnly") && (-z "$__BuildTestWrappersOnly") ]]; then diff --git a/src/coreclr/build.cmd b/src/coreclr/build.cmd index 698d2683e9f015..a668f9fe15485e 100644 --- a/src/coreclr/build.cmd +++ b/src/coreclr/build.cmd @@ -23,11 +23,6 @@ if defined VS160COMNTOOLS ( set __VSVersion=vs2017 ) -:: Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment -:: variables, and msbuild can't handle environment blocks with such large variables. So clear -:: out the variables that might be too large. -set ghprbCommentBody= - :: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set: :: __BuildArch -- default: x64 :: __BuildType -- default: Debug diff --git a/src/coreclr/build.sh b/src/coreclr/build.sh index 11caf9bbc6e56d..07e5580358685d 100755 --- a/src/coreclr/build.sh +++ b/src/coreclr/build.sh @@ -1,12 +1,7 @@ #!/usr/bin/env bash -# Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment -# variables, and msbuild can't handle environment blocks with such large variables. So clear -# out the variables that might be too large. -export ghprbCommentBody= - # resolve python-version to use -if [ "$PYTHON" == "" ] ; then +if [ -z "$PYTHON" ] ; then if ! PYTHON=$(command -v python3 || command -v python2 || command -v python || command -v py) then echo "Unable to locate build-dependency python!" 1>&2 @@ -15,7 +10,7 @@ if [ "$PYTHON" == "" ] ; then fi # validate python-dependency # useful in case of explicitly set option. -if ! command -v $PYTHON > /dev/null +if ! command -v "$PYTHON" > /dev/null then echo "Unable to locate build-dependency python ($PYTHON)!" 1>&2 exit 1 @@ -38,45 +33,23 @@ usage_list+=("-skipnuget: skip NuGet package generation.") usage_list+=("-skiprestore: specify the official build ID to be used by this build.") usage_list+=("-skiprestoreoptdata: build CoreLib as PartialNGen.") usage_list+=("-staticanalyzer: skip native image generation.") -usage_list+=("-stripSymbols: skip native image generation.") -setup_dirs() +setup_dirs_local() { - echo Setting up directories for build + setup_dirs - mkdir -p "$__RootBinDir" - mkdir -p "$__BinDir" mkdir -p "$__LogsDir" mkdir -p "$__MsbuildDebugLogsDir" - mkdir -p "$__IntermediatesDir" - if [ $__CrossBuild == 1 ]; then + if [ "$__CrossBuild" = 1 ]; then mkdir -p "$__CrossComponentBinDir" fi } -# Check the system to ensure the right prereqs are in place - -check_prereqs() -{ - echo "Checking prerequisites..." - - # Check presence of CMake on the path - hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; } - - function version { echo "$@" | awk -F. '{ printf("%d%02d%02d\n", $1,$2,$3); }'; } - - local cmake_version=$(cmake --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+") - - if [[ $(version $cmake_version) -lt $(version 3.14.0) ]]; then - echo "Please install CMake 3.14 or newer from http://www.cmake.org/download/ or https://apt.kitware.com and ensure it is on your path."; exit 1; - fi -} - restore_optdata() { local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj" - if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then + if [ "$__SkipRestoreOptData" = 0 ] && [ "$__IsMSBuildOnNETCoreSupported" = 1 ]; then echo "Restoring the OptimizationData package" "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs \ $OptDataProjectFilePath /t:Restore /m \ @@ -88,7 +61,7 @@ restore_optdata() fi fi - if [ $__isMSBuildOnNETCoreSupported == 1 ]; then + if [ "$__IsMSBuildOnNETCoreSupported" = 1 ]; then # Parse the optdata package versions out of msbuild so that we can pass them on to CMake local PgoDataPackagePathOutputFile="${__IntermediatesDir}/optdatapath.txt" @@ -137,115 +110,6 @@ generate_event_logging() fi } -build_native() -{ - skipCondition=$1 - platformArch="$2" - intermediatesForBuild="$3" - extraCmakeArguments="$4" - message="$5" - - if [ $skipCondition == 1 ]; then - echo "Skipping $message build." - return - fi - - # All set to commence the build - echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild" - - generator="" - buildTool="make" - if [ $__UseNinja == 1 ]; then - generator="ninja" - if ! buildTool=$(command -v ninja || command -v ninja-build); then - echo "Unable to locate ninja!" 1>&2 - exit 1 - fi - fi - - if [ $__SkipConfigure == 0 ]; then - # if msbuild is not supported, then set __SkipGenerateVersion to 1 - if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi - # Drop version.c file - __versionSourceFile="$intermediatesForBuild/version.c" - if [ $__SkipGenerateVersion == 0 ]; then - pwd - "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs $__RepoRootDir/eng/empty.csproj \ - /p:NativeVersionFile=$__versionSourceFile \ - /t:GenerateNativeVersionFile /restore \ - $__CommonMSBuildArgs $__UnprocessedBuildArgs - local exit_code=$? - if [ $exit_code != 0 ]; then - echo "${__ErrMsgPrefix}Failed to generate native version file." - exit $exit_code - fi - else - # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild - __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";" - if [ -e $__versionSourceFile ]; then - read existingVersionSourceLine < $__versionSourceFile - fi - if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then - echo $__versionSourceLine > $__versionSourceFile - fi - fi - - # Regenerate the CMake solution - - if [ "$__StaticAnalyzer" = 1 ]; then - scan_build=scan-build - fi - if [[ -n "$__CodeCoverage" ]]; then - extraCmakeArguments="$extraCmakeArguments -DCLR_CMAKE_ENABLE_CODE_COVERAGE=1" - fi - - engNativeDir="$__RepoRootDir/eng/native" - __cmakeargs="$__cmakeargs -DCLR_ENG_NATIVE_DIR=\"$engNativeDir\"" - nextCommand="\"$engNativeDir/gen-buildsys.sh\" \"$__ProjectRoot\" \"$__ProjectRoot\" \"$intermediatesForBuild\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType $generator $scan_build $extraCmakeArguments $__cmakeargs" - echo "Invoking $nextCommand" - eval $nextCommand - - if [ $? != 0 ]; then - echo "${__ErrMsgPrefix}Failed to generate $message build project!" - exit 1 - fi - fi - - if [ ! -f "$intermediatesForBuild/CMakeCache.txt" ]; then - echo "${__ErrMsgPrefix}Unable to find generated build files for $message project!" - exit 1 - fi - - # Build - if [ $__ConfigureOnly == 1 ]; then - echo "Finish configuration & skipping $message build." - return - fi - - # Check that the makefiles were created. - - if [ $__StaticAnalyzer == 1 ]; then - pushd "$intermediatesForBuild" - - buildTool="$SCAN_BUILD_COMMAND -o $__BinDir/scan-build-log $buildTool" - echo "Executing $buildTool install -j $__NumProc" - $buildTool install -j $__NumProc - - popd - else - echo "Executing cmake --build \"$intermediatesForBuild\" --target install -j $__NumProc" - - cmake --build "$intermediatesForBuild" --target install -j $__NumProc - fi - - local exit_code=$? - if [ $exit_code != 0 ]; then - echo "${__ErrMsgPrefix}Failed to build $message." - exit $exit_code - fi - -} - build_cross_architecture_components() { local intermediatesForBuild="$__IntermediatesDir/Host$__CrossArch/crossgen" @@ -270,8 +134,12 @@ build_cross_architecture_components() export __CMakeBinDir="$crossArchBinDir" export CROSSCOMPILE=0 - __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize -DCLR_CROSS_COMPONENTS_BUILD=1" - build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components" + __CMakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CROSS_COMPONENTS_BUILD=1 $__CMakeArgs" + if [ "$__SkipCrossArchBuild" = 1 ]; then + echo "Skipping cross-architecture components build." + else + build_native "$__CrossArch" "$__ProjectRoot" "$__ProjectRoot" "$intermediatesForBuild" "cross-architecture components" + fi export CROSSCOMPILE=1 } @@ -311,7 +179,7 @@ build_CoreLib_ni() build_CoreLib() { - if [ $__isMSBuildOnNETCoreSupported == 0 ]; then + if [ "$__IsMSBuildOnNETCoreSupported" = 0 ]; then echo "System.Private.CoreLib.dll build unsupported." return fi @@ -370,7 +238,7 @@ build_CoreLib() exit $exit_code fi - if [ "$__HostOS" == "OSX" ]; then + if [ "$__HostOS" = "OSX" ]; then cp "$__BinDir/libclrjit.dylib" "$__BinDir/crossgen2/libclrjitilc.dylib" cp "$__BinDir/libjitinterface.dylib" "$__BinDir/crossgen2/libjitinterface.dylib" else @@ -379,14 +247,14 @@ build_CoreLib() fi fi - local __CoreLibILDir=$__BinDir/IL + local __CoreLibILDir="$__BinDir"/IL - if [ $__SkipCrossgen == 1 ]; then + if [ "$__SkipCrossgen" = 1 ]; then echo "Skipping generating native image" - if [ $__CrossBuild == 1 ]; then + if [ "$__CrossBuild" = 1 ]; then # Crossgen not performed, so treat the IL version as the final version - cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll + cp "$__CoreLibILDir"/System.Private.CoreLib.dll "$__BinDir"/System.Private.CoreLib.dll fi return @@ -425,7 +293,7 @@ build_CoreLib() generate_NugetPackages() { # We can only generate nuget package if we also support building mscorlib as part of this build. - if [ $__isMSBuildOnNETCoreSupported == 0 ]; then + if [ "$__IsMSBuildOnNETCoreSupported" = 0 ]; then echo "Nuget package generation unsupported." return fi @@ -454,8 +322,8 @@ generate_NugetPackages() fi } -handle_arguments() { - case $1 in +handle_arguments_local() { + case "$1" in crossgenonly|-crossgenonly) __SkipMSCorLib=1 __SkipCoreCLR=1 @@ -472,7 +340,7 @@ handle_arguments() { ignorewarnings|-ignorewarnings) __IgnoreWarnings=1 - __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF" + __CMakeArgs="-DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF $__CMakeArgs" ;; nopgooptimize|-nopgooptimize) @@ -526,12 +394,8 @@ handle_arguments() { __StaticAnalyzer=1 ;; - stripsymbols|-stripsymbols) - __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true" - ;; - *) - __UnprocessedBuildArgs+=("$1") + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" ;; esac } @@ -553,7 +417,7 @@ __RepoRootDir="${__ProjectRoot}/../.." __BuildArch= __BuildType=Debug -__CodeCoverage= +__CodeCoverage=0 __IgnoreWarnings=0 # Set the various build properties here so that CMake and MSBuild can pick them up @@ -568,6 +432,7 @@ __CrossgenOnly=0 __DistroRid="" __IbcOptDataPath="" __IbcTuning="" +__IsMSBuildOnNETCoreSupported=0 __MSBCleanBuildArgs= __OfficialBuildIdArg="" __PartialNgen=0 @@ -595,8 +460,7 @@ __UnprocessedBuildArgs= __UseNinja=0 __VerboseBuild=0 __ValidateCrossArg=1 -__cmakeargs="" -__msbuildonunsupportedplatform=0 +__CMakeArgs="" source "$__ProjectRoot"/_build-commons.sh @@ -613,40 +477,21 @@ __BinDir="$__RootBinDir/bin/coreclr/$__BuildOS.$__BuildArch.$__BuildType" __PackagesBinDir="$__BinDir/.nuget" export __IntermediatesDir="$__RootBinDir/obj/coreclr/$__BuildOS.$__BuildArch.$__BuildType" export __ArtifactsIntermediatesDir="$__RepoRootDir/artifacts/obj/coreclr" -__isMSBuildOnNETCoreSupported=0 __CrossComponentBinDir="$__BinDir" __CrossArch="$__HostArch" -if [ $__CrossBuild == 1 ]; then +if [ "$__CrossBuild" = 1 ]; then __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch" fi __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log" -# Configure environment if we are doing a cross compile. -if [ $__CrossBuild == 1 ]; then - export CROSSCOMPILE=1 - if ! [[ -n "$ROOTFS_DIR" ]]; then - export ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__BuildArch" - fi -fi - -# init the target distro name -initTargetDistroRid - -if [ $__PortableBuild == 0 ]; then - __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false" -fi - -# Init if MSBuild for .NET Core is supported for this platform -isMSBuildOnNETCoreSupported - # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set. # This is needed by CLI to function. if [ -z "$HOME" ]; then if [ ! -d "$__ProjectDir/temp_home" ]; then mkdir temp_home fi - export HOME=$__ProjectDir/temp_home + export HOME="$__ProjectDir"/temp_home echo "HOME not defined; setting it to $HOME" fi @@ -655,7 +500,7 @@ fi export __CMakeBinDir="$__BinDir" # Make the directories necessary for build if they don't exist -setup_dirs +setup_dirs_local # Set up the directory for MSBuild debug logs. export MSBUILDDEBUGPATH="${__MsbuildDebugLogsDir}" @@ -670,13 +515,21 @@ restore_optdata generate_event_logging # Build the coreclr (native) components. -__ExtraCmakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize" +__CMakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize $__CMakeArgs" + +if [ "$__SkipConfigure" = 0 ] && [ "$__CodeCoverage" = 1 ]; then + __CMakeArgs="-DCLR_CMAKE_ENABLE_CODE_COVERAGE=1 $__CMakeArgs" +fi -build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component" +if [ "$__SkipCoreCLR" = 1 ]; then + echo "Skipping CoreCLR component build." +else + build_native "$__BuildArch" "$__ProjectRoot" "$__ProjectRoot" "$__IntermediatesDir" "CoreCLR component" +fi # Build cross-architecture components -if [ $__SkipCrossArchNative != 1 ]; then - if [[ $__CrossBuild == 1 ]]; then +if [ "$__SkipCrossArchNative" != 1 ]; then + if [ "$__CrossBuild" = 1 ]; then build_cross_architecture_components fi fi @@ -685,12 +538,12 @@ fi build_CoreLib -if [ $__CrossgenOnly == 1 ]; then +if [ "$__CrossgenOnly" = 1 ]; then build_CoreLib_ni "$__BinDir/crossgen" fi # Generate nuget packages -if [ $__SkipNuget != 1 ]; then +if [ "$__SkipNuget" != 1 ]; then generate_NugetPackages fi diff --git a/src/coreclr/configurecompiler.cmake b/src/coreclr/configurecompiler.cmake index aa37d103b70e5d..63f229a6504af4 100644 --- a/src/coreclr/configurecompiler.cmake +++ b/src/coreclr/configurecompiler.cmake @@ -8,194 +8,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) cmake_policy(SET CMP0083 NEW) -include(CheckPIESupported) include(CheckCXXCompilerFlag) - -# All code we build should be compiled as position independent -check_pie_supported(OUTPUT_VARIABLE PIE_SUPPORT_OUTPUT LANGUAGES CXX) -if(NOT MSVC AND NOT CMAKE_CXX_LINK_PIE_SUPPORTED) - message(WARNING "PIE is not supported at link time: ${PIE_SUPPORT_OUTPUT}.\n" - "PIE link options will not be passed to linker.") -endif() -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -#---------------------------------------- -# Detect and set platform variable names -# - for non-windows build platform & architecture is detected using inbuilt CMAKE variables and cross target component configure -# - for windows we use the passed in parameter to CMAKE to determine build arch -#---------------------------------------- -if(CMAKE_SYSTEM_NAME STREQUAL Linux) - set(CLR_CMAKE_PLATFORM_UNIX 1) - if(CLR_CROSS_COMPONENTS_BUILD) - # CMAKE_HOST_SYSTEM_PROCESSOR returns the value of `uname -p` on host. - if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL amd64) - if(CLR_CMAKE_TARGET_ARCH STREQUAL "arm" OR CLR_CMAKE_TARGET_ARCH STREQUAL "armel") - if(CMAKE_CROSSCOMPILING) - set(CLR_CMAKE_PLATFORM_UNIX_X86 1) - else() - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - endif() - else() - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - endif() - elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL i686) - set(CLR_CMAKE_PLATFORM_UNIX_X86 1) - else() - clr_unknown_arch() - endif() - else() - # CMAKE_SYSTEM_PROCESSOR returns the value of `uname -p` on target. - # For the AMD/Intel 64bit architecture two different strings are common. - # Linux and Darwin identify it as "x86_64" while FreeBSD and netbsd uses the - # "amd64" string. Accept either of the two here. - if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64) - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l) - set(CLR_CMAKE_PLATFORM_UNIX_ARM 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm) - set(CLR_CMAKE_PLATFORM_UNIX_ARM 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) - set(CLR_CMAKE_PLATFORM_UNIX_ARM64 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686) - set(CLR_CMAKE_PLATFORM_UNIX_X86 1) - else() - clr_unknown_arch() - endif() - endif() - set(CLR_CMAKE_PLATFORM_LINUX 1) - - # Detect Linux ID - set(LINUX_ID_FILE "/etc/os-release") - if(CMAKE_CROSSCOMPILING) - set(LINUX_ID_FILE "${CMAKE_SYSROOT}${LINUX_ID_FILE}") - endif() - - execute_process( - COMMAND bash -c "source ${LINUX_ID_FILE} && echo \$ID" - OUTPUT_VARIABLE CLR_CMAKE_LINUX_ID - OUTPUT_STRIP_TRAILING_WHITESPACE) - - if(DEFINED CLR_CMAKE_LINUX_ID) - if(CLR_CMAKE_LINUX_ID STREQUAL tizen) - set(CLR_CMAKE_TARGET_TIZEN_LINUX 1) - elseif(CLR_CMAKE_LINUX_ID STREQUAL alpine) - set(CLR_CMAKE_PLATFORM_ALPINE_LINUX 1) - endif() - endif(DEFINED CLR_CMAKE_LINUX_ID) -endif(CMAKE_SYSTEM_NAME STREQUAL Linux) - -if(CMAKE_SYSTEM_NAME STREQUAL Darwin) - set(CLR_CMAKE_PLATFORM_UNIX 1) - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - set(CLR_CMAKE_PLATFORM_DARWIN 1) - set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} -o -c ") -endif(CMAKE_SYSTEM_NAME STREQUAL Darwin) - -if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - set(CLR_CMAKE_PLATFORM_UNIX 1) - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - set(CLR_CMAKE_PLATFORM_FREEBSD 1) -endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - -if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD) - set(CLR_CMAKE_PLATFORM_UNIX 1) - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - set(CLR_CMAKE_PLATFORM_OPENBSD 1) -endif(CMAKE_SYSTEM_NAME STREQUAL OpenBSD) - -if(CMAKE_SYSTEM_NAME STREQUAL NetBSD) - set(CLR_CMAKE_PLATFORM_UNIX 1) - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - set(CLR_CMAKE_PLATFORM_NETBSD 1) -endif(CMAKE_SYSTEM_NAME STREQUAL NetBSD) - -if(CMAKE_SYSTEM_NAME STREQUAL SunOS) - set(CLR_CMAKE_PLATFORM_UNIX 1) - EXECUTE_PROCESS( - COMMAND isainfo -n - OUTPUT_VARIABLE SUNOS_NATIVE_INSTRUCTION_SET - ) - if(SUNOS_NATIVE_INSTRUCTION_SET MATCHES "amd64") - set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1) - set(CMAKE_SYSTEM_PROCESSOR "amd64") - else() - clr_unknown_arch() - endif() - set(CLR_CMAKE_PLATFORM_SUNOS 1) -endif(CMAKE_SYSTEM_NAME STREQUAL SunOS) - +include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake) # "configureoptimization.cmake" must be included after CLR_CMAKE_PLATFORM_UNIX has been set. include(${CMAKE_CURRENT_LIST_DIR}/configureoptimization.cmake) -#-------------------------------------------- -# This repo builds two set of binaries -# 1. binaries which execute on target arch machine -# - for such binaries host architecture & target architecture are same -# - eg. coreclr.dll -# 2. binaries which execute on host machine but target another architecture -# - host architecture is different from target architecture -# - eg. crossgen.exe - runs on x64 machine and generates nis targeting arm64 -# - for complete list of such binaries refer to file crosscomponents.cmake -#------------------------------------------------------------- -# Set HOST architecture variables -if(CLR_CMAKE_PLATFORM_UNIX_ARM) - set(CLR_CMAKE_PLATFORM_ARCH_ARM 1) - set(CLR_CMAKE_HOST_ARCH "arm") -elseif(CLR_CMAKE_PLATFORM_UNIX_ARM64) - set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1) - set(CLR_CMAKE_HOST_ARCH "arm64") -elseif(CLR_CMAKE_PLATFORM_UNIX_AMD64) - set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1) - set(CLR_CMAKE_HOST_ARCH "x64") -elseif(CLR_CMAKE_PLATFORM_UNIX_X86) - set(CLR_CMAKE_PLATFORM_ARCH_I386 1) - set(CLR_CMAKE_HOST_ARCH "x86") -elseif(WIN32) - # CLR_CMAKE_HOST_ARCH is passed in as param to cmake - if (CLR_CMAKE_HOST_ARCH STREQUAL x64) - set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1) - elseif(CLR_CMAKE_HOST_ARCH STREQUAL x86) - set(CLR_CMAKE_PLATFORM_ARCH_I386 1) - elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm) - set(CLR_CMAKE_PLATFORM_ARCH_ARM 1) - elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64) - set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1) - else() - clr_unknown_arch() - endif() -endif() - -# Set TARGET architecture variables -# Target arch will be a cmake param (optional) for both windows as well as non-windows build -# if target arch is not specified then host & target are same -if(NOT DEFINED CLR_CMAKE_TARGET_ARCH OR CLR_CMAKE_TARGET_ARCH STREQUAL "" ) - set(CLR_CMAKE_TARGET_ARCH ${CLR_CMAKE_HOST_ARCH}) -endif() - -# Set target architecture variables -if (CLR_CMAKE_TARGET_ARCH STREQUAL x64) - set(CLR_CMAKE_TARGET_ARCH_AMD64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) - set(CLR_CMAKE_TARGET_ARCH_I386 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64) - set(CLR_CMAKE_TARGET_ARCH_ARM64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm) - set(CLR_CMAKE_TARGET_ARCH_ARM 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armel) - set(CLR_CMAKE_TARGET_ARCH_ARM 1) - set(ARM_SOFTFP 1) - else() - clr_unknown_arch() -endif() - -# check if host & target arch combination are valid -if(NOT(CLR_CMAKE_TARGET_ARCH STREQUAL CLR_CMAKE_HOST_ARCH)) - if(NOT((CLR_CMAKE_PLATFORM_ARCH_AMD64 AND CLR_CMAKE_TARGET_ARCH_ARM64) OR (CLR_CMAKE_PLATFORM_ARCH_I386 AND CLR_CMAKE_TARGET_ARCH_ARM) OR (CLR_CMAKE_PLATFORM_ARCH_AMD64 AND CLR_CMAKE_TARGET_ARCH_ARM))) - message(FATAL_ERROR "Invalid host and target arch combination") - endif() -endif() - #----------------------------------------------------- # Initialize Cmake compiler flags and other variables #----------------------------------------------------- @@ -645,4 +463,4 @@ endif(CLR_CMAKE_ENABLE_CODE_COVERAGE) if (CMAKE_BUILD_TOOL STREQUAL nmake) set(CMAKE_RC_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}") -endif(CMAKE_BUILD_TOOL STREQUAL nmake) \ No newline at end of file +endif(CMAKE_BUILD_TOOL STREQUAL nmake) diff --git a/src/coreclr/tests/setup-stress-dependencies.sh b/src/coreclr/tests/setup-stress-dependencies.sh index 9ab4170e3fa38c..8141123fc63dd1 100755 --- a/src/coreclr/tests/setup-stress-dependencies.sh +++ b/src/coreclr/tests/setup-stress-dependencies.sh @@ -104,7 +104,7 @@ fi # Use uname to determine what the OS is. OSName=$(uname -s) -case $OSName in +case "$OSName" in Linux) __BuildOS=Linux __HostOS=Linux @@ -144,8 +144,8 @@ esac isPortable=0 -source "${scriptDir}"/../init-distro-rid.sh -initDistroRidGlobal ${__BuildOS} x64 ${isPortable} +source "${scriptDir}"/../../../eng/native/init-distro-rid.sh +initDistroRidGlobal "$__BuildOS" x64 "$isPortable" # Hack, replace the rid to ubuntu.14.04 which has a valid non-portable # package. @@ -153,22 +153,22 @@ initDistroRidGlobal ${__BuildOS} x64 ${isPortable} # The CoreDisTools package is currently manually packaged and we only have # 14.04 and 16.04 packages. Use the oldest package which will work on newer # platforms. -if [[ ${__BuildOS} == "Linux" ]]; then - if [[ ${__BuildArch} == "x64" ]]; then +if [ "$__BuildOS" = "Linux" ]; then + if [ "$__BuildArch" = "x64" ]; then __DistroRid=ubuntu.14.04-x64 - elif [[ ${__BuildArch} == "x86" ]]; then + elif [ "$__BuildArch" = "x86" ]; then __DistroRid=ubuntu.14.04-x86 fi fi # Query runtime Id -rid=${__DistroRid} +rid="$__DistroRid" echo "Rid to be used: ${rid}" if [ -z "$rid" ]; then exit_with_error 1 "Failed to query runtime Id" -fi +fi # Download the package echo Downloading CoreDisTools package diff --git a/src/installer/corehost/CMakeLists.txt b/src/installer/corehost/CMakeLists.txt index eccefce32ad0a3..ca3a9bed66b25a 100644 --- a/src/installer/corehost/CMakeLists.txt +++ b/src/installer/corehost/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.14.2) project(corehost) +include(${CLR_ENG_NATIVE_DIR}/functions.cmake) +include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) +include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake) include(../settings.cmake) include(../functions.cmake) add_subdirectory(cli) diff --git a/src/installer/corehost/Windows/gen-buildsys-win.bat b/src/installer/corehost/Windows/gen-buildsys-win.bat index d2404e5797a0b4..e5935d75901331 100644 --- a/src/installer/corehost/Windows/gen-buildsys-win.bat +++ b/src/installer/corehost/Windows/gen-buildsys-win.bat @@ -16,11 +16,11 @@ set __VSString=%__VSString:"=% set __ExtraCmakeParams= :: Set the target architecture to a format cmake understands. ANYCPU defaults to x64 -set __RIDArch=%3 -if /i "%3" == "x64" (set cm_BaseRid=win7&&set cm_Arch=AMD64&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A x64) -if /i "%3" == "x86" (set cm_BaseRid=win7&&set cm_Arch=I386&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A Win32) -if /i "%3" == "arm" (set cm_BaseRid=win8&&set cm_Arch=ARM&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM) -if /i "%3" == "arm64" (set cm_BaseRid=win10&&set cm_Arch=ARM64&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM64) +set __Arch=%3 +if /i "%__Arch%" == "x64" (set cm_BaseRid=win7&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A x64) +if /i "%__Arch%" == "x86" (set cm_BaseRid=win7&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A Win32) +if /i "%__Arch%" == "arm" (set cm_BaseRid=win8&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM) +if /i "%__Arch%" == "arm64" (set cm_BaseRid=win10&&set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM64) set __LatestCommit=%4 set __HostVersion=%5 @@ -30,7 +30,7 @@ set __HostPolicyVersion=%8 :: Form the base RID to be used if we are doing a portable build if /i "%9" == "1" (set cm_BaseRid=win) -set cm_BaseRid=%cm_BaseRid%-%__RIDArch% +set cm_BaseRid=%cm_BaseRid%-%__Arch% echo "Computed RID for native build is %cm_BaseRid%" if defined CMakePath goto DoGen @@ -41,8 +41,12 @@ for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& .\Win popd :DoGen -echo "%CMakePath%" %__sourceDir% "-DCMAKE_SYSTEM_VERSION=10.0" "-DCLI_CMAKE_HOST_VER=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER=%__HostFxrVersion%" "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH=%__LatestCommit%" "-DCLI_CMAKE_PLATFORM_ARCH_%cm_Arch%=1" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR=%__ResourcesDir%" -G "Visual Studio %__VSString%" %__ExtraCmakeParams% -"%CMakePath%" %__sourceDir% "-DCMAKE_SYSTEM_VERSION=10.0" "-DCLI_CMAKE_HOST_VER=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER=%__HostFxrVersion%" "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH=%__LatestCommit%" "-DCLI_CMAKE_PLATFORM_ARCH_%cm_Arch%=1" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR=%__ResourcesDir%" -G "Visual Studio %__VSString%" %__ExtraCmakeParams% +set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0" "-DCLI_CMAKE_HOST_VER=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER=%__HostFxrVersion%" +set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH=%__LatestCommit%" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" +set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR=%__ResourcesDir%" "-DCLR_ENG_NATIVE_DIR="%__sourceDir%\..\..\..\eng\native" + +echo "%CMakePath%" %__sourceDir% -G "Visual Studio %__VSString%" %__ExtraCmakeParams% +"%CMakePath%" %__sourceDir% -G "Visual Studio %__VSString%" %__ExtraCmakeParams% endlocal GOTO :DONE diff --git a/src/installer/corehost/build.proj b/src/installer/corehost/build.proj index a666f704f85644..12c6909e73f23e 100644 --- a/src/installer/corehost/build.proj +++ b/src/installer/corehost/build.proj @@ -27,11 +27,10 @@ $(IntermediateOutputRootPath)corehost\cmake\ - --configuration $(ConfigurationGroup) --arch $(TargetArchitecture) --apphostver $(AppHostVersion) --hostver $(HostVersion) --fxrver $(HostResolverVersion) --policyver $(HostPolicyVersion) --commithash $(LatestCommit) - $(BuildArgs) -portable - $(BuildArgs) --cross - $(BuildArgs) --stripsymbols - $(BuildArgs) --rootdir $(RepoRoot) + $(ConfigurationGroup) $(TargetArchitecture) -apphostver "$(AppHostVersion)" -hostver "$(HostVersion)" -fxrver "$(HostResolverVersion)" -policyver "$(HostPolicyVersion)" -commithash "$(LatestCommit)" + $(BuildArgs) -portablebuild=false + $(BuildArgs) -cross + $(BuildArgs) -stripsymbols - + - - $(ArtifactsObjDir)_version.h - $(ArtifactsObjDir)_version.c - <_BuildNativeArgs>$(ArchGroup) $(ConfigurationGroup) $(OSGroup) outconfig $(Configuration) + <_BuildNativeArgs>$(ArchGroup) $(ConfigurationGroup) outconfig $(Configuration) - <_ProcessorCountArg> --numproc $(MSBuildNodeCount) - <_StripSymbolsArg Condition="'$(BuildNativeStripSymbols)' == 'true' and '$(OSGroup)' != 'WebAssembly'"> stripsymbols - <_PortableBuildArg Condition="'$(PortableBuild)' == 'true'"> -portable + <_ProcessorCountArg> -numproc $(MSBuildNodeCount) + <_StripSymbolsArg Condition="'$(BuildNativeStripSymbols)' == 'true' and '$(OSGroup)' != 'WebAssembly'"> -stripsymbols + <_PortableBuildArg Condition="'$(PortableBuild)' != 'true'"> -portablebuild=false + <_CrossBuildArg Condition="'$(CrossBuild)' == 'true'"> -cross <_BuildNativeCompilerArg Condition="'$(BuildNativeCompiler)' != ''"> $(BuildNativeCompiler) - - <_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessCountArg)$(_StripSymbolsArg)$(_PortableBuildArg)$(_BuildNativeCompilerArg) + <_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessCountArg)$(_StripSymbolsArg)$(_PortableBuildArg)$(_CrossBuildArg)$(_BuildNativeCompilerArg) @@ -41,10 +38,6 @@ - - <_BuildNativeWindowsArgs>$(_BuildNativeArgs) - - diff --git a/src/libraries/Native/build-native.sh b/src/libraries/Native/build-native.sh index 5247d468b3841f..4ed90f5c4212a8 100755 --- a/src/libraries/Native/build-native.sh +++ b/src/libraries/Native/build-native.sh @@ -1,398 +1,88 @@ #!/usr/bin/env bash -usage() -{ - echo "Our parameters changed! The parameters: buildArch, buildType, buildOS, numProc" - echo "are passed by the Run Command Tool." - echo "If you plan to only run this script, be sure to pass those parameters." - echo "For more information type build-native.sh -? at the root of the repo." - echo - echo "Usage: $0 [runParameters][-verbose] [-clangx.y] [-gccx.y] [-cross] [-staticLibLink] [-cmakeargs] [-makeargs]" - echo "runParameters: buildArch, buildType, buildOS, -numProc " - echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64" - echo "BuildType can be: -debug, -checked, -release" - echo "-verbose - optional argument to enable verbose build output." - echo "-clangx.y - optional argument to build using clang version x.y." - echo "-gccx.y - optional argument to build using gcc version x.y." - echo "-cross - optional argument to signify cross compilation," - echo " - will use ROOTFS_DIR environment variable if set." - echo "-staticLibLink - Optional argument to statically link any native library." - echo "-portable - Optional argument to build native libraries portable over GLIBC based Linux distros." - echo "-stripSymbols - Optional argument to strip native symbols during the build." - echo "-skipgenerateversion - Pass this in to skip getting a version on the build output." - echo "-cmakeargs - user-settable additional arguments passed to CMake." - exit 1 -} - -__scriptpath=$(cd "$(dirname "$0")"; pwd -P) -__nativeroot=$__scriptpath/Unix -__rootRepo=$(cd "$__scriptpath/../../.."; pwd -P) -__artifactsDir="$__rootRepo/artifacts" - -initHostDistroRid() -{ - __HostDistroRid="" - if [ "$__HostOS" == "Linux" ]; then - if [ -e /etc/os-release ]; then - source /etc/os-release - if [[ $ID == "alpine" ]]; then - # remove the last version digit - VERSION_ID=${VERSION_ID%.*} - fi - __HostDistroRid="$ID.$VERSION_ID-$__HostArch" - fi - elif [ "$__HostOS" == "OSX" ]; then - _osx_version=`sw_vers -productVersion | cut -f1-2 -d'.'` - __HostDistroRid="osx.$_osx_version-x64" - elif [ "$__HostOS" == "FreeBSD" ]; then - __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'-'` - __HostDistroRid="freebsd.$__freebsd_version-x64" - fi - - - if [ "$__HostDistroRid" == "" ]; then - echo "WARNING: Can not determine runtime id for current distro." - fi -} - -initTargetDistroRid() -{ - if [ $__CrossBuild == 1 ]; then - if [ "$__BuildOS" == "Linux" ]; then - if [ ! -e $ROOTFS_DIR/etc/os-release ]; then - echo "WARNING: Can not determine runtime id for current distro." - export __DistroRid="" - else - source $ROOTFS_DIR/etc/os-release - export __DistroRid="$ID.$VERSION_ID-$__BuildArch" - fi - fi - else - export __DistroRid="$__HostDistroRid" - fi -} - -setup_dirs() -{ - echo Setting up directories for build - - mkdir -p "$__BinDir" - mkdir -p "$__IntermediatesDir" -} - -# Check the system to ensure the right pre-reqs are in place -check_native_prereqs() -{ - echo "Checking pre-requisites..." - - # Check presence of CMake on the path - hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; } -} - -prepare_native_build() -{ - # Specify path to be set for CMAKE_INSTALL_PREFIX. - # This is where all built CoreClr libraries will copied to. - export __CMakeBinDir="$__BinDir" - - # Configure environment if we are doing a verbose build - if [ $__VerboseBuild == 1 ]; then - export VERBOSE=1 - fi - - # Generate version.c if specified, else have an empty one. - __versionSourceFile=$__artifactsDir/obj/_version.c - if [ ! -e "${__versionSourceFile}" ]; then - __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";" - echo "${__versionSourceLine}" > ${__versionSourceFile} - fi -} - -build_native() -{ - # All set to commence the build - - echo "Commencing build of corefx native components for $__BuildOS.$__BuildArch.$__BuildType" - cd "$__IntermediatesDir" - - if [ "$__BuildArch" == "wasm" ]; then - if [ "$EMSDK_PATH" == "" ]; then - echo "Error: Should set EMSDK_PATH environment variable pointing to emsdk root." - exit 1 - fi - source $EMSDK_PATH/emsdk_env.sh - fi - - # Regenerate the CMake solution - engNativeDir="$__rootRepo/eng/native" - __CMakeExtraArgs="$__CMakeExtraArgs -DCLR_ENG_NATIVE_DIR=\"$engNativeDir\"" - nextCommand="\"$engNativeDir/gen-buildsys.sh\" \"$__nativeroot\" \"$__nativeroot\" \"$__IntermediatesDir\" $__BuildArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType $__CMakeArgs $__CMakeExtraArgs" - echo "Invoking $nextCommand" - eval "$nextCommand" +usage_list=("-outconfig: Configuration, typically a quadruplet such as 'netcoreapp5.0-Linux-Release-x64', used to name output directory.") +usage_list+=("-staticLibLink: Optional argument to statically link any native library.") - if [ $? != 0 ]; then - echo "Failed to generate $message build project!" - exit 1 - fi +__scriptpath="$(cd "$(dirname "$0")"; pwd -P)" +__nativeroot="$__scriptpath"/Unix +__RepoRootDir="$(cd "$__scriptpath"/../../..; pwd -P)" +__artifactsDir="$__RepoRootDir/artifacts" - # Check that the makefiles were created. +handle_arguments() { - if [ ! -f "$__IntermediatesDir/CMakeCache.txt" ]; then - echo "Unable to find generated build files for native component project!" - exit 1 - fi - - # Build + case "$1" in + outconfig|-outconfig) + __outConfig="$2" + __ShiftArgs=1 + ;; - echo "Executing make install -j $__NumProc $__MakeExtraArgs" + staticliblink|-staticliblink) + __StaticLibLink=1 + ;; - make install -j $__NumProc $__MakeExtraArgs - if [ $? != 0 ]; then - echo "Failed to build corefx native components." - exit 1 - fi + *) + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" + esac } # Set the various build properties here so that CMake and MSBuild can pick them up -__CMakeExtraArgs="" -__MakeExtraArgs="" __BuildArch=x64 -__BuildType=Debug -__CMakeArgs=DEBUG __BuildOS=Linux -__NumProc=1 -__UnprocessedBuildArgs= -__CrossBuild=0 -__ServerGC=0 -__VerboseBuild=false +__BuildType=Debug +__CMakeArgs="" __Compiler=clang __CompilerMajorVersion= __CompilerMinorVersion= +__CrossBuild=0 +__IsMSBuildOnNETCoreSupported=0 +__NumProc=1 +__PortableBuild=1 +__RootBinDir="$__RepoRootDir/artifacts" +__SkipConfigure=0 +__SkipGenerateVersion=0 __StaticLibLink=0 -__PortableBuild=0 - -CPUName=$(uname -m) -if [ "$CPUName" == "i686" ]; then - __BuildArch=x86 -fi - -# Use uname to determine what the OS is. -OSName=$(uname -s) -case $OSName in - Linux) - __BuildOS=Linux - __HostOS=Linux - ;; - - Darwin) - __BuildOS=OSX - __HostOS=OSX - ;; - - FreeBSD) - __BuildOS=FreeBSD - __HostOS=FreeBSD - ;; - - OpenBSD) - __BuildOS=OpenBSD - __HostOS=OpenBSD - ;; - - NetBSD) - __BuildOS=NetBSD - __HostOS=NetBSD - ;; - - SunOS) - __BuildOS=SunOS - __HostOS=SunOS - ;; - - *) - echo "Unsupported OS $OSName detected, configuring as if for Linux" - __BuildOS=Linux - __HostOS=Linux - ;; -esac - -while :; do - if [ $# -le 0 ]; then - break - fi - - lowerI="$(echo $1 | awk '{print tolower($0)}')" - case $lowerI in - -\?|-h|--help) - usage - exit 1 - ;; - x86|-x86) - __BuildArch=x86 - ;; - x64|-x64) - __BuildArch=x64 - ;; - arm|-arm) - __BuildArch=arm - ;; - armel|-armel) - __BuildArch=armel - ;; - arm64|-arm64) - __BuildArch=arm64 - ;; - wasm|-wasm) - __BuildArch=wasm - ;; - debug|-debug) - __BuildType=Debug - ;; - release|-release) - __BuildType=Release - __CMakeArgs=RELEASE - ;; - outconfig|-outconfig) - __outConfig=$2 - shift - ;; - freebsd|FreeBSD|-freebsd|-FreeBSD) - __BuildOS=FreeBSD - ;; - linux|-linux) - __BuildOS=Linux - ;; - netbsd|-netbsd) - __BuildOS=NetBSD - ;; - osx|-osx) - __BuildOS=OSX - ;; - stripsymbols|-stripsymbols) - __CMakeExtraArgs="$__CMakeExtraArgs -DSTRIP_SYMBOLS=true" - ;; - numproc|-numproc|--numproc) - shift - __NumProc=$1 - ;; - verbose|-verbose) - __VerboseBuild=1 - ;; - staticliblink|-staticliblink) - __StaticLibLink=1 - ;; - portable|-portable) - # Portable native components are only supported on Linux - if [ "$__HostOS" == "Linux" ]; then - __PortableBuild=1 - fi - ;; - clang*|-clang*|--clang*) - __Compiler=clang - # clangx.y or clang-x.y - version="$(echo "$lowerI" | tr -d '[:alpha:]-=')" - parts=(${version//./ }) - __CompilerMajorVersion="${parts[0]}" - __CompilerMinorVersion="${parts[1]}" - if [ -z "$__CompilerMinorVersion" ] && [ "$__CompilerMajorVersion" -le 6 ]; then - __CompilerMinorVersion=0; - fi - ;; - gcc*|-gcc*) - __Compiler=gcc - # gccx.y or gcc-x.y - version="$(echo "$lowerI" | tr -d '[:alpha:]-=')" - parts=(${version//./ }) - __CompilerMajorVersion="${parts[0]}" - __CompilerMinorVersion="${parts[1]}" - ;; - cross|-cross) - __CrossBuild=1 - ;; - cmakeargs|-cmakeargs) - if [ -n "$2" ]; then - __CMakeExtraArgs="$__CMakeExtraArgs $2" - shift - else - echo "ERROR: 'cmakeargs' requires a non-empty option argument" - exit 1 - fi - ;; - makeargs|-makeargs) - if [ -n "$2" ]; then - __MakeExtraArgs="$__MakeExtraArgs $2" - shift - else - echo "ERROR: 'makeargs' requires a non-empty option argument" - exit 1 - fi - ;; - useservergc|-useservergc) - __ServerGC=1 - ;; - *) - __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" - esac +__UnprocessedBuildArgs= +__VerboseBuild=false - shift -done +source "$__RepoRootDir"/eng/native/build-commons.sh # Set cross build -if [ $__BuildArch != wasm ]; then - __CMakeExtraArgs="$__CMakeExtraArgs -DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild" - __CMakeExtraArgs="$__CMakeExtraArgs -DCMAKE_STATIC_LIB_LINK=$__StaticLibLink" +if [ "$__BuildArch" != wasm ]; then + __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs" + __CMakeArgs="-DCMAKE_STATIC_LIB_LINK=$__StaticLibLink $__CMakeArgs" - case $CPUName in - i686) - if [ $__BuildArch != x86 ]; then - __CrossBuild=1 - echo "Set CrossBuild for $__BuildArch build" - fi - ;; - x86_64) - if [ $__BuildArch != x64 ]; then - __CrossBuild=1 - echo "Set CrossBuild for $__BuildArch build" - fi - ;; - esac + if [ "$__BuildArch" != x86 ] && [ "$__BuildArch" != x64 ]; then + __CrossBuild=1 + echo "Set CrossBuild for $__BuildArch build" + fi +else + if [ -z "$EMSDK_PATH" ]; then + echo "Error: Should set EMSDK_PATH environment variable pointing to emsdk root." + exit 1 + fi + source "$EMSDK_PATH"/emsdk_env.sh fi # set default OSX deployment target -if [[ $__BuildOS == OSX ]]; then - __CMakeExtraArgs="$__CMakeExtraArgs -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13" +if [ "$__BuildOS" = OSX ]; then + __CMakeArgs="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 $__CMakeArgs" fi # Set the remaining variables based upon the determined build configuration -__outConfig=${__outConfig:-"$__BuildOS-$__BuildArch-$__BuildType"} -__IntermediatesDir="$__artifactsDir/obj/native/$__outConfig" -__BinDir="$__artifactsDir/bin/native/$__outConfig" +__outConfig="${__outConfig:-"$__BuildOS-$__BuildArch-$__BuildType"}" +__IntermediatesDir="$__RootBinDir/obj/native/$__outConfig" +__BinDir="$__RootBinDir/bin/native/$__outConfig" + +# Specify path to be set for CMAKE_INSTALL_PREFIX. +# This is where all built CoreClr libraries will copied to. +__CMakeBinDir="$__BinDir" +export __CMakeBinDir # Make the directories necessary for build if they don't exist setup_dirs -# Configure environment if we are doing a cross compile. -if [ "$__CrossBuild" == 1 ]; then - export CROSSCOMPILE=1 - if ! [[ -n "$ROOTFS_DIR" ]]; then - export ROOTFS_DIR="$__rootRepo/.tools/rootfs/$__BuildArch" - fi -fi - -# init the host distro name -initHostDistroRid - -# init the target distro name -initTargetDistroRid - - # Check prereqs. - - check_native_prereqs - - # Prepare the system - - prepare_native_build - - # Build the corefx native components. +# Check prereqs. +check_prereqs - build_native +# Build the corefx native components. +build_native "$__BuildArch" "$__nativeroot" "$__nativeroot" "$__IntermediatesDir" "native libraries component" From 28fd654b1962ac41eb191ecf50d207ba9e66371b Mon Sep 17 00:00:00 2001 From: Adeel Date: Mon, 20 Jan 2020 17:13:50 +0000 Subject: [PATCH 2/4] Use if [[ cond ]] in all places --- eng/native/build-commons.sh | 70 ++++----- eng/native/gen-buildsys.sh | 41 +++--- src/coreclr/build-test.sh | 209 ++++++++++++++------------- src/coreclr/build.sh | 156 ++++++++++---------- src/installer/corehost/build.sh | 2 +- src/libraries/Native/build-native.sh | 8 +- 6 files changed, 244 insertions(+), 242 deletions(-) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 63a6e6e8028f53..4728876c0db997 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -7,7 +7,7 @@ initTargetDistroRid() local passedRootfsDir="" # Only pass ROOTFS_DIR if cross is specified. - if [ "$__CrossBuild" = 1 ]; then + if [[ "$__CrossBuild" == 1 ]]; then passedRootfsDir="$ROOTFS_DIR" fi @@ -18,18 +18,18 @@ isMSBuildOnNETCoreSupported() { __IsMSBuildOnNETCoreSupported="$__msbuildonunsupportedplatform" - if [ "$__IsMSBuildOnNETCoreSupported" = 1 ]; then + if [[ "$__IsMSBuildOnNETCoreSupported" == 1 ]]; then return fi - if [ "$__SkipManaged" = 1 ]; then + if [[ "$__SkipManaged" == 1 ]]; then __IsMSBuildOnNETCoreSupported=0 return fi - if [ "$__HostOS" = "Linux" ] && { [ "$__HostArch" = "x64" ] || [ "$__HostArch" = "arm" ] || [ "$__HostArch" = "arm64" ]; }; then + if [[ ( "$__HostOS" == "Linux" ) && ( "$__HostArch" == "x64" || "$__HostArch" == "arm" || "$__HostArch" == "arm64" ) ]]; then __IsMSBuildOnNETCoreSupported=1 - elif [ "$__HostArch" = "x64" ] && { [ "$__HostOS" = "OSX" ] || [ "$__HostOS" = "FreeBSD" ]; }; then + elif [[ "$__HostArch" == "x64" && ( "$__HostOS" == "OSX" || "$__HostOS" == "FreeBSD" ) ]]; then __IsMSBuildOnNETCoreSupported=1 fi } @@ -55,11 +55,11 @@ check_prereqs() local cmake_version="$(cmake --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")" - if [ $(version "$cmake_version") -lt "$(version 3.14.2)" ]; then + if [[ "$(version "$cmake_version")" -lt "$(version 3.14.2)" ]]; then echo "Please install CMake 3.14.2 or newer from http://www.cmake.org/download/ or https://apt.kitware.com and ensure it is on your path."; exit 1; fi - if [ "$__UseNinja" = 1 ]; then + if [[ "$__UseNinja" == 1 ]]; then command -v ninja 2>/dev/null || command -v ninja-build 2>/dev/null || { echo "Unable to locate ninja!"; exit 1; } fi } @@ -75,40 +75,40 @@ build_native() # All set to commence the build echo "Commencing build of \"$message\" for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesDir" - if [ "$__UseNinja" = 1 ]; then + if [[ "$__UseNinja" == 1 ]]; then generator="ninja" buildTool="$(command -v ninja || command -v ninja-build)" else buildTool="make" fi - if [ "$__SkipConfigure" = 0 ]; then + if [[ "$__SkipConfigure" == 0 ]]; then # if msbuild is not supported, then set __SkipGenerateVersion to 1 - if [ "$__IsMSBuildOnNETCoreSupported" = 0 ]; then __SkipGenerateVersion=1; fi + if [[ "$__IsMSBuildOnNETCoreSupported" == 0 ]]; then __SkipGenerateVersion=1; fi # Drop version.c file __versionSourceFile="$intermediatesDir/version.c" - if [ "$__SkipGenerateVersion" = 0 ]; then + if [[ "$__SkipGenerateVersion" == 0 ]]; then "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary "$__ArcadeScriptArgs" "$__RepoRootDir"/eng/empty.csproj \ /p:NativeVersionFile="$__versionSourceFile" \ /t:GenerateNativeVersionFile /restore \ $__CommonMSBuildArgs $__UnprocessedBuildArgs local exit_code="$?" - if [ "$exit_code" != 0 ]; then + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to generate native version file." exit "$exit_code" fi else # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";" - if [ -e "$__versionSourceFile" ]; then + if [[ -e "$__versionSourceFile" ]]; then read existingVersionSourceLine < "$__versionSourceFile" fi - if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then + if [[ "$__versionSourceLine" != "$existingVersionSourceLine" ]]; then echo "$__versionSourceLine" > "$__versionSourceFile" fi fi - if [ "$__StaticAnalyzer" = 1 ]; then + if [[ "$__StaticAnalyzer" == 1 ]]; then scan_build=scan-build fi @@ -119,25 +119,25 @@ build_native() eval $nextCommand local exit_code="$?" - if [ "$exit_code" != 0 ]; then + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to generate \"$message\" build project!" exit "$exit_code" fi fi # Check that the makefiles were created. - if [ ! -f "$intermediatesDir/CMakeCache.txt" ]; then + if [[ ! -f "$intermediatesDir/CMakeCache.txt" ]]; then echo "${__ErrMsgPrefix}Unable to find generated build files for \"$message\" project!" exit 1 fi # Build - if [ "$__ConfigureOnly" = 1 ]; then + if [[ "$__ConfigureOnly" == 1 ]]; then echo "Finish configuration & skipping \"$message\" build." return fi - if [ "$__StaticAnalyzer" = 1 ]; then + if [[ "$__StaticAnalyzer" == 1 ]]; then pushd "$intermediatesDir" buildTool="$SCAN_BUILD_COMMAND -o $__BinDir/scan-build-log $buildTool" @@ -151,7 +151,7 @@ build_native() fi local exit_code="$?" - if [ "$exit_code" != 0 ]; then + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to build \"$message\"." exit "$exit_code" fi @@ -197,7 +197,7 @@ usage() CPUName=$(uname -p) # Some Linux platforms report unknown for platform, but the arch for machine. -if [ "$CPUName" = "unknown" ]; then +if [[ "$CPUName" == "unknown" ]]; then CPUName=$(uname -m) fi @@ -279,7 +279,7 @@ esac __msbuildonunsupportedplatform=0 while :; do - if [ "$#" -le 0 ]; then + if [[ "$#" -le 0 ]]; then break fi @@ -303,9 +303,9 @@ while :; do ;; bindir|-bindir) - if [ -n "$2" ]; then + if [[ -n "$2" ]]; then __RootBinDir="$2" - if [ ! -d "$__RootBinDir" ]; then + if [[ ! -d "$__RootBinDir" ]]; then mkdir "$__RootBinDir" fi __RootBinParent=$(dirname "$__RootBinDir") @@ -334,13 +334,13 @@ while :; do parts=(${version//./ }) __CompilerMajorVersion="${parts[0]}" __CompilerMinorVersion="${parts[1]}" - if [ -z "$__CompilerMinorVersion" ] && [ "$__CompilerMajorVersion" -le 6 ]; then + if [[ -z "$__CompilerMinorVersion" && "$__CompilerMajorVersion" -le 6 ]]; then __CompilerMinorVersion=0; fi ;; cmakeargs|-cmakeargs) - if [ -n "$2" ]; then + if [[ -n "$2" ]]; then __CMakeArgs="$2 $__CMakeArgs" shift else @@ -381,7 +381,7 @@ while :; do ;; numproc|-numproc) - if [ -n "$2" ]; then + if [[ -n "$2" ]]; then __NumProc="$2" shift else @@ -428,7 +428,7 @@ while :; do *) handle_arguments "$1" "$2" - if [ "$__ShiftArgs" = 1 ]; then + if [[ "$__ShiftArgs" == 1 ]]; then shift __ShiftArgs=0 fi @@ -442,11 +442,11 @@ done # Other techniques such as `nproc` only get the number of # processors available to a single process. platform=$(uname) -if [ "$platform" = "FreeBSD" ]; then +if [[ "$platform" == "FreeBSD" ]]; then __NumProc=$(sysctl hw.ncpu | awk '{ print $2+1 }') -elif [ "$platform" = "NetBSD" ]; then +elif [[ "$platform" == "NetBSD" ]]; then __NumProc=$(($(getconf NPROCESSORS_ONLN)+1)) -elif [ "$platform" = "Darwin" ]; then +elif [[ "$platform" == "Darwin" ]]; then __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1)) else __NumProc=$(nproc --all) @@ -455,19 +455,19 @@ fi __CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg" # Configure environment if we are doing a verbose build -if [ "$__VerboseBuild" = 1 ]; then +if [[ "$__VerboseBuild" == 1 ]]; then export VERBOSE=1 __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed" fi -if [ "$__PortableBuild" = 0 ]; then +if [[ "$__PortableBuild" == 0 ]]; then __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false" fi # Configure environment if we are doing a cross compile. -if [ "$__CrossBuild" = 1 ]; then +if [[ "$__CrossBuild" == 1 ]]; then export CROSSCOMPILE=1 - if [ ! -n "$ROOTFS_DIR" ]; then + if [[ ! -n "$ROOTFS_DIR" ]]; then export ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__BuildArch" fi fi diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index beb910087f5bc0..ae2e0eb2d0bd5c 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -5,8 +5,7 @@ scriptroot="$( cd -P "$( dirname "$0" )" && pwd )" -if [ "$#" -lt 4 ] -then +if [[ "$#" -lt 4 ]]; then echo "Usage..." echo "gen-buildsys.sh [build flavor] [ninja] [scan-build] [cmakeargs]" echo "Specify the path to the top level CMake file." @@ -30,7 +29,7 @@ cxxCompiler="$compiler++" majorVersion="$6" minorVersion="$7" -if [ "$compiler" = "gcc" ]; then cxxCompiler="g++"; fi +if [[ "$compiler" == "gcc" ]]; then cxxCompiler="g++"; fi check_version_exists() { desired_version=-1 @@ -47,23 +46,23 @@ check_version_exists() { echo "$desired_version" } -if [ -z "$CLR_CC" ]; then +if [[ -z "$CLR_CC" ]]; then # Set default versions - if [ -z "$majorVersion" ]; then + if [[ -z "$majorVersion" ]]; then # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero. - if [ "$compiler" = "clang" ]; then versions=( 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) - elif [ "$compiler" = "gcc" ]; then versions=( 9 8 7 6 5 4.9 ); fi + if [[ "$compiler" == "clang" ]]; then versions=( 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) + elif [[ "$compiler" == "gcc" ]]; then versions=( 9 8 7 6 5 4.9 ); fi for version in "${versions[@]}"; do parts=(${version//./ }) desired_version="$(check_version_exists "${parts[0]}" "${parts[1]}")" - if [ "$desired_version" != "-1" ]; then majorVersion="${parts[0]}"; break; fi + if [[ "$desired_version" != "-1" ]]; then majorVersion="${parts[0]}"; break; fi done - if [ -z "$majorVersion" ]; then + if [[ -z "$majorVersion" ]]; then if command -v "$compiler" > /dev/null; then - if [ "$(uname)" != "Darwin" ]; then + if [[ "$(uname)" != "Darwin" ]]; then echo "WARN: Specific version of $compiler not found, falling back to use the one in PATH." fi CC="$(command -v "$compiler")" @@ -73,8 +72,8 @@ if [ -z "$CLR_CC" ]; then exit 1 fi else - if [ "$compiler" = "clang" ] && [ "$majorVersion" -lt 5 ]; then - if [ "$build_arch" = "arm" ] || [ "$build_arch" = "armel" ]; then + if [[ "$compiler" == "clang" && "$majorVersion" -lt 5 ]]; then + if [[ "$build_arch" == "arm" || "$build_arch" == "armel" ]]; then if command -v "$compiler" > /dev/null; then echo "WARN: Found clang version $majorVersion which is not supported on arm/armel architectures, falling back to use clang from PATH." CC="$(command -v "$compiler")" @@ -88,19 +87,19 @@ if [ -z "$CLR_CC" ]; then fi else desired_version="$(check_version_exists "$majorVersion" "$minorVersion")" - if [ "$desired_version" = "-1" ]; then + if [[ "$desired_version" == "-1" ]]; then echo "ERROR: Could not find specific version of $compiler: $majorVersion $minorVersion." exit 1 fi fi - if [ -z "$CC" ]; then + if [[ -z "$CC" ]]; then CC="$(command -v "$compiler$desired_version")" CXX="$(command -v "$cxxCompiler$desired_version")" - if [ -z "$CXX" ]; then CXX="$(command -v "$cxxCompiler")"; fi + if [[ -z "$CXX" ]]; then CXX="$(command -v "$cxxCompiler")"; fi fi else - if [ ! -f "$CLR_CC" ]; then + if [[ ! -f "$CLR_CC" ]]; then echo "ERROR: CLR_CC is set but path '$CLR_CC' does not exist" exit 1 fi @@ -108,7 +107,7 @@ else CXX="$CLR_CXX" fi -if [ -z "$CC" ]; then +if [[ -z "$CC" ]]; then echo "ERROR: Unable to find $compiler." exit 1 fi @@ -146,7 +145,7 @@ for i in "${@:8}"; do done cmake_extra_defines= -if [ "$CROSSCOMPILE" == "1" ]; then +if [[ "$CROSSCOMPILE" == "1" ]]; then if ! [[ -n "$ROOTFS_DIR" ]]; then echo "ROOTFS_DIR not set for crosscompile" exit 1 @@ -155,19 +154,19 @@ if [ "$CROSSCOMPILE" == "1" ]; then TARGET_BUILD_ARCH="$build_arch" export TARGET_BUILD_ARCH - if [ -n "$tryrun_dir" ]; then + if [[ -n "$tryrun_dir" ]]; then cmake_extra_defines="$cmake_extra_defines -C $tryrun_dir/tryrun.cmake" fi cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$scriptroot/../common/cross/toolchain.cmake" fi -if [ "$build_arch" == "armel" ]; then +if [[ "$build_arch" == "armel" ]]; then cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1" fi cmake_command=$(command -v cmake) -if [[ "$scan_build" == "ON" && "$SCAN_BUILD_COMMAND" != "" ]]; then +if [[ "$scan_build" == "ON" && -n "$SCAN_BUILD_COMMAND" ]]; then cmake_command="$SCAN_BUILD_COMMAND $cmake_command" fi diff --git a/src/coreclr/build-test.sh b/src/coreclr/build-test.sh index d3dff1af213756..914e6ac73beebf 100755 --- a/src/coreclr/build-test.sh +++ b/src/coreclr/build-test.sh @@ -2,7 +2,7 @@ build_test_wrappers() { - if [ "$__BuildTestWrappers" -ne -0 ]; then + if [[ "$__BuildTestWrappers" -ne -0 ]]; then echo "${__MsgPrefix}Creating test wrappers..." export __Exclude="${__ProjectDir}/tests/issues.targets" @@ -10,7 +10,7 @@ build_test_wrappers() buildVerbosity="Summary" - if [ "$__VerboseBuild" = 1 ]; then + if [[ "$__VerboseBuild" == 1 ]]; then buildVerbosity="Diag" fi @@ -27,9 +27,10 @@ build_test_wrappers() nextCommand="\"${__DotNetCli}\" msbuild \"${__ProjectDir}/tests/src/runtest.proj\" /nodereuse:false /p:BuildWrappers=true /p:TargetsWindows=false $__Logging /p:__BuildOS=$__BuildOS /p:__BuildType=$__BuildType /p:__BuildArch=$__BuildArch" eval $nextCommand - if [ $? -ne 0 ]; then + local exitCode="$?" + if [[ "$exitCode" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: XUnit wrapper build failed. Refer to the build log files for details (above)" - exit 1 + exit "$exitCode" else echo "XUnit Wrappers have been built." echo { "\"build_os\"": "\"${__BuildOS}\"", "\"build_arch\"": "\"${__BuildArch}\"", "\"build_type\"": "\"${__BuildType}\"" } > "${__TestWorkingDir}/build_info.json" @@ -42,20 +43,20 @@ generate_layout() { echo "${__MsgPrefix}Creating test overlay..." - __TestDir=$__ProjectDir/tests - __ProjectFilesDir=$__TestDir - __TestBinDir=$__TestWorkingDir + __TestDir="$__ProjectDir"/tests + __ProjectFilesDir="$__TestDir" + __TestBinDir="$__TestWorkingDir" - if [ $__RebuildTests -ne 0 ]; then - if [ -d "${__TestBinDir}" ]; then + if [[ "$__RebuildTests" -ne 0 ]]; then + if [[ -d "${__TestBinDir}" ]]; then echo "Removing tests build dir: ${__TestBinDir}" - rm -rf $__TestBinDir + rm -rf "$__TestBinDir" fi fi __CMakeBinDir="${__TestBinDir}" - if [ -z "$__TestIntermediateDir" ]; then + if [[ -z "$__TestIntermediateDir" ]]; then __TestIntermediateDir="tests/obj/${__BuildOS}.${__BuildArch}.${__BuildType}" fi @@ -64,17 +65,17 @@ generate_layout() echo "__BuildType: ${__BuildType}" echo "__TestIntermediateDir: ${__TestIntermediateDir}" - if [ ! -f "$__TestBinDir" ]; then + if [[ ! -f "$__TestBinDir" ]]; then echo "Creating TestBinDir: ${__TestBinDir}" - mkdir -p $__TestBinDir + mkdir -p "$__TestBinDir" fi - if [ ! -f "$__LogsDir" ]; then + if [[ ! -f "$__LogsDir" ]]; then echo "Creating LogsDir: ${__LogsDir}" - mkdir -p $__LogsDir + mkdir -p "$__LogsDir" fi - if [ ! -f "$__MsbuildDebugLogsDir" ]; then + if [[ ! -f "$__MsbuildDebugLogsDir" ]]; then echo "Creating MsbuildDebugLogsDir: ${__MsbuildDebugLogsDir}" - mkdir -p $__MsbuildDebugLogsDir + mkdir -p "$__MsbuildDebugLogsDir" fi # Set up the directory for MSBuild debug logs. @@ -90,51 +91,53 @@ generate_layout() build_MSBuild_projects "Restore_Packages" "${__ProjectDir}/tests/build.proj" "Restore product binaries (build tests)" "/t:BatchRestorePackages" - if [ -n "$__UpdateInvalidPackagesArg" ]; then + if [[ -n "$__UpdateInvalidPackagesArg" ]]; then __up="/t:UpdateInvalidPackageVersions" fi echo "${__MsgPrefix}Creating test overlay..." - if [ -z "$xUnitTestBinBase" ]; then - xUnitTestBinBase=$__TestWorkingDir + if [[ -z "$xUnitTestBinBase" ]]; then + xUnitTestBinBase="$__TestWorkingDir" fi - export CORE_ROOT=$xUnitTestBinBase/Tests/Core_Root + export CORE_ROOT="$xUnitTestBinBase"/Tests/Core_Root - if [ -d "${CORE_ROOT}" ]; then - rm -rf $CORE_ROOT + if [[ -d "${CORE_ROOT}" ]]; then + rm -rf "$CORE_ROOT" fi - mkdir -p $CORE_ROOT + mkdir -p "$CORE_ROOT" build_MSBuild_projects "Tests_Overlay_Managed" "${__ProjectDir}/tests/src/runtest.proj" "Creating test overlay" "/t:CreateTestOverlay" - chmod +x $__BinDir/corerun - chmod +x $__CrossgenExe + chmod +x "$__BinDir"/corerun + chmod +x "$__CrossgenExe" # Make sure to copy over the pulled down packages - cp -r $__BinDir/* $CORE_ROOT/ > /dev/null + cp -r "$__BinDir/*" "$CORE_ROOT/" > /dev/null - if [ "$__BuildOS" != "OSX" ]; then + if [[ "$__BuildOS" != "OSX" ]]; then nextCommand="\"$__TestDir/setup-stress-dependencies.sh\" --arch=$__BuildArch --outputDir=$CORE_ROOT" echo "Resolve runtime dependences via $nextCommand" eval $nextCommand - if [ $? != 0 ]; then + + local exitCode="$?" + if [[ "$exitCode" != 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: setup-stress-dependencies failed." - exit 1 + exit "$exitCode" fi fi # Precompile framework assemblies with crossgen if required - if [[ $__DoCrossgen != 0 || $__DoCrossgen2 != 0 ]]; then + if [[ "$__DoCrossgen" != 0 || "$__DoCrossgen2" != 0 ]]; then precompile_coreroot_fx fi } precompile_coreroot_fx() { - local overlayDir=$CORE_ROOT + local overlayDir="$CORE_ROOT" local compilerName=Crossgen # Read the exclusion file for this platform @@ -142,24 +145,24 @@ precompile_coreroot_fx() skipCrossGenFiles+=('System.Runtime.WindowsRuntime.dll') # Temporary output folder for Crossgen2-compiled assemblies - local outputDir=${overlayDir}/out + local outputDir="$overlayDir"/out # Delete previously crossgened assemblies - rm ${overlayDir}/*.ni.dll + rm "$overlayDir"/*.ni.dll # Collect reference assemblies for Crossgen2 local crossgen2References="" - if [[ $__DoCrossgen2 != 0 ]]; then + if [[ "$__DoCrossgen2" != 0 ]]; then compilerName=Crossgen2 - mkdir ${outputDir} + mkdir "$outputDir" skipCrossGenFiles+=('Microsoft.CodeAnalysis.CSharp.dll') skipCrossGenFiles+=('Microsoft.CodeAnalysis.dll') skipCrossGenFiles+=('Microsoft.CodeAnalysis.VisualBasic.dll') - for reference in ${overlayDir}/*.dll; do + for reference in "$overlayDir"/*.dll; do crossgen2References+=" -r:${reference}" done fi @@ -170,49 +173,49 @@ precompile_coreroot_fx() local failedToPrecompile=0 declare -a failedAssemblies - filesToPrecompile=$(find -L $overlayDir -maxdepth 1 -iname Microsoft.\*.dll -o -iname System.\*.dll -type f) + filesToPrecompile=$(find -L "$overlayDir" -maxdepth 1 -iname Microsoft.\*.dll -o -iname System.\*.dll -type f) for fileToPrecompile in ${filesToPrecompile}; do - local filename=${fileToPrecompile} + local filename="$fileToPrecompile" if is_skip_crossgen_test "$(basename $filename)"; then continue fi - echo Precompiling $filename + echo Precompiling "$filename" - if [[ $__DoCrossgen != 0 ]]; then - $__CrossgenExe /Platform_Assemblies_Paths $overlayDir $filename 1> $filename.stdout 2>$filename.stderr + if [[ "$__DoCrossgen" != 0 ]]; then + "$__CrossgenExe" /Platform_Assemblies_Paths "$overlayDir" "$filename" 1> "$filename".stdout 2> "$filename".stderr fi - if [[ $__DoCrossgen2 != 0 ]]; then - ${overlayDir}/crossgen2/crossgen2 ${crossgen2References} -O --inputbubble --out ${outputDir}/$(basename $filename) $filename 1>$filename.stdout 2>$filename.stderr + if [[ "$__DoCrossgen2" != 0 ]]; then + "$overlayDir"/crossgen2/crossgen2 "$crossgen2References" -O --inputbubble --out "$outputDir"/"$(basename $filename)" "$filename" 1> "$filename".stdout 2> "$filename".stderr fi - local exitCode=$? - if [[ $exitCode != 0 ]]; then - if grep -q -e '0x80131018' $filename.stderr; then + local exitCode="$?" + if [[ "$exitCode" != 0 ]]; then + if grep -q -e '0x80131018' "$filename".stderr; then printf "\n\t$filename is not a managed assembly.\n\n" else - echo Unable to precompile $filename, exit code is $exitCode. - cat $filename.stdout - cat $filename.stderr + echo Unable to precompile "$filename", exit code is "$exitCode". + cat "$filename".stdout + cat "$filename".stderr failedAssemblies+=($(basename -- "$filename")) failedToPrecompile=$((failedToPrecompile+1)) fi else - rm $filename.{stdout,stderr} + rm "$filename".{stdout,stderr} fi totalPrecompiled=$((totalPrecompiled+1)) - echo Processed: $totalPrecompiled, failed $failedToPrecompile + echo "Processed: $totalPrecompiled, failed $failedToPrecompile" done - if [[ $__DoCrossgen2 != 0 ]]; then + if [[ "$__DoCrossgen2" != 0 ]]; then # Copy the Crossgen-compiled assemblies back to CORE_ROOT - mv -f ${outputDir}/* ${overlayDir}/ - rm -r ${outputDir} + mv -f "$outputDir"/* "$overlayDir"/ + rm -r "$outputDir" fi - if [[ $failedToPrecompile != 0 ]]; then + if [[ "$failedToPrecompile" != 0 ]]; then echo Failed assemblies: for assembly in "${failedAssemblies[@]}"; do echo " $assembly" @@ -226,7 +229,7 @@ declare -a skipCrossGenFiles function is_skip_crossgen_test { for skip in "${skipCrossGenFiles[@]}"; do - if [ "$1" == "$skip" ]; then + if [[ "$1" == "$skip" ]]; then return 0 fi done @@ -237,34 +240,34 @@ build_Tests() { echo "${__MsgPrefix}Building Tests..." - __TestDir=$__ProjectDir/tests - __ProjectFilesDir=$__TestDir - __TestBinDir=$__TestWorkingDir + __TestDir="$__ProjectDir"/tests + __ProjectFilesDir="$__TestDir" + __TestBinDir="$__TestWorkingDir" - if [ -f "${__TestWorkingDir}/build_info.json" ]; then + if [[ -f "${__TestWorkingDir}/build_info.json" ]]; then rm "${__TestWorkingDir}/build_info.json" fi - if [ $__RebuildTests -ne 0 ]; then - if [ -d "${__TestBinDir}" ]; then + if [[ "$__RebuildTests" -ne 0 ]]; then + if [[ -d "$__TestBinDir" ]]; then echo "Removing tests build dir: ${__TestBinDir}" - rm -rf $__TestBinDir + rm -rf "$__TestBinDir" fi fi - export __CMakeBinDir="${__TestBinDir}" - if [ ! -d "${__TestIntermediatesDir}" ]; then - mkdir -p ${__TestIntermediatesDir} + export __CMakeBinDir="$__TestBinDir" + if [[ ! -d "$__TestIntermediatesDir" ]]; then + mkdir -p "$__TestIntermediatesDir" fi __NativeTestIntermediatesDir="${__TestIntermediatesDir}/Native" - if [ ! -d "${__NativeTestIntermediatesDir}" ]; then - mkdir -p ${__NativeTestIntermediatesDir} + if [[ ! -d "${__NativeTestIntermediatesDir}" ]]; then + mkdir -p "${__NativeTestIntermediatesDir}" fi __ManagedTestIntermediatesDir="${__TestIntermediatesDir}/Managed" - if [ ! -d "${__ManagedTestIntermediatesDir}" ]; then - mkdir -p ${__ManagedTestIntermediatesDir} + if [[ ! -d "${__ManagedTestIntermediatesDir}" ]]; then + mkdir -p "${__ManagedTestIntermediatesDir}" fi echo "__BuildOS: ${__BuildOS}" @@ -274,17 +277,17 @@ build_Tests() echo "__NativeTestIntermediatesDir: ${__NativeTestIntermediatesDir}" echo "__ManagedTestIntermediatesDir: ${__ManagedTestIntermediatesDir}" - if [ ! -f "$__TestBinDir" ]; then + if [[ ! -f "$__TestBinDir" ]]; then echo "Creating TestBinDir: ${__TestBinDir}" - mkdir -p $__TestBinDir + mkdir -p "$__TestBinDir" fi - if [ ! -f "$__LogsDir" ]; then + if [[ ! -f "$__LogsDir" ]]; then echo "Creating LogsDir: ${__LogsDir}" - mkdir -p $__LogsDir + mkdir -p "$__LogsDir" fi - if [ ! -f "$__MsbuildDebugLogsDir" ]; then + if [[ ! -f "$__MsbuildDebugLogsDir" ]]; then echo "Creating MsbuildDebugLogsDir: ${__MsbuildDebugLogsDir}" - mkdir -p $__MsbuildDebugLogsDir + mkdir -p "$__MsbuildDebugLogsDir" fi # Set up the directory for MSBuild debug logs. @@ -298,30 +301,30 @@ build_Tests() # === # ========================================================================================= - if [ ${__SkipRestorePackages} != 1 ]; then + if [[ "${__SkipRestorePackages}" != 1 ]]; then build_MSBuild_projects "Restore_Product" "${__ProjectDir}/tests/build.proj" "Restore product binaries (build tests)" "/t:BatchRestorePackages" - if [ $? -ne 0 ]; then + if [[ "$?" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: package restoration failed. Refer to the build log files for details (above)" exit 1 fi fi - if [ $__SkipNative != 1 ]; then + if [[ "$__SkipNative" != 1 ]]; then build_native "$__BuildArch" "$__TestDir" "$__ProjectRoot" "$__NativeTestIntermediatesDir" "CoreCLR test component" - if [ $? -ne 0 ]; then + if [[ "$?" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: native test build failed. Refer to the build log files for details (above)" exit 1 fi fi - if [ $__SkipManaged != 1 ]; then + if [[ "$__SkipManaged" != 1 ]]; then echo "Starting the Managed Tests Build..." build_MSBuild_projects "Tests_Managed" "$__ProjectDir/tests/build.proj" "Managed tests build (build tests)" "$__up" - if [ $? -ne 0 ]; then + if [[ "$?" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: managed test build failed. Refer to the build log files for details (above)" exit 1 else @@ -329,7 +332,7 @@ build_Tests() build_MSBuild_projects "Check_Test_Build" "${__ProjectDir}/tests/src/runtest.proj" "Check Test Build" "/t:CheckTestBuild" - if [ $? -ne 0 ]; then + if [[ "$?" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: Check Test Build failed." exit 1 fi @@ -340,38 +343,38 @@ build_Tests() build_test_wrappers fi - if [ $__CopyNativeTestBinaries == 1 ]; then + if [[ "$__CopyNativeTestBinaries" == 1 ]]; then echo "Copying native test binaries to output..." build_MSBuild_projects "Tests_Managed" "$__ProjectDir/tests/build.proj" "Managed tests build (build tests)" "/t:CopyAllNativeProjectReferenceBinaries" - if [ $? -ne 0 ]; then + if [[ "$?" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Error: copying native test binaries failed. Refer to the build log files for details (above)" exit 1 fi fi - if [ -n "$__UpdateInvalidPackagesArg" ]; then + if [[ -n "$__UpdateInvalidPackagesArg" ]]; then __up="/t:UpdateInvalidPackageVersions" fi - if [ $__SkipGenerateLayout != 1 ]; then + if [[ "$__SkipGenerateLayout" != 1 ]]; then generate_layout fi } build_MSBuild_projects() { - subDirectoryName=$1 + subDirectoryName="$1" shift - projectName=$1 + projectName="$1" shift stepName="$1" shift extraBuildParameters=("$@") # Set up directories and file names - __BuildLogRootName=$subDirectoryName + __BuildLogRootName="$subDirectoryName" __BuildLog="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.log" __BuildWrn="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.wrn" __BuildErr="$__LogsDir/${__BuildLogRootName}.${__BuildOS}.${__BuildArch}.${__BuildType}.err" @@ -387,7 +390,7 @@ build_MSBuild_projects() __AppendToLog=false - if [ -n "$__priority1" ]; then + if [[ -n "$__priority1" ]]; then export __NumberOfTestGroups=10 fi @@ -397,7 +400,7 @@ build_MSBuild_projects() __msbuildWrn="\"/flp1:WarningsOnly;LogFile=${__BuildWrn};Append=${__AppendToLog}\"" __msbuildErr="\"/flp2:ErrorsOnly;LogFile=${__BuildErr};Append=${__AppendToLog}\"" - export __TestGroupToBuild=$testGroupToBuild + export __TestGroupToBuild="$testGroupToBuild" # Generate build command buildArgs=("$projectName") @@ -417,7 +420,7 @@ build_MSBuild_projects() eval $nextCommand # Make sure everything is OK - if [ $? -ne 0 ]; then + if [[ "$?" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Failed to build $stepName. See the build logs:" echo " $__BuildLog" echo " $__BuildWrn" @@ -449,7 +452,7 @@ build_MSBuild_projects() eval $nextCommand # Make sure everything is OK - if [ $? -ne 0 ]; then + if [[ "$?" -ne 0 ]]; then echo "${__ErrMsgPrefix}${__MsgPrefix}Failed to build $stepName. See the build logs:" echo " $__BuildLog" echo " $__BuildWrn" @@ -577,7 +580,7 @@ CORE_ROOT= source "$__ProjectRoot"/_build-commons.sh -if [ "${__BuildArch}" != "${__HostArch}" ]; then +if [[ "${__BuildArch}" != "${__HostArch}" ]]; then __CrossBuild=1 fi @@ -596,7 +599,7 @@ __CrossComponentBinDir="$__BinDir" __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen" __CrossArch="$__HostArch" -if [ "$__CrossBuild" = 1 ]; then +if [[ "$__CrossBuild" == 1 ]]; then __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch" fi __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log" @@ -604,8 +607,8 @@ __CrossgenExe="$__CrossComponentBinDir/crossgen" # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to it. # This is needed by CLI to function. -if [ -z "$HOME" ]; then - if [ ! -d "$__ProjectDir/temp_home" ]; then +if [[ -z "$HOME" ]]; then + if [[ ! -d "$__ProjectDir/temp_home" ]]; then mkdir temp_home fi @@ -616,13 +619,13 @@ fi if [[ (-z "$__GenerateLayoutOnly") && (-z "$__GenerateTestHostOnly") && (-z "$__BuildTestWrappersOnly") ]]; then build_Tests -elif [ ! -z "$__BuildTestWrappersOnly" ]; then +elif [[ ! -z "$__BuildTestWrappersOnly" ]]; then build_test_wrappers else generate_layout fi -if [ $? -ne 0 ]; then +if [[ "$?" -ne 0 ]]; then echo "Failed to build tests" exit 1 fi @@ -630,9 +633,9 @@ fi echo "${__MsgPrefix}Test build successful." echo "${__MsgPrefix}Test binaries are available at ${__TestBinDir}" -__testNativeBinDir=$__IntermediatesDir/tests +__testNativeBinDir="$__IntermediatesDir"/tests -if [ $__RunTests -ne 0 ]; then +if [[ "$__RunTests" -ne 0 ]]; then echo "Run Tests..." diff --git a/src/coreclr/build.sh b/src/coreclr/build.sh index 07e5580358685d..85ae602b50b90e 100755 --- a/src/coreclr/build.sh +++ b/src/coreclr/build.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # resolve python-version to use -if [ -z "$PYTHON" ] ; then +if [[ -z "$PYTHON" ]]; then if ! PYTHON=$(command -v python3 || command -v python2 || command -v python || command -v py) then echo "Unable to locate build-dependency python!" 1>&2 @@ -41,7 +41,7 @@ setup_dirs_local() mkdir -p "$__LogsDir" mkdir -p "$__MsbuildDebugLogsDir" - if [ "$__CrossBuild" = 1 ]; then + if [[ "$__CrossBuild" == 1 ]]; then mkdir -p "$__CrossComponentBinDir" fi } @@ -49,40 +49,40 @@ setup_dirs_local() restore_optdata() { local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj" - if [ "$__SkipRestoreOptData" = 0 ] && [ "$__IsMSBuildOnNETCoreSupported" = 1 ]; then + if [[ "$__SkipRestoreOptData" == 0 && "$__IsMSBuildOnNETCoreSupported" == 1 ]]; then echo "Restoring the OptimizationData package" "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs \ $OptDataProjectFilePath /t:Restore /m \ $__CommonMSBuildArgs $__UnprocessedBuildArgs - local exit_code=$? - if [ $exit_code != 0 ]; then + local exit_code="$?" + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to restore the optimization data package." - exit $exit_code + exit "$exit_code" fi fi - if [ "$__IsMSBuildOnNETCoreSupported" = 1 ]; then + if [[ "$__IsMSBuildOnNETCoreSupported" == 1 ]]; then # Parse the optdata package versions out of msbuild so that we can pass them on to CMake local PgoDataPackagePathOutputFile="${__IntermediatesDir}/optdatapath.txt" local IbcDataPackagePathOutputFile="${__IntermediatesDir}/ibcoptdatapath.txt" # Writes into ${PgoDataPackagePathOutputFile} - "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpPgoDataPackagePath ${__CommonMSBuildArgs} /p:PgoDataPackagePathOutputFile=${PgoDataPackagePathOutputFile} 2>&1 > /dev/null - local exit_code=$? - if [ $exit_code != 0 ] || [ ! -f "${PgoDataPackagePathOutputFile}" ]; then + "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpPgoDataPackagePath ${__CommonMSBuildArgs} /p:PgoDataPackagePathOutputFile=${PgoDataPackagePathOutputFile} > /dev/null 2>&1 + local exit_code="$?" + if [[ "$exit_code" != 0 || ! -f "${PgoDataPackagePathOutputFile}" ]]; then echo "${__ErrMsgPrefix}Failed to get PGO data package path." - exit $exit_code + exit "$exit_code" fi __PgoOptDataPath=$(<"${PgoDataPackagePathOutputFile}") # Writes into ${IbcDataPackagePathOutputFile} - "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpIbcDataPackagePath ${__CommonMSBuildArgs} /p:IbcDataPackagePathOutputFile=${IbcDataPackagePathOutputFile} 2>&1 > /dev/null - local exit_code=$? - if [ $exit_code != 0 ] || [ ! -f "${IbcDataPackagePathOutputFile}" ]; then + "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpIbcDataPackagePath ${__CommonMSBuildArgs} /p:IbcDataPackagePathOutputFile=${IbcDataPackagePathOutputFile} > /dev/null 2>&1 + local exit_code="$?" + if [[ "$exit_code" != 0 || ! -f "${IbcDataPackagePathOutputFile}" ]]; then echo "${__ErrMsgPrefix}Failed to get IBC data package path." - exit $exit_code + exit "$exit_code" fi __IbcOptDataPath=$(<"${IbcDataPackagePathOutputFile}") @@ -91,21 +91,21 @@ restore_optdata() generate_event_logging_sources() { - __OutputEventingDir=$1 + __OutputEventingDir="$1" __PythonWarningFlags="-Wall" - if [[ $__IgnoreWarnings == 0 ]]; then + if [[ "$__IgnoreWarnings" == 0 ]]; then __PythonWarningFlags="$__PythonWarningFlags -Werror" fi echo "Laying out dynamically generated EventSource classes" - $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir" + "$PYTHON" -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir" } generate_event_logging() { # Event Logging Infrastructure - if [[ $__SkipMSCorLib == 0 ]]; then + if [[ "$__SkipMSCorLib" == 0 ]]; then generate_event_logging_sources "$__ArtifactsIntermediatesDir/Eventing/$__BuildArch/$__BuildType" fi } @@ -135,7 +135,7 @@ build_cross_architecture_components() export CROSSCOMPILE=0 __CMakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CROSS_COMPONENTS_BUILD=1 $__CMakeArgs" - if [ "$__SkipCrossArchBuild" = 1 ]; then + if [[ "$__SkipCrossArchBuild" == 1 ]]; then echo "Skipping cross-architecture components build." else build_native "$__CrossArch" "$__ProjectRoot" "$__ProjectRoot" "$intermediatesForBuild" "cross-architecture components" @@ -149,42 +149,42 @@ build_CoreLib_ni() local __CrossGenExec=$1 local __CoreLibILDir=$2 - if [ $__PartialNgen == 1 ]; then + if [[ "$__PartialNgen" == 1 ]]; then export COMPlus_PartialNGen=1 fi - if [ -e $__CrossGenCoreLibLog ]; then - rm $__CrossGenCoreLibLog + if [[ -e "$__CrossGenCoreLibLog" ]]; then + rm "$__CrossGenCoreLibLog" fi echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"." echo "$__CrossGenExec /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll" - $__CrossGenExec /nologo /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1 - local exit_code=$? - if [ $exit_code != 0 ]; then + "$__CrossGenExec" /nologo /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1 + local exit_code="$?" + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog" - exit $exit_code + exit "$exit_code" fi - if [ "$__BuildOS" == "Linux" ]; then + if [[ "$__BuildOS" == "Linux" ]]; then echo "Generating symbol file for System.Private.CoreLib.dll" echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll" - $__CrossGenExec /nologo /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1 - local exit_code=$? - if [ $exit_code != 0 ]; then + "$__CrossGenExec" /nologo /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1 + local exit_code="$?" + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog" - exit $exit_code + exit "$exit_code" fi fi } build_CoreLib() { - if [ "$__IsMSBuildOnNETCoreSupported" = 0 ]; then + if [[ "$__IsMSBuildOnNETCoreSupported" == 0 ]]; then echo "System.Private.CoreLib.dll build unsupported." return fi - if [ $__SkipMSCorLib == 1 ]; then + if [[ "$__SkipMSCorLib" == 1 ]]; then echo "Skipping building System.Private.CoreLib." return fi @@ -193,7 +193,7 @@ build_CoreLib() # Invoke MSBuild __ExtraBuildArgs="" - if [[ "$__IbcTuning" == "" ]]; then + if [[ -z "$__IbcTuning" ]]; then __ExtraBuildArgs="$__ExtraBuildArgs /p:OptimizationDataDir=\"$__IbcOptDataPath/data\"" __ExtraBuildArgs="$__ExtraBuildArgs /p:EnableProfileGuidedOptimization=true" fi @@ -209,10 +209,10 @@ build_CoreLib() /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \ $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs - local exit_code=$? - if [ $exit_code != 0 ]; then + local exit_code="$?" + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to restore managed components." - exit $exit_code + exit "$exit_code" fi "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary $__ArcadeScriptArgs \ @@ -222,23 +222,23 @@ build_CoreLib() /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \ $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs - local exit_code=$? - if [ $exit_code != 0 ]; then + local exit_code="$?" + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to build managed components." - exit $exit_code + exit "$exit_code" fi if [[ "$__BuildManagedTools" -eq "1" ]]; then echo "Publishing crossgen2 for $__DistroRid" "$__RepoRootDir/dotnet.sh" publish --self-contained -r $__DistroRid -c $__BuildType -o "$__BinDir/crossgen2" "$__ProjectRoot/src/tools/crossgen2/crossgen2/crossgen2.csproj" /nologo /p:BuildArch=$__BuildArch - local exit_code=$? - if [ $exit_code != 0 ]; then + local exit_code="$?" + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to build crossgen2." - exit $exit_code + exit "$exit_code" fi - if [ "$__HostOS" = "OSX" ]; then + if [[ "$__HostOS" == "OSX" ]]; then cp "$__BinDir/libclrjit.dylib" "$__BinDir/crossgen2/libclrjitilc.dylib" cp "$__BinDir/libjitinterface.dylib" "$__BinDir/crossgen2/libjitinterface.dylib" else @@ -249,10 +249,10 @@ build_CoreLib() local __CoreLibILDir="$__BinDir"/IL - if [ "$__SkipCrossgen" = 1 ]; then + if [[ "$__SkipCrossgen" == 1 ]]; then echo "Skipping generating native image" - if [ "$__CrossBuild" = 1 ]; then + if [[ "$__CrossBuild" == 1 ]]; then # Crossgen not performed, so treat the IL version as the final version cp "$__CoreLibILDir"/System.Private.CoreLib.dll "$__BinDir"/System.Private.CoreLib.dll fi @@ -261,31 +261,31 @@ build_CoreLib() fi # The cross build generates a crossgen with the target architecture. - if [ $__CrossBuild == 0 ]; then - if [ $__SkipCoreCLR == 1 ]; then + if [[ "$__CrossBuild" == 0 ]]; then + if [[ "$__SkipCoreCLR" == 1 ]]; then return fi # The architecture of host pc must be same architecture with target. - if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then - build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir + if [[ "$__HostArch" == "$__BuildArch" ]]; then + build_CoreLib_ni "$__BinDir/crossgen" "$__CoreLibILDir" elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then - build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir + build_CoreLib_ni "$__BinDir/crossgen" "$__CoreLibILDir" elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then - build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir + build_CoreLib_ni "$__BinDir/crossgen" "$__CoreLibILDir" else exit 1 fi else if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then - build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir + build_CoreLib_ni "$__CrossComponentBinDir/crossgen" "$__CoreLibILDir" elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then - build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir + build_CoreLib_ni "$__CrossComponentBinDir/crossgen" "$__CoreLibILDir" elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then - build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir + build_CoreLib_ni "$__CrossComponentBinDir/crossgen" "$__CoreLibILDir" else # Crossgen not performed, so treat the IL version as the final version - cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll + cp "$__CoreLibILDir"/System.Private.CoreLib.dll "$__BinDir"/System.Private.CoreLib.dll fi fi } @@ -293,32 +293,32 @@ build_CoreLib() generate_NugetPackages() { # We can only generate nuget package if we also support building mscorlib as part of this build. - if [ "$__IsMSBuildOnNETCoreSupported" = 0 ]; then + if [[ "$__IsMSBuildOnNETCoreSupported" == 0 ]]; then echo "Nuget package generation unsupported." return fi # Since we can build mscorlib for this OS, did we build the native components as well? - if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then + if [[ "$__SkipCoreCLR" == 1 && "$__CrossgenOnly" == 0 ]]; then echo "Unable to generate nuget packages since native components were not built." return fi - echo "Generating nuget packages for "$__BuildOS - echo "DistroRid is "$__DistroRid - echo "ROOTFS_DIR is "$ROOTFS_DIR + echo "Generating nuget packages for $__BuildOS" + echo "DistroRid is $__DistroRid" + echo "ROOTFS_DIR is $ROOTFS_DIR" # Build the packages # Package build uses the Arcade system and scripts, relying on it to restore required toolsets as part of build - $__RepoRootDir/eng/common/build.sh -r -b -projects $__SourceDir/.nuget/packages.builds \ - -verbosity minimal -bl:$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.binlog \ + "$__RepoRootDir"/eng/common/build.sh -r -b -projects "$__SourceDir"/.nuget/packages.builds \ + -verbosity minimal -bl:"$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.binlog" \ /p:PortableBuild=true \ - /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:__DoCrossArchBuild=$__CrossBuild \ + /p:"__IntermediatesDir=$__IntermediatesDir" /p:"__RootBinDir=$__RootBinDir" /p:"__DoCrossArchBuild=$__CrossBuild" \ $__CommonMSBuildArgs $__UnprocessedBuildArgs - local exit_code=$? - if [ $exit_code != 0 ]; then + local exit_code="$?" + if [[ "$exit_code" != 0 ]]; then echo "${__ErrMsgPrefix}Failed to generate Nuget packages." - exit $exit_code + exit "$exit_code" fi } @@ -464,7 +464,7 @@ __CMakeArgs="" source "$__ProjectRoot"/_build-commons.sh -if [ "${__BuildArch}" != "${__HostArch}" ]; then +if [[ "${__BuildArch}" != "${__HostArch}" ]]; then __CrossBuild=1 fi @@ -480,15 +480,15 @@ export __ArtifactsIntermediatesDir="$__RepoRootDir/artifacts/obj/coreclr" __CrossComponentBinDir="$__BinDir" __CrossArch="$__HostArch" -if [ "$__CrossBuild" = 1 ]; then +if [[ "$__CrossBuild" == 1 ]]; then __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch" fi __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log" # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set. # This is needed by CLI to function. -if [ -z "$HOME" ]; then - if [ ! -d "$__ProjectDir/temp_home" ]; then +if [[ -z "$HOME" ]]; then + if [[ ! -d "$__ProjectDir/temp_home" ]]; then mkdir temp_home fi export HOME="$__ProjectDir"/temp_home @@ -517,19 +517,19 @@ generate_event_logging # Build the coreclr (native) components. __CMakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize $__CMakeArgs" -if [ "$__SkipConfigure" = 0 ] && [ "$__CodeCoverage" = 1 ]; then +if [[ "$__SkipConfigure" == 0 && "$__CodeCoverage" == 1 ]]; then __CMakeArgs="-DCLR_CMAKE_ENABLE_CODE_COVERAGE=1 $__CMakeArgs" fi -if [ "$__SkipCoreCLR" = 1 ]; then +if [[ "$__SkipCoreCLR" == 1 ]]; then echo "Skipping CoreCLR component build." else build_native "$__BuildArch" "$__ProjectRoot" "$__ProjectRoot" "$__IntermediatesDir" "CoreCLR component" fi # Build cross-architecture components -if [ "$__SkipCrossArchNative" != 1 ]; then - if [ "$__CrossBuild" = 1 ]; then +if [[ "$__SkipCrossArchNative" != 1 ]]; then + if [[ "$__CrossBuild" == 1 ]]; then build_cross_architecture_components fi fi @@ -538,12 +538,12 @@ fi build_CoreLib -if [ "$__CrossgenOnly" = 1 ]; then +if [[ "$__CrossgenOnly" == 1 ]]; then build_CoreLib_ni "$__BinDir/crossgen" fi # Generate nuget packages -if [ "$__SkipNuget" != 1 ]; then +if [[ "$__SkipNuget" != 1 ]]; then generate_NugetPackages fi diff --git a/src/installer/corehost/build.sh b/src/installer/corehost/build.sh index f5fe1ceeecce1a..9e2878bb4d4b56 100755 --- a/src/installer/corehost/build.sh +++ b/src/installer/corehost/build.sh @@ -83,7 +83,7 @@ export __BinDir __IntermediatesDir __CMakeArgs="-DCLI_CMAKE_HOST_VER=\"$__host_ver\" -DCLI_CMAKE_COMMON_HOST_VER=\"$__apphost_ver\" -DCLI_CMAKE_HOST_FXR_VER=\"$__fxr_ver\"" __CMakeArgs="-DCLI_CMAKE_HOST_POLICY_VER=\"$__policy_ver\" -DCLI_CMAKE_PKG_RID=\"$__DistroRid\" -DCLI_CMAKE_COMMIT_HASH=\"$__commit_hash\" $__CMakeArgs" -if [ "$__PortableBuild" = 1 ]; then +if [[ "$__PortableBuild" == 1 ]]; then __CMakeArgs="-DCLI_CMAKE_PORTABLE_BUILD=1 $__CMakeArgs" fi diff --git a/src/libraries/Native/build-native.sh b/src/libraries/Native/build-native.sh index 4ed90f5c4212a8..a0481c6f2b668d 100755 --- a/src/libraries/Native/build-native.sh +++ b/src/libraries/Native/build-native.sh @@ -47,16 +47,16 @@ __VerboseBuild=false source "$__RepoRootDir"/eng/native/build-commons.sh # Set cross build -if [ "$__BuildArch" != wasm ]; then +if [[ "$__BuildArch" != wasm ]]; then __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs" __CMakeArgs="-DCMAKE_STATIC_LIB_LINK=$__StaticLibLink $__CMakeArgs" - if [ "$__BuildArch" != x86 ] && [ "$__BuildArch" != x64 ]; then + if [[ "$__BuildArch" != x86 && "$__BuildArch" != x64 ]]; then __CrossBuild=1 echo "Set CrossBuild for $__BuildArch build" fi else - if [ -z "$EMSDK_PATH" ]; then + if [[ -z "$EMSDK_PATH" ]]; then echo "Error: Should set EMSDK_PATH environment variable pointing to emsdk root." exit 1 fi @@ -64,7 +64,7 @@ else fi # set default OSX deployment target -if [ "$__BuildOS" = OSX ]; then +if [[ "$__BuildOS" == OSX ]]; then __CMakeArgs="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 $__CMakeArgs" fi From 933d4afedd38aa4ccb493b7b55690db77d761c08 Mon Sep 17 00:00:00 2001 From: Adeel Date: Mon, 20 Jan 2020 17:58:18 +0000 Subject: [PATCH 3/4] Address CR feedback --- src/coreclr/build-test.sh | 4 ++-- src/coreclr/build.sh | 14 ++++---------- src/installer/corehost/build.sh | 1 - src/libraries/Native/build-native.sh | 1 - 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/coreclr/build-test.sh b/src/coreclr/build-test.sh index 914e6ac73beebf..c65661b732496d 100755 --- a/src/coreclr/build-test.sh +++ b/src/coreclr/build-test.sh @@ -473,8 +473,8 @@ usage_list+=("-skipgeneratelayout: Do not generate the Core_Root layout.") usage_list+=("-skiprestorepackages: skip package restore.") # Obtain the location of the bash script to figure out where the root of the repo is. -__ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -__RepoRootDir="${__ProjectRoot}/../.." +__ProjectRoot="$(cd "$(dirname "$0")"; pwd -P)" +__RepoRootDir="$(cd "$__ProjectRoot"/../..; pwd -P)" handle_arguments_local() { case "$1" in diff --git a/src/coreclr/build.sh b/src/coreclr/build.sh index 85ae602b50b90e..6c54d81b115e3c 100755 --- a/src/coreclr/build.sh +++ b/src/coreclr/build.sh @@ -135,11 +135,7 @@ build_cross_architecture_components() export CROSSCOMPILE=0 __CMakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CROSS_COMPONENTS_BUILD=1 $__CMakeArgs" - if [[ "$__SkipCrossArchBuild" == 1 ]]; then - echo "Skipping cross-architecture components build." - else - build_native "$__CrossArch" "$__ProjectRoot" "$__ProjectRoot" "$intermediatesForBuild" "cross-architecture components" - fi + build_native "$__CrossArch" "$__ProjectRoot" "$__ProjectRoot" "$intermediatesForBuild" "cross-architecture components" export CROSSCOMPILE=1 } @@ -409,11 +405,9 @@ echo "Commencing CoreCLR Repo build" # # Set the default arguments for build -# Obtain the location of the bash script to figure out where the root of the subrepo is. -__ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Some paths are relative to the main repo root -__RepoRootDir="${__ProjectRoot}/../.." +# Obtain the location of the bash script to figure out where the root of the repo is. +__ProjectRoot="$(cd "$(dirname "$0")"; pwd -P)" +__RepoRootDir="$(cd "$__ProjectRoot"/../..; pwd -P)" __BuildArch= __BuildType=Debug diff --git a/src/installer/corehost/build.sh b/src/installer/corehost/build.sh index 9e2878bb4d4b56..5cd97ec0ded1e1 100755 --- a/src/installer/corehost/build.sh +++ b/src/installer/corehost/build.sh @@ -20,7 +20,6 @@ __CompilerMajorVersion= __CompilerMinorVersion= __CrossBuild=0 __IsMSBuildOnNETCoreSupported=0 -__NumProc=1 __PortableBuild=1 __RootBinDir="$__RepoRootDir/artifacts" __SkipConfigure=0 diff --git a/src/libraries/Native/build-native.sh b/src/libraries/Native/build-native.sh index a0481c6f2b668d..9f0031031e8694 100755 --- a/src/libraries/Native/build-native.sh +++ b/src/libraries/Native/build-native.sh @@ -35,7 +35,6 @@ __CompilerMajorVersion= __CompilerMinorVersion= __CrossBuild=0 __IsMSBuildOnNETCoreSupported=0 -__NumProc=1 __PortableBuild=1 __RootBinDir="$__RepoRootDir/artifacts" __SkipConfigure=0 From f37f9b4482196c7e14d1691c34b6d8bd999b22c0 Mon Sep 17 00:00:00 2001 From: Adeel Date: Tue, 21 Jan 2020 00:11:58 +0000 Subject: [PATCH 4/4] Fix quotes --- src/coreclr/build-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/build-test.sh b/src/coreclr/build-test.sh index c65661b732496d..1898c16d5f01cc 100755 --- a/src/coreclr/build-test.sh +++ b/src/coreclr/build-test.sh @@ -115,7 +115,7 @@ generate_layout() chmod +x "$__CrossgenExe" # Make sure to copy over the pulled down packages - cp -r "$__BinDir/*" "$CORE_ROOT/" > /dev/null + cp -r "$__BinDir"/* "$CORE_ROOT/" > /dev/null if [[ "$__BuildOS" != "OSX" ]]; then nextCommand="\"$__TestDir/setup-stress-dependencies.sh\" --arch=$__BuildArch --outputDir=$CORE_ROOT"