packages feed

liquidhaskell-0.8.10.7: scripts/generate_testing_ghc_env

#!/usr/bin/env bash

# We do not want to use '-e' here as 'grep' might fail in case of a no-match.

set -u
set -o pipefail

# Generates a temporary testing.env file which resolves some module ambiguity. This is necessary
# because we use 'cabal v2-exec' which pulls packages from the store and the local dist-newstyle
# but at the same time we depend on things like 'liquid-base', but 'base' is automatically added to
# the GHC_ENVIRONMENT when doing 'cabal v2-exec', so we would get an ambiguity error if we do not prune
# base and all the relevant packages from the enviroment.
# For more information see:
# https://downloads.haskell.org/ghc/latest/docs/html/users_guide/packages.html#package-environments

TMP_GHC_ENVIRONMENT_FILE=$(mktemp /tmp/liquid-ghc-enviroment.XXXXXX)
PROJECT_FILE=${1:-cabal.project}

cabal -v0 v2-exec --project-file $PROJECT_FILE $PWD/scripts/dump_ghc_environment > $TMP_GHC_ENVIRONMENT_FILE

# Remove the packages in the set:

conflicting_packages=(
  "ghc-prim"
  "base"
  "vctr"
  "vector"
  "containers"
  "bytestring"
)

for i in "${conflicting_packages[@]}"; do

    regex_query=`printf "^package-id %s-[0-9].*$" $i`

    grep -qE "$regex_query" $TMP_GHC_ENVIRONMENT_FILE
    if [ $? -eq 0 ]
    then
      sed -i.bak -E "/$regex_query/d" $TMP_GHC_ENVIRONMENT_FILE
    fi

done

echo $TMP_GHC_ENVIRONMENT_FILE