Skip to content

Commit

Permalink
stack is removed from the hlint steps
Browse files Browse the repository at this point in the history
  • Loading branch information
shayne-fletcher committed Jul 28, 2024
1 parent ffd8235 commit 01e64c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 205 deletions.
30 changes: 9 additions & 21 deletions hlint-from-scratch-cabal-build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ opts:
"
usage="usage: $prog ARGS"

ghc_version="$(ghc --version | sed -e 's/The Glorious Glasgow Haskell Compilation System, version //g' -e 's/^/ghc-/g')"
ghc_version="ghc-$(echo -n "$(ghc --numeric-version)")"
version_tag=""
ghc_lib_dir=""
ghc_lib_parser_ex_dir=""
Expand Down Expand Up @@ -89,14 +89,6 @@ if [ -d "$HOME/$ghc_version" ]; then
export PATH
fi

# Make sure cabal-install is up-to-date with the most recent
# available. At this time there aren't build plans for compilers >
# ghc-9.2.4.
# (PATH=$HOME/ghc-9.2.4/bin:$PATH; export PATH && \
# cabal update && \
# cabal new-install cabal-install --overwrite-policy=always \
# )

echo "cabal-install: $(which cabal)"
echo "cabal-install version: $(cabal -V)"
echo "ghc: $(which ghc)"
Expand Down Expand Up @@ -163,7 +155,6 @@ fi
# (reference https://cabal.readthedocs.io/en/3.8/index.html)
constraints="constraints: $extra_constraints hlint +ghc-lib, ghc-lib-parser-ex -auto -no-ghc-lib, ghc-lib $threaded_rts, ghc-lib-parser $threaded_rts"

cat > cabal.project<<EOF
cat > cabal.project<<EOF
packages: */*.cabal
$allow_newer
Expand Down Expand Up @@ -202,18 +193,15 @@ fi

# cabal new-haddock all
if "$with_haddock"; then
eval "cabal" "new-haddock" "all"
eval "cabal" "haddock" "all"
fi

cabal_project="$build_dir_for_this_ghc/cabal.project"
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")
cabal_project="$build_dir_for_this_ghc"/cabal.project
echo -n > "$build_dir_for_this_ghc"/ghc-lib-test-mini-hlint "cabal run exe:ghc-lib-test-mini-hlint --project-dir .. -- "
echo -n > "$build_dir_for_this_ghc"/ghc-lib-test-mini-compile "cabal run exe:ghc-lib-test-mini-compile --project-dir .. -- "
(cd ghc-lib-test-mini-hlint-"$version_tag" && eval 'cabal' 'test' '--project-dir' '..' '--test-show-details' 'direct' '--test-options="--color always --test-command ../ghc-lib-test-mini-hlint"')
(cd ghc-lib-test-mini-compile-"$version_tag" && eval 'cabal' 'test' '--project-dir' '..' '--test-show-details' 'direct' '--test-options="--color always --test-command ../ghc-lib-test-mini-compile"')
(cd ghc-lib-parser-ex-"$version_tag" && eval 'cabal' 'test' '--project-dir' '..' '--test-show-details' 'direct' '--test-options="--color always"')
(cd hlint-"$version_tag" && eval 'cabal' 'run' 'exe:hlint' '--project-dir' '..' '--' '--test')

exit 0
201 changes: 17 additions & 184 deletions hlint-from-scratch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ args="
--repo-dir=ARG
A directory of git clones. Defaults to $HOME/project.
--stack-yaml=ARG
Stack configuration file.
--resolver=ARG
Stack resolver.
--matrix-build
Invoke matrix build behaviors.
Expand Down Expand Up @@ -64,11 +58,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
GHC_FLAVOR=""
no_builds=""
no_cabal=""
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=""
resolver_flag=""
cabal_with_ghc="$(echo -n "ghc-$(ghc --numeric-version)")"
repo_dir="$HOME/project"
with_haddock_flag="--with-hadock"
no_threaded_rts=false
Expand All @@ -89,12 +79,6 @@ while [ $# -gt 0 ]; do
exit 0
elif [[ "$1" =~ --repo-dir=([^[:space:]]+) ]]; then
repo_dir="${BASH_REMATCH[1]}"
elif [[ "$1" =~ --stack-yaml=([^[:space:]]+) ]]; then
stack_yaml="${BASH_REMATCH[1]}"
stack_yaml_flag="--stack-yaml $stack_yaml"
elif [[ "$1" =~ --resolver=([^[:space:]]+) ]]; then
resolver="${BASH_REMATCH[1]}"
resolver_flag="--resolver $resolver"
elif [[ "$1" =~ --cabal-with-ghc=([^[:space:]]+) ]]; then
cabal_with_ghc="${BASH_REMATCH[1]}"
elif [ "$1" = "--no-checkout" ]; then
Expand Down Expand Up @@ -134,10 +118,6 @@ set -u

echo "uname: $(uname)"
echo "ghc-flavor: $GHC_FLAVOR"
echo "stack-yaml: $stack_yaml"
echo "stack-yaml flag: $stack_yaml_flag"
echo "resolver: $resolver"
echo "resolver flag: $resolver_flag"
echo "repo-dir: $repo_dir"
echo "no-builds: $no_builds"
echo "no-cabal: $no_cabal"
Expand All @@ -147,22 +127,10 @@ echo "no-threaded-rts: $no_threaded_rts"
echo "no-threaded-rts-flag: $no_threaded_rts_flag"
echo "threaded-rts: \"$threaded_rts\""

packages="--package extra --package optparse-applicative"
runhaskell="stack runhaskell $packages"
DOLLAR="$"
locals="locals"
everything="everything"

# If there's a new release, let's have it.
if true; then
# cd "$repo_dir/stack"
# git fetch origin && git merge origin/master
# stack install
:
else
stack upgrade # Upgrade to the latest official
fi

cd "$repo_dir"/ghc-lib

git checkout ghc-next
Expand All @@ -175,9 +143,7 @@ fi

if ! [[ -d ./ghc ]]; then
echo "There is no ghc checkout here to update."
echo "Building with ghc-flavor 'ghc-master' to get started."
eval "$runhaskell $stack_yaml_flag $resolver_flag CI.hs -- $stack_yaml_flag $resolver_flag --ghc-flavor ghc-master"
echo "Now restarting build at the latest GHC commit."
exit 1
fi

# It's common for the git fetch step to report errors of the form
Expand Down Expand Up @@ -223,18 +189,6 @@ else
version="$flavor"".""$(date -u +'%Y%m%d')"
fi

# Set these both to false for quick iteration. Set false/true for
# matrix builds.
if false; then
rm -rf ~/.stack/programs/x86_64-osx/"$resolver"
:
fi
if $matrix_build; then
set +e
rm -rf ~/.stack/snapshots/x86_64-osx/
set -e
fi

# ghc-lib

cmd="cabal run exe:ghc-lib-build-tool -- $no_checkout_flag $no_builds --ghc-flavor "
Expand All @@ -256,18 +210,9 @@ if [ -z "$GHC_FLAVOR" ]; then
grep "current = .*" "$repo_dir"/ghc-lib/CI.hs
fi

ghc_lib_parser_sha256=""
if [[ $(uname) == 'Darwin' ]]; then
sha_ghc_lib_parser="$(shasum -a 256 "$repo_dir"/ghc-lib/ghc-lib-parser-"$version".tar.gz | awk '{ print $1 }')"
ghc_lib_parser_sha256="sha256: \"${sha_ghc_lib_parser}\""
fi

# ghc-lib-parser-ex

cd "$repo_dir"/ghc-lib-parser-ex && git checkout .
if [ -z "$ghc_lib_parser_sha256" ]; then
rm -f *.yaml.lock
fi

branch=$(git rev-parse --abbrev-ref HEAD)

Expand Down Expand Up @@ -295,92 +240,19 @@ else
fi
fi

# If a resolver hasn't been set, set it now to this.
[[ -z "$resolver" ]] && resolver=nightly-2022-08-04 # ghc-9.2.4

# Record the ghc-version (e.g. 9.8.1). Since this is the first time
# calling stack it will pause for a while to setup here.
build_comp_version="$(stack $stack_yaml_flag $resolver_flag --silent exec -- ghc --version | sed 's/The Glorious Glasgow Haskell Compilation System, version //g')"

# This an elaborate step to create a config file'stack-head.yaml'.
#
# If a stack-yaml argument was provided, seed its contents from it
# otherwise, assume a curated $resolver and create it from scratch.

# Enable 'allow-newer' if using ghc-9.10.1.
allow_newer=""
if [[ "$build_comp_version" == 9.10.* ]]; then
allow_newer="allow-newer: True"
fi

# windows hack: repo_dir_stripped is the path with ^/[a-z]/ removed
# e.g. /c/users/... -> /users/...
repo_dir_stripped=$(echo "${repo_dir}" | sed -e "s;^/./;/;g")

cat > cabal.project<<EOF
allow-newer: ghc-lib-parser-ex:ghc-lib-parser
allow-older: ghc-lib-parser-ex:ghc-lib-parser
packages:
./ghc-lib-parser-ex.cabal
$(pwd)/../ghc-lib/ghc-lib-parser/ghc-lib-parser.cabal
../ghc-lib/ghc-lib-parser/ghc-lib-parser.cabal
EOF

# if [[ -n "$stack_yaml" ]]; then
# echo "Seeding stack-head.yaml from $stack_yaml"
# # shellcheck disable=SC2002
# cat "$stack_yaml" | \
# # Delete any pre-existing ghc-lib-parser extra dependency.
# sed -e "s;^.*ghc-lib-parser.*$;;g" | \
# sed -e "s;^extra-deps:$;\
# # enable ghc-9.8.1 as a build compiler (base-4.19.0)\n\
# # --\n\
# $allow_newer\n\
# # --\n\
# extra-deps:\n\
# - archive: ${repo_dir_stripped}/ghc-lib/ghc-lib-parser-${version}.tar.gz\n\
# ${ghc_lib_parser_sha256};\
# g" | \
# sed -e "s;^resolver:.*$;resolver: ${resolver};g" > stack-head.yaml
# else
# cat > stack-head.yaml <<EOF
# resolver: $resolver
# extra-deps:
# - archive: ${repo_dir_stripped}/ghc-lib/ghc-lib-parser-${version}.tar.gz\n\
# ${ghc_lib_parser_sha256};\
# ghc-options:
# "$DOLLAR$everything": -j
# "$DOLLAR$locals": -ddump-to-file -ddump-hi -Wall -Wno-name-shadowing -Wunused-imports
# flags:
# ghc-lib-parser:
# threaded-rts: $threaded_rts
# ghc-lib-parser-ex:
# auto: false
# no-ghc-lib: false
# packages:
# - .
# EOF
# fi

stack_yaml=stack-head.yaml
stack_yaml_flag="--stack-yaml $stack_yaml"
# No need to pass $resolver_flag here, we fixed the resolver in
# 'stack-head.yaml'.
# cat "$stack_yaml"
#eval "$runhaskell $stack_yaml_flag CI.hs -- $no_builds $stack_yaml_flag --version-tag $version"
cabal run exe:ghc-lib-parser-ex-build-tool -- --version-tag $version

ghc_lib_parser_ex_sha256=""
if [ $(uname) == 'Darwin' ]; then
sha_ghc_lib_parser_ex=$(shasum -a 256 "$repo_dir"/ghc-lib-parser-ex/ghc-lib-parser-ex-"$version".tar.gz | awk '{ print $1 }')
ghc_lib_parser_ex_sha256="sha256: \"${sha_ghc_lib_parser_ex}\""
fi

# Hlint

cd "$repo_dir"/hlint && git checkout .
if [ -z "$ghc_lib_parser_sha256" ] || [ -z "$ghc_lib_parser_ex_sha256" ]; then
rm -f *.yaml.lock
fi

branch=$(git rev-parse --abbrev-ref HEAD)
# if the flavor indicates ghc's master branch get on hlint's
Expand All @@ -404,57 +276,18 @@ else
fi
fi

# We're stuck with only curated resolvers for hlint at this time.
if [[ -z "$GHC_FLAVOR" \
|| "$GHC_FLAVOR" == "ghc-master" \
|| "$GHC_FLAVOR" == "ghc-9.10.1"
]]; then
# ghc-flavor >= ghc-master
resolver=lts-22.19 # ghc-9.6.4 (and it must provide os-string)
else
resolver=lts-21.6 # ghc-9.4.5
fi

# Currently in sync with 'hlint/stack.yaml'.

cat > stack-head.yaml <<EOF
resolver: $resolver
# Why 'allow-older'?
# ghc-lib-parser versions of the form 0.x for example require this.
cat > cabal.project<<EOF
allow-newer: ghc-lib-parser-ex:ghc-lib-parser, hlint:ghc-lib-parser-ex, hlint:ghc-lib-parser
allow-older: ghc-lib-parser-ex:ghc-lib-parser, hlint:ghc-lib-parser-ex, hlint:ghc-lib-parser
packages:
- .
extra-deps:
- os-string-2.0.3
- unix-2.8.5.1
- directory-1.3.8.5
- process-1.6.20.0
- filepath-1.5.2.0
- Win32-2.14.0.0
- time-1.12.2
- archive: ${repo_dir_stripped}/ghc-lib/ghc-lib-parser-${version}.tar.gz
${ghc_lib_parser_sha256}
- archive: ${repo_dir_stripped}/ghc-lib-parser-ex/ghc-lib-parser-ex-$version.tar.gz
${ghc_lib_parser_ex_sha256}
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
flags:
hlint:
ghc-lib: true
ghc-lib-parser:
threaded-rts: $threaded_rts
ghc-lib-parser-ex:
auto: false
no-ghc-lib: false
directory:
os-string: true
unix:
os-string: true
Win32:
os-string: true
# Allow out-of-bounds ghc-lib-parser and ghc-lib-parser-ex.
allow-newer: true
./hlint.cabal
../ghc-lib-parser-ex/ghc-lib-parser-ex.cabal
../ghc-lib/ghc-lib-parser/ghc-lib-parser.cabal
EOF

# phase: hlint: stack build/test
# phase: hlint: build/test
#if true; then
if [ true ]; then
# if ! [ "$no_builds" == --no-builds ]; then
Expand All @@ -466,18 +299,18 @@ if [ true ]; then
fi

# Build hlint.
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "stack" "$stack_yaml_flag" "build"
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "cabal" "build" "--ghc-options=-j" "exe:hlint"

# Run its tests.
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "stack" "$stack_yaml_flag" "run" "--" "--test"
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "cabal" "run" "exe:hlint" "--" "--test"

# Test there are no changes to 'hints.md'.
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "stack" "$stack_yaml_flag" "run" "--" "hlint" "--generate-summary"
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "cabal" "run" "exe:hlint" "--" "hlint" "--generate-summary"

git diff --exit-code hints.md

# Run it on its own source.
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "stack" "$stack_yaml_flag" "run" "--" "src"
eval "C_INCLUDE_PATH=$C_INCLUDE_PATH" "cabal" "run" "exe:hlint" "--" "src"
fi

# --
Expand Down Expand Up @@ -512,7 +345,7 @@ else
# 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" "."
eval "cabal" "sdist" "-o" "."

# - Generate a cabal.project of
# - ghc-lib, ghc-lib-parser-ex, examples, hlint
Expand Down

0 comments on commit 01e64c5

Please sign in to comment.