From 42d1d05d8560d8a560a320633b80479b4e1fb565 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 11:39:39 -0700 Subject: [PATCH 1/8] Support CentOS 7 in build module --- build.psm1 | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/build.psm1 b/build.psm1 index dcbdb34ea1..39e56d5d73 100644 --- a/build.psm1 +++ b/build.psm1 @@ -19,6 +19,10 @@ try { catch { } } +if ($IsLinux) { + $LinuxInfo = Get-Content /etc/os-release | ConvertFrom-StringData +} + function Start-PSBuild { [CmdletBinding(DefaultParameterSetName='CoreCLR')] @@ -81,7 +85,7 @@ function Start-PSBuild { } # verify we have all tools in place to do the build - $precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH! See: https://dotnet.github.io/getting-started/" + $precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH. Run Start-PSBootstrap. Also see: https://dotnet.github.io/getting-started/" if ($FullCLR) { # cmake is needed to build powershell.exe $precheck = $precheck -and (precheck 'cmake' 'cmake not found. You can install it from https://chocolatey.org/packages/cmake.portable') @@ -95,14 +99,8 @@ function Start-PSBuild { $precheck = $precheck -and (precheck 'msbuild' 'msbuild not found. Install Visual Studio 2015.') } elseif ($IsLinux -or $IsOSX) { - $InstallCommand = if ($IsLinux) { - 'apt-get' - } elseif ($IsOSX) { - 'brew' - } - foreach ($Dependency in 'cmake', 'make', 'g++') { - $precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run '$InstallCommand install $Dependency'") + $precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run Start-PSBootstrap.") } } @@ -397,14 +395,15 @@ function Start-PSBootstrap { try { # Install dependencies for Linux and OS X if ($IsLinux) { - $IsUbuntu = Select-String "Ubuntu 14.04" /etc/os-release -Quiet precheck 'curl' "Bootstrap dependency 'curl' not found in PATH, please install!" > $null - if ($IsUbuntu) { + if ($LinuxInfo.ID -eq 'ubuntu' -and $LinuxInfo.Version -eq '"14.04"') { # Install ours and .NET's dependencies sudo apt-get update -qq sudo apt-get install -y -qq make g++ cmake libc6 libgcc1 libstdc++6 libcurl3 libgssapi-krb5-2 libicu52 liblldb-3.6 liblttng-ust0 libssl1.0.0 libunwind8 libuuid1 zlib1g clang-3.5 + } elseif ($LinuxInfo.ID -eq 'centos' -and $LinuxInfo.Version -eq '"7"') { + sudo apt-get install -y -q make gcc cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang } else { - Write-Warning "This script only supports Ubuntu 14.04, you must install dependencies manually!" + Write-Warning "This script only supports Ubuntu 14.04 and CentOS 7, you must install dependencies manually!" } } elseif ($IsOSX) { precheck 'brew' "Bootstrap dependency 'brew' not found, must install Homebrew! See http://brew.sh/" From 511936606e1162e59dc201c3ea3fd0e1112078d5 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 11:59:14 -0700 Subject: [PATCH 2/8] Add Find-Dotnet to make build module smarter New function smartly adds the probable location of the .NET CLI tools to the path if `dotnet` is not found. If it is still not found, it restores the path. All functions using `dotnet` should call `Find-Dotnet` first. --- build.psm1 | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/build.psm1 b/build.psm1 index 39e56d5d73..7c4b9ead2e 100644 --- a/build.psm1 +++ b/build.psm1 @@ -68,14 +68,8 @@ function Start-PSBuild { $FullCLR = $true } - if (-not $NoPath) { - Write-Verbose "Appending probable .NET CLI tool path" - if ($IsWindows) { - $env:Path += ";$env:LocalAppData\Microsoft\dotnet" - } else { - $env:PATH += ":$env:HOME/.dotnet" - } - } + # Add .NET CLI tools to PATH + Find-Dotnet if ($IsWindows) { # use custom package store - this value is also defined in nuget.config under config/repositoryPath @@ -241,6 +235,9 @@ function New-PSOptions { [switch]$FullCLR ) + # Add .NET CLI tools to PATH + Find-Dotnet + if ($FullCLR) { $Top = "$PSScriptRoot/src/Microsoft.PowerShell.ConsoleHost" } else { @@ -344,6 +341,7 @@ function Start-PSPester { function Start-PSxUnit { [CmdletBinding()]param() + if ($IsWindows) { throw "xUnit tests are only currently supported on Linux / OS X" } @@ -353,6 +351,9 @@ function Start-PSxUnit { return } + # Add .NET CLI tools to PATH + Find-Dotnet + $Arguments = "--configuration", "Linux", "-parallel", "none" if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) { $Arguments += "-verbose" @@ -588,6 +589,9 @@ function Publish-NuGetFeed [string]$VersionSuffix ) + # Add .NET CLI tools to PATH + Find-Dotnet + @( 'Microsoft.PowerShell.Commands.Management', 'Microsoft.PowerShell.Commands.Utility', @@ -885,6 +889,9 @@ function Start-TypeGen throw "Start-TypeGen is not supported on non-windows. Use src/TypeCatalogGen/build.sh instead" } + # Add .NET CLI tools to PATH + Find-Dotnet + Push-Location "$PSScriptRoot/src/TypeCatalogParser" try { @@ -933,6 +940,24 @@ function Start-ResGen } +function Find-Dotnet() { + $originalPath = $env:PATH + $dotnetPath = if ($IsWindows) { + "$env:LocalAppData\Microsoft\dotnet" + } else { + "$env:HOME/.dotnet" + } + + if (-not (precheck 'dotnet' "Could not find 'dotnet', appending $dotnetPath to PATH.")) { + $env:PATH += [IO.Path]::PathSeparator + $dotnetPath + } + + if (-not (precheck 'dotnet' "Still could not find 'dotnet', restoring PATH.")) { + $env:PATH = $originalPath + } +} + + function script:log([string]$message) { Write-Host -Foreground Green $message } From 30dadb8dae74a6a6610d3dafc397848645c7b215 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 12:08:08 -0700 Subject: [PATCH 3/8] Use -match instead of -eq Since the use of quotes in /etc/os-release is inconsistent across distributions, we have to match instead of exactly compare. --- build.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index 7c4b9ead2e..b82356df5d 100644 --- a/build.psm1 +++ b/build.psm1 @@ -397,12 +397,12 @@ function Start-PSBootstrap { # Install dependencies for Linux and OS X if ($IsLinux) { precheck 'curl' "Bootstrap dependency 'curl' not found in PATH, please install!" > $null - if ($LinuxInfo.ID -eq 'ubuntu' -and $LinuxInfo.Version -eq '"14.04"') { + if ($LinuxInfo.ID -match 'ubuntu' -and $LinuxInfo.Version -match '14.04') { # Install ours and .NET's dependencies sudo apt-get update -qq sudo apt-get install -y -qq make g++ cmake libc6 libgcc1 libstdc++6 libcurl3 libgssapi-krb5-2 libicu52 liblldb-3.6 liblttng-ust0 libssl1.0.0 libunwind8 libuuid1 zlib1g clang-3.5 - } elseif ($LinuxInfo.ID -eq 'centos' -and $LinuxInfo.Version -eq '"7"') { sudo apt-get install -y -q make gcc cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang + } elseif ($LinuxInfo.ID -match 'centos' -and $LinuxInfo.Version -match '7') { } else { Write-Warning "This script only supports Ubuntu 14.04 and CentOS 7, you must install dependencies manually!" } From f3070bf28bfdec6541fd91e74db58f4add8ddcc5 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 12:08:44 -0700 Subject: [PATCH 4/8] Install curl during bootstrap Since the LLVM feed is no longer added, we do not need to update nor require curl beforehand, nor install wget. --- build.psm1 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/build.psm1 b/build.psm1 index b82356df5d..3979a2bb23 100644 --- a/build.psm1 +++ b/build.psm1 @@ -396,13 +396,11 @@ function Start-PSBootstrap { try { # Install dependencies for Linux and OS X if ($IsLinux) { - precheck 'curl' "Bootstrap dependency 'curl' not found in PATH, please install!" > $null if ($LinuxInfo.ID -match 'ubuntu' -and $LinuxInfo.Version -match '14.04') { # Install ours and .NET's dependencies - sudo apt-get update -qq - sudo apt-get install -y -qq make g++ cmake libc6 libgcc1 libstdc++6 libcurl3 libgssapi-krb5-2 libicu52 liblldb-3.6 liblttng-ust0 libssl1.0.0 libunwind8 libuuid1 zlib1g clang-3.5 - sudo apt-get install -y -q make gcc cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang + sudo apt-get install -y -qq curl make g++ cmake libc6 libgcc1 libstdc++6 libcurl3 libgssapi-krb5-2 libicu52 liblldb-3.6 liblttng-ust0 libssl1.0.0 libunwind8 libuuid1 zlib1g clang-3.5 } elseif ($LinuxInfo.ID -match 'centos' -and $LinuxInfo.Version -match '7') { + sudo apt-get install -y -q curl make gcc cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang } else { Write-Warning "This script only supports Ubuntu 14.04 and CentOS 7, you must install dependencies manually!" } @@ -410,7 +408,7 @@ function Start-PSBootstrap { precheck 'brew' "Bootstrap dependency 'brew' not found, must install Homebrew! See http://brew.sh/" # Install ours and .NET's dependencies - brew install cmake wget openssl + brew install curl cmake openssl brew link --force openssl } From bedcff49f6573dfe000f11dcc4540d0af2be1509 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 12:13:12 -0700 Subject: [PATCH 5/8] Use VERSION_ID instead of Version from /etc/os-release They are different fields and VERSION_ID is just the number. --- build.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.psm1 b/build.psm1 index 3979a2bb23..bdd94bd357 100644 --- a/build.psm1 +++ b/build.psm1 @@ -396,11 +396,11 @@ function Start-PSBootstrap { try { # Install dependencies for Linux and OS X if ($IsLinux) { - if ($LinuxInfo.ID -match 'ubuntu' -and $LinuxInfo.Version -match '14.04') { + if ($LinuxInfo.ID -match 'ubuntu' -and $LinuxInfo.VERSION_ID -match '14.04') { # Install ours and .NET's dependencies sudo apt-get install -y -qq curl make g++ cmake libc6 libgcc1 libstdc++6 libcurl3 libgssapi-krb5-2 libicu52 liblldb-3.6 liblttng-ust0 libssl1.0.0 libunwind8 libuuid1 zlib1g clang-3.5 - } elseif ($LinuxInfo.ID -match 'centos' -and $LinuxInfo.Version -match '7') { - sudo apt-get install -y -q curl make gcc cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang + } elseif ($LinuxInfo.ID -match 'centos' -and $LinuxInfo.VERSION_ID -match '7') { + sudo yum install -y -q curl make gcc cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang } else { Write-Warning "This script only supports Ubuntu 14.04 and CentOS 7, you must install dependencies manually!" } From 01b1b13344c303016fe7de69ac9fdb3d762b2e66 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 12:16:14 -0700 Subject: [PATCH 6/8] Install gcc-c++ instead of just gcc on CentOS --- build.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index bdd94bd357..d01136e2ae 100644 --- a/build.psm1 +++ b/build.psm1 @@ -400,7 +400,7 @@ function Start-PSBootstrap { # Install ours and .NET's dependencies sudo apt-get install -y -qq curl make g++ cmake libc6 libgcc1 libstdc++6 libcurl3 libgssapi-krb5-2 libicu52 liblldb-3.6 liblttng-ust0 libssl1.0.0 libunwind8 libuuid1 zlib1g clang-3.5 } elseif ($LinuxInfo.ID -match 'centos' -and $LinuxInfo.VERSION_ID -match '7') { - sudo yum install -y -q curl make gcc cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang + sudo yum install -y -q curl make gcc-c++ cmake glibc libgcc libstdc++ libcurl krb5-libs libicu lldb openssl-libs libunwind libuuid zlib clang } else { Write-Warning "This script only supports Ubuntu 14.04 and CentOS 7, you must install dependencies manually!" } From 0cdc7cfc7e173fc95413de2c33dfe74c458f0334 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 12:38:11 -0700 Subject: [PATCH 7/8] Use COMPILE_FLAGS instead of add_compile_options The latter came with CMake 2.8.12, and CentOS comes with 2.8.11, so we need to use a more compatible method. Also bump the minimum required version now that it is properly known. --- src/libpsl-native/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libpsl-native/CMakeLists.txt b/src/libpsl-native/CMakeLists.txt index 3e77b46eed..9193d6fabf 100644 --- a/src/libpsl-native/CMakeLists.txt +++ b/src/libpsl-native/CMakeLists.txt @@ -1,7 +1,8 @@ -cmake_minimum_required(VERSION 2.8.4) +cmake_minimum_required(VERSION 2.8.11) project(PSL-NATIVE) -add_compile_options(-std=c++11 -Wall -Werror) +# Can't use add_compile_options with 2.8.11 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror") set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/../powershell") # test in BUILD_DIR From 36d982f7f53cbfe6fb19d84b4d3ec88058d750c1 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 20 Jun 2016 13:03:54 -0700 Subject: [PATCH 8/8] Detect DEB and RPM package types Instead of assuming DEB for Linux. --- build.psm1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index d01136e2ae..151a33759a 100644 --- a/build.psm1 +++ b/build.psm1 @@ -483,7 +483,7 @@ Built upon .NET Core, it is also a C# REPL. $appxPackagePath = New-AppxPackage -PackageVersion $Version -SourcePath $Source -AssetsPath "$PSScriptRoot\Assets" -Verbose $packages = @($msiPackagePath, $appxPackagePath) - + return $packages } @@ -493,7 +493,17 @@ Built upon .NET Core, it is also a C# REPL. # Decide package output type if (-not $Type) { - $Type = if ($IsLinux) { "deb" } elseif ($IsOSX) { "osxpkg" } + $Type = if ($IsLinux) { + if ($LinuxInfo.ID -match 'ubuntu') { + "deb" + } elseif ($LinuxInfo.ID -match 'centos') { + "rpm" + } else { + throw "Building packages for $($LinuxInfo.PRETTY_NAME) is unsupported!" + } + } elseif ($IsOSX) { + 'osxpkg' + } Write-Warning "-Type was not specified, continuing with $Type" }