Skip to content

Commit

Permalink
enable cabal
Browse files Browse the repository at this point in the history
  • Loading branch information
shayne-fletcher committed Jan 28, 2024
1 parent fea70c7 commit 3291d3f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 36 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/hlint-from-scratch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # end of every day
- cron: '0 0 * * 1-5' # 00:00 mon-fri
jobs:
hlint-from-scratch-ubuntu:
name: ${{ matrix.os }}
Expand All @@ -17,15 +17,11 @@ jobs:
- uses: actions/checkout@v4
- run: brew install automake
if: matrix.os == 'macos'
- run: cabal update
# - run: cabal new-install cabal-install --overwrite-policy=always
- run: cabal new-install apply-refact
if: matrix.os == 'ubuntu'
- run: |-
echo "GHCLIB_AZURE='1'" >> $GITHUB_ENV
echo "repo_dir=$HOME/project" >> $GITHUB_ENV
- run: echo "GHCLIB_AZURE='1'" >> $GITHUB_ENV
shell: bash
- run: echo "$repo_dir"&&./hlint-from-scratch.sh --init="$repo_dir"
- run: ./hlint-from-scratch.sh --init="$HOME/project"
shell: bash
- run: echo "$repo_dir"&&./hlint-from-scratch.sh --repo-dir="$repo_dir" --ghc-flavor="" --no-cabal --stack-yaml=stack-exact.yaml --resolver=ghc-9.6.4 --no-checkout --no-cabal
- run: cabal update
- run: cabal new-install apply-refact
- run: ./hlint-from-scratch.sh --ghc-flavor="" --stack-yaml=stack-exact.yaml --resolver=ghc-9.6.4 --no-checkout
shell: bash
19 changes: 11 additions & 8 deletions hlint-from-scratch-cabal-build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ cabal new-clean
# cabal new-build all
flags="--ghc-option=-j"
cmd="cabal new-build all $flags"
ffi_inc_path="C_INCLUDE_PATH=$(xcrun --show-sdk-path)/usr/include/ffi"
ffi_inc_path=""
if [ $(uname) == 'Darwin' ]; then
ffi_inc_path="C_INCLUDE_PATH=$(xcrun --show-sdk-path)/usr/include/ffi"
fi
ghc_version_number=$(ghc -V | tail -c 6)
if [[ "$ghc_version_number" == "9.2.2" ]]; then
eval "$ffi_inc_path" "$cmd"
Expand All @@ -190,14 +193,14 @@ if "$with_haddock"; then
eval "cabal" "new-haddock" "all"
fi

# run tests
cabal_project="$build_dir_for_this_ghc/cabal.project"

echo -n > "$build_dir_for_this_ghc"/ghc-lib-test-mini-hlint "cabal -v0 new-run exe:ghc-lib-test-mini-hlint --project-file $cabal_project -- "
echo -n > "$build_dir_for_this_ghc"/ghc-lib-test-mini-compile "cabal -v0 new-run exe:ghc-lib-test-mini-compile --project-file $cabal_project -- "

(cd "ghc-lib-test-mini-hlint-$version_tag" && eval 'cabal' 'new-test' '--test-show-details' 'direct' '--project-file' "$cabal_project" '--test-options="--test-command ../ghc-lib-test-mini-hlint"')
(cd "ghc-lib-test-mini-compile-$version_tag" && eval 'cabal' 'new-test' '--test-show-details' 'direct' '--project-file' "$cabal_project" '--test-options="--test-command ../ghc-lib-test-mini-compile"')
if [ $(uname) == "Darwin" || $(uname) == "Linux"]; then
# these tests have issues on windows
echo -n > "$build_dir_for_this_ghc"/ghc-lib-test-mini-hlint "cabal -v0 new-run exe:ghc-lib-test-mini-hlint --project-file $cabal_project -- "
echo -n > "$build_dir_for_this_ghc"/ghc-lib-test-mini-compile "cabal -v0 new-run exe:ghc-lib-test-mini-compile --project-file $cabal_project -- "
(cd "ghc-lib-test-mini-hlint-$version_tag" && eval 'cabal' 'new-test' '--test-show-details' 'direct' '--project-file' "$cabal_project" '--test-options="--test-command ../ghc-lib-test-mini-hlint"')
(cd "ghc-lib-test-mini-compile-$version_tag" && eval 'cabal' 'new-test' '--test-show-details' 'direct' '--project-file' "$cabal_project" '--test-options="--test-command ../ghc-lib-test-mini-compile"')
fi
(cd "ghc-lib-parser-ex-$version_tag" && eval 'cabal' 'new-test' '--test-show-details' 'direct' '--project-file' "$cabal_project")
(cd "hlint-$version_tag" && eval "cabal new-run exe:hlint" "--project-file" "$cabal_project" "--" "--test")

Expand Down
53 changes: 35 additions & 18 deletions hlint-from-scratch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ args="
"
usage="usage: $prog $args"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

GHC_FLAVOR=""
no_builds=""
no_cabal=""
cabal_with_ghc="ghc-9.4.4"
cabal_with_ghc="$(ghc --version | sed -e 's/The Glorious Glasgow Haskell Compilation System, version //g' -e 's/^/ghc-/g')"
stack_yaml=""
stack_yaml_flag=""
resolver=""
Expand All @@ -81,7 +83,7 @@ while [ $# -gt 0 ]; do
GHC_FLAVOR="${BASH_REMATCH[1]}"
elif [[ "$1" =~ --init=([^[:space:]]+) ]]; then
repo_dir="${BASH_REMATCH[1]}"
./hlint-from-scratch-init.sh --repo-dir="$repo_dir"
"$SCRIPT_DIR"/hlint-from-scratch-init.sh --repo-dir="$repo_dir"
echo "repo-dir \"$repo_dir\" initialized"
echo "next: hlint-from-scratch --ghc-flavor=... ... --repo-dir=$repo_dir"
exit 0
Expand Down Expand Up @@ -240,15 +242,19 @@ fi
if false; then
if [ -z "$GHC_FLAVOR" ]; then
# If the above worked out, update CI.hs.
sed -i '' "s/current = \".*\" -- .*/current = \"$HEAD\" -- $today/g" "$repo_dir"/ghc-lib/CI.hs
if [ $(uname == "Darwin") ]; then
sed -i '' "s/current = \".*\" -- .*/current = \"$HEAD\" -- $today/g" "$repo_dir"/ghc-lib/CI.hs
else
sed -i'' "s/current = \".*\" -- .*/current = \"$HEAD\" -- $today/g" "$repo_dir"/ghc-lib/CI.hs
fi
# Report.
grep "current = .*" "$repo_dir"/ghc-lib/CI.hs
fi
fi

# ghc-lib-parser-ex

cd ../ghc-lib-parser-ex && git checkout .
cd "$repo_dir"/ghc-lib-parser-ex && git checkout .
branch=$(git rev-parse --abbrev-ref HEAD)

# if the flavor indicates ghc's master branch get on
Expand Down Expand Up @@ -292,10 +298,10 @@ if [[ "$build_comp_version" == 9.8.* ]]; then
allow_newer="allow-newer: True"
fi

repo_dir_stripped=$(echo "${repo_dir}" | sed -e "s;^/./;/;g") # peel off leading /c if neccessary for this

if [[ -n "$stack_yaml" ]]; then
echo "Seeding stack-head.yaml from $stack_yaml"
repo_dir=$(echo "${repo_dir}" | sed -e "s;^/./;/;g") # peel off leading /c if neccessary
echo "repo_dir: ${repo_dir}"
# shellcheck disable=SC2002
cat "$stack_yaml" | \
# Delete any pre-existing ghc-lib-parser extra dependency.
Expand All @@ -307,14 +313,14 @@ $allow_newer\n\
# --\n\
extra-deps:\n\
# ghc-lib-parser\n\
- archive: ${repo_dir}/ghc-lib/ghc-lib-parser-${version}.tar.gz;\
- archive: ${repo_dir_stripped}/ghc-lib/ghc-lib-parser-${version}.tar.gz;\
g" | \
sed -e "s;^resolver:.*$;resolver: ${resolver};g" > stack-head.yaml
else
cat > stack-head.yaml <<EOF
resolver: $resolver
extra-deps:
- archive: ${repo_dir}/ghc-lib/ghc-lib-parser-$version.tar.gz
- archive: ${repo_dir_stripped}/ghc-lib/ghc-lib-parser-$version.tar.gz
ghc-options:
"$DOLLAR$everything": -j
"$DOLLAR$locals": -ddump-to-file -ddump-hi -Wall -Wno-name-shadowing -Wunused-imports
Expand All @@ -341,7 +347,7 @@ set -e

# Hlint

cd ../hlint && git checkout .
cd "$repo_dir"/hlint && git checkout .
branch=$(git rev-parse --abbrev-ref HEAD)
# if the flavor indicates ghc's master branch get on hlint's
# 'ghc-next' branch ...
Expand Down Expand Up @@ -378,8 +384,8 @@ resolver: $resolver
packages:
- .
extra-deps:
- archive: $repo_dir/ghc-lib/ghc-lib-parser-$version.tar.gz
- archive: $repo_dir/ghc-lib-parser-ex/ghc-lib-parser-ex-$version.tar.gz
- archive: $repo_dir_stripped/ghc-lib/ghc-lib-parser-$version.tar.gz
- archive: $repo_dir_stripped/ghc-lib-parser-ex/ghc-lib-parser-ex-$version.tar.gz
ghc-options:
"$DOLLAR$everything": -j
"$DOLLAR$locals": -ddump-to-file -ddump-hi -Werror=unused-imports -Werror=unused-local-binds -Werror=unused-top-binds -Werror=orphans
Expand Down Expand Up @@ -448,11 +454,21 @@ fi
# context. Well, never mind; take the approach of constraining the
# bounds exactly. It's kind of more explicitly saying what we mean
# anyway.
sed -i '' "s/^version:.*\$/version: $version/g" hlint.cabal
sed -i '' "s/^.*ghc-lib-parser ==.*\$/ ghc-lib-parser == $version/g" hlint.cabal
sed -i '' "s/^.*ghc-lib-parser-ex >=.*\$/ ghc-lib-parser-ex == $version/g" hlint.cabal
# sarif tests encode the current hlint version number
sed -i '' "s/3.5/$version/g" tests/sarif.test # hack. see issue https://github.com/ndmitchell/hlint/issues/1492
echo "phase test-ghc-9.0.sh in $(pwd)"

if [ $(uname) == "Darwin" ]; then
sed -i '' "s/^version:.*\$/version: $version/g" hlint.cabal
sed -i '' "s/^.*ghc-lib-parser ==.*\$/ ghc-lib-parser == $version/g" hlint.cabal
sed -i '' "s/^.*ghc-lib-parser-ex >=.*\$/ ghc-lib-parser-ex == $version/g" hlint.cabal
# sarif tests encode the current hlint version number
sed -i '' "s/3.5/$version/g" tests/sarif.test # hack. see issue https://github.com/ndmitchell/hlint/issues/1492
else
sed -i'' "s/^version:.*\$/version: $version/g" hlint.cabal
sed -i'' "s/^.*ghc-lib-parser ==.*\$/ ghc-lib-parser == $version/g" hlint.cabal
sed -i'' "s/^.*ghc-lib-parser-ex >=.*\$/ ghc-lib-parser-ex == $version/g" hlint.cabal
# sarif tests encode the current hlint version number
sed -i'' "s/3.5/$version/g" tests/sarif.test # hack. see issue https://github.com/ndmitchell/hlint/issues/1492
fi
eval "stack" "$stack_yaml_flag" "sdist" "." "--tar-dir" "."

# - Generate a cabal.project of
Expand All @@ -463,8 +479,9 @@ eval "stack" "$stack_yaml_flag" "sdist" "." "--tar-dir" "."
# - Depending on the contents of `$with_haddock_flag`. Also,
# - Run ghc-lib-test-mini-hlint, ghc-lib-test-mini-compile and the
# hlint test suite.
tmp_dir=$(mktemp -d)
(cd "$tmp_dir" && hlint-from-scratch-cabal-build-test.sh \
tmp_dir=$HOME/tmp
mkdir -p "$tmp_dir"
(cd "$tmp_dir" && "$SCRIPT_DIR"/hlint-from-scratch-cabal-build-test.sh \
"$cabal_with_ghc_flag" \
--version-tag="$version" \
--ghc-lib-dir="$repo_dir/ghc-lib" \
Expand Down

0 comments on commit 3291d3f

Please sign in to comment.