Skip to content

Instantly share code, notes, and snippets.

@andreasabel
Created December 8, 2021 17:13
Show Gist options
  • Save andreasabel/4ad1c803f8a8a5cc27b97d101c866179 to your computer and use it in GitHub Desktop.
Save andreasabel/4ad1c803f8a8a5cc27b97d101c866179 to your computer and use it in GitHub Desktop.
Extracting "since" information for GHC Warnings from the published documentation
# Andreas Abel, 2021-07-15
# A Makefile to extract 'since' information for GHC warnings from published documentation in html.
# Variables
# GHC versions
oldVersions = 5.04.3 6.0.1 6.2.2 6.4.2 6.6.1 6.8.3 6.10.4 6.12.3 7.0.4 7.4.2 7.6.3 7.8.4 7.10.3
newVersions = 8.0.2 8.2.2 8.4.4 8.6.5 8.8.4 8.10.5 9.0.1
allVersions = $(oldVersions) $(newVersions)
oldHtmls = $(patsubst %,warnings-%.html,$(oldVersions))
newHtmls = $(patsubst %,warnings-%.html,$(newVersions))
allHtmls = $(newHtmls) $(oldHtmls)
oldTxts = $(patsubst %.html,%.txt,$(oldHtmls))
newTxts = $(patsubst %.html,%.txt,$(newHtmls))
allTxts = $(patsubst %.html,%.txt,$(allHtmls))
# List functions
# From https://riptutorial.com/makefile/example/23643/zipping-lists
#
# Example
#
# func = $1-$2
#
# all:
# @echo $(call zipWith,func,$(LIST1),$(LIST2))
#
tail = $(wordlist 2,$(words $1),$1)
zipWith = $(and $(strip $2),$(strip $3),$(call \
$1,$(firstword $2),$(firstword $3)) $(call \
zipWith,$1,$(call tail,$2),$(call tail,$3)))
# onVersionPairs f = zipWith f allVersions (tail allVersions)
onVersionPairs = $(call zipWith,$1,$(allVersions),$(call tail,$(allVersions)))
# Defined shell commands
# Cumulatively supported warnings of version
#
# cumul-2 = cumul cumul-1 warnings-2
cumulate = $(shell cat cumul-$1.txt warnings-$2.txt | sort | uniq > cumul-$2.txt)
# New warnings of version
#
# since-2 = cumul-2 - cumul-1
difference=$(shell comm -13 cumul-$1.txt cumul-$2.txt > since-$2.txt)
#difference=$(shell diff --suppress-common-lines warnings-$1.txt warnings-$2.txt > diff-$1-$2.txt)
# Main goal: report.md
report.md : since Makefile
-rm $@
for i in $(call tail,$(allVersions)); do echo "\`\`\`\n\n# Since $$i\n\n\`\`\`" >> $@; cat since-$$i.txt >>$@; done
since : cumul Makefile
$(call onVersionPairs,difference)
# Accumulate warnings from previous versions
cumul : txts Makefile
cp warnings-$(firstword $(allVersions)).txt cumul-$(firstword $(allVersions)).txt
$(call onVersionPairs,cumulate)
txts : $(allTxts)
# Extract mentioned warnings
$(newTxts) : warnings-%.txt : warnings-%.html Makefile
gsed -r -n 's/.*-W([a-z-]+).*/\1/p' $< | sort | uniq > $@
# grep -P -o -e '-W\K[a-z-]+' $< | sort | uniq > $@
# grep -E -o -e '-W[a-z-]+' $< | sort | uniq > $@
$(oldTxts) : warnings-%.txt : warnings-%.html Makefile
iconv -f ISO-8859-1 -t UTF8 $< | gsed -r -n 's/.*-(W|fwarn-)([a-z-]+).*/\2/p' | sort | uniq > $@
# grep -P -o -e '-fwarn-\K[a-z-]+' $< | sort | uniq > $@
# Download warning documentation
$(newHtmls) : warnings-%.html :
wget https://downloads.haskell.org/~ghc/$*/docs/html/users_guide/using-warnings.html && mv using-warnings.html warnings-$*.html
$(oldHtmls) : warnings-%.html :
wget https://downloads.haskell.org/~ghc/$*/docs/html/users_guide/options-sanity.html && mv options-sanity.html warnings-$*.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment