From 3291d3f990f87bd87a24bd2e6fa8fdc7876d9be2 Mon Sep 17 00:00:00 2001 From: Shayne Fletcher Date: Sun, 28 Jan 2024 18:46:18 -0500 Subject: [PATCH] enable cabal --- .github/workflows/hlint-from-scratch.yml | 16 +++---- hlint-from-scratch-cabal-build-test.sh | 19 +++++---- hlint-from-scratch.sh | 53 ++++++++++++++++-------- 3 files changed, 52 insertions(+), 36 deletions(-) diff --git a/.github/workflows/hlint-from-scratch.yml b/.github/workflows/hlint-from-scratch.yml index 71acdf4..ac1cbf7 100644 --- a/.github/workflows/hlint-from-scratch.yml +++ b/.github/workflows/hlint-from-scratch.yml @@ -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 }} @@ -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 diff --git a/hlint-from-scratch-cabal-build-test.sh b/hlint-from-scratch-cabal-build-test.sh index eedbd22..f21edd9 100755 --- a/hlint-from-scratch-cabal-build-test.sh +++ b/hlint-from-scratch-cabal-build-test.sh @@ -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" @@ -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") diff --git a/hlint-from-scratch.sh b/hlint-from-scratch.sh index 1b4eb7d..1210c84 100755 --- a/hlint-from-scratch.sh +++ b/hlint-from-scratch.sh @@ -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="" @@ -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 @@ -240,7 +242,11 @@ 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 @@ -248,7 +254,7 @@ 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 @@ -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. @@ -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 <=.*\$/ 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 @@ -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" \