From 2c96d280ed473e18e6aca9f3fe4945ba5695ebd5 Mon Sep 17 00:00:00 2001 From: Nikita Bykov <49442273+nikita-bykov@users.noreply.github.com> Date: Fri, 19 Feb 2021 10:20:15 +0300 Subject: [PATCH] [Ubuntu] Rework haskell.sh to install Cabal using GHCup (#2636) * reworked haskell installation * added comment * resolved comments and added symlink * fixed haskell.sh * update haskell.sh * update installation * added error suppressing * reverted ghc intallation * added comments Co-authored-by: Nikita Bykov --- .../SoftwareReport/SoftwareReport.Common.psm1 | 6 +++++ .../SoftwareReport.Generator.ps1 | 1 + images/linux/scripts/installers/haskell.sh | 26 ++++++++++++++----- images/linux/scripts/tests/Haskell.Tests.ps1 | 4 +++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 index 0d5a0d04..62d47590 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 @@ -219,6 +219,12 @@ function Get-GHCVersion { return "GHC $ghcVersion" } +function Get-GHCupVersion { + $(ghcup --version) -match "version v(?\d+(\.\d+){2,})" | Out-Null + $ghcVersion = $Matches.version + return "GHCup $ghcVersion" +} + function Get-CabalVersion { $(cabal --version | Out-String) -match "cabal-install version (?\d+\.\d+\.\d+\.\d+)" | Out-Null $cabalVersion = $Matches.version diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index c1d8af0c..a8654cb7 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -181,6 +181,7 @@ $markdown += New-MDNewLine $markdown += New-MDHeader "Haskell" -Level 3 $markdown += New-MDList -Style Unordered -Lines (@( (Get-GHCVersion), + (Get-GHCupVersion), (Get-CabalVersion), (Get-StackVersion) ) | Sort-Object diff --git a/images/linux/scripts/installers/haskell.sh b/images/linux/scripts/installers/haskell.sh index 206bfe56..725ab8bc 100644 --- a/images/linux/scripts/installers/haskell.sh +++ b/images/linux/scripts/installers/haskell.sh @@ -7,16 +7,30 @@ # Source the helpers for use with the script source $HELPER_SCRIPTS/etc-environment.sh +# Any nonzero value for noninteractive installation +export BOOTSTRAP_HASKELL_NONINTERACTIVE=1 +export GHCUP_INSTALL_BASE_PREFIX=/usr/local +export BOOTSTRAP_HASKELL_GHC_VERSION=0 +ghcup_bin=$GHCUP_INSTALL_BASE_PREFIX/.ghcup/bin +setEtcEnvironmentVariable "BOOTSTRAP_HASKELL_NONINTERACTIVE" $BOOTSTRAP_HASKELL_NONINTERACTIVE + # Install Herbert V. Riedel's PPA for managing multiple version of ghc on ubuntu. # https://launchpad.net/~hvr/+archive/ubuntu/ghc apt-get install -y software-properties-common add-apt-repository -y ppa:hvr/ghc apt-get update +# Install GHCup +curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh > /dev/null 2>&1 || true +export PATH="$ghcup_bin:$PATH" +prependEtcEnvironmentPath $ghcup_bin + # Get 2 latest Haskell Major.Minor versions allGhcVersions=$(apt-cache search "^ghc-" | grep -Po '(\d*\.){2}\d*' | sort --unique --version-sort) ghcMajorMinorVersions=$(echo "$allGhcVersions" | cut -d "." -f 1,2 | sort --unique --version-sort | tail -2) +# We are using apt-get to install ghc, not ghcup, +# because ghc installed through ghcup takes up too much disk space (2GB versus 1GB through apt-get) for version in $ghcMajorMinorVersions; do # Get latest patch version for given Major.Minor one (ex. 8.6.5 for 8.6) and install it exactVersion=$(echo "$allGhcVersions" | grep $version | sort --unique --version-sort | tail -1) @@ -25,16 +39,14 @@ for version in $ghcMajorMinorVersions; do defaultGHCVersion=$exactVersion done -# Get latest cabal version -cabalVersion=$(apt-cache search cabal-install-[0-9] | grep -Po '\d*\.\d*' | sort --unique --version-sort | tail -1) +echo "install cabal..." +ghcup install cabal -apt-get install -y cabal-install-$cabalVersion +chmod -R 777 $GHCUP_INSTALL_BASE_PREFIX/.ghcup +ln -s $GHCUP_INSTALL_BASE_PREFIX/.ghcup /etc/skel/.ghcup +ln -s "/opt/ghc/$defaultGHCVersion/bin/ghc" "/usr/bin/ghc" # Install the latest stable release of haskell stack curl -sSL https://get.haskellstack.org/ | sh -# Create symlink for ghc and cabal in /usr/bin -ln -s "/opt/ghc/$defaultGHCVersion/bin/ghc" "/usr/bin/ghc" -ln -s "/opt/cabal/$cabalVersion/bin/cabal" "/usr/bin/cabal" - invoke_tests "Haskell" \ No newline at end of file diff --git a/images/linux/scripts/tests/Haskell.Tests.ps1 b/images/linux/scripts/tests/Haskell.Tests.ps1 index 45cc2be3..b271cf72 100644 --- a/images/linux/scripts/tests/Haskell.Tests.ps1 +++ b/images/linux/scripts/tests/Haskell.Tests.ps1 @@ -17,6 +17,10 @@ Describe "Haskell" { "$GHCPath --version" | Should -ReturnZeroExitCode } + It "GHCup" { + "ghcup --version" | Should -ReturnZeroExitCode + } + It "Default GHC" { "ghc --version" | Should -ReturnZeroExitCode }