Skip to content

Commit 1d9b6b8

Browse files
committed
Add bash script to print the used GHC packages
including their version and license and copyright information, erroring if the license if ever not BSD-3-Clause or BSD-2-Clause
1 parent d33c3cb commit 1d9b6b8

File tree

2 files changed

+130
-21
lines changed

2 files changed

+130
-21
lines changed

src/comp/Makefile

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,25 @@ endif
125125
GHCPROFAUTO = -fprof-auto
126126

127127
PACKAGES = \
128-
-package base \
129-
-package containers \
130-
-package array \
131-
-package mtl \
132-
-package unix \
133-
-package regex-compat \
134-
-package bytestring \
135-
-package directory \
136-
-package process \
137-
-package filepath \
138-
-package time \
139-
-package old-time \
140-
-package old-locale \
141-
-package split \
142-
-package syb \
143-
-package integer-gmp \
144-
-package text \
145-
-package deepseq \
146-
-package strict-concurrency \
147-
$(GHCEXTRAPKGS)
128+
base \
129+
containers \
130+
array \
131+
mtl \
132+
unix \
133+
regex-compat \
134+
bytestring \
135+
directory \
136+
process \
137+
filepath \
138+
time \
139+
old-time \
140+
old-locale \
141+
split \
142+
syb \
143+
integer-gmp \
144+
text \
145+
deepseq \
146+
strict-concurrency \
148147

149148
# GHC can compile either a single file (use GHCCOMPILEFLAGS) or
150149
# in make mode where it follows dependencies (use GHCMAKEFLAGS).
@@ -184,7 +183,7 @@ GHCFLAGS = \
184183
-fno-warn-orphans \
185184
-fno-warn-name-shadowing \
186185
-fno-warn-unused-matches \
187-
$(PACKAGES) \
186+
$(addprefix -package ,$(PACKAGES)) \
188187
$(GHCINCLUDES) \
189188
$(GHCTMP) \
190189

@@ -246,6 +245,10 @@ EXES = $(BSCEXES) $(TCLEXES) $(UTILEXES) $(SHOWRULESEXES)
246245
.PHONY: all
247246
all: $(EXES)
248247

248+
.PHONY: ghc-pkg-info
249+
ghc-pkg-info:
250+
./make-ghc-pkg-info.sh $(PACKAGES) > ghc-pkg-info.txt
251+
249252
BuildVersion.hs:
250253
./update-build-version.sh
251254

src/comp/make-ghc-pkg-info.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#! /usr/bin/env bash
2+
set -euo pipefail
3+
4+
PACKAGES=$@
5+
6+
declare -A arr_id=()
7+
declare -A arr_ver=()
8+
declare -A arr_lic=()
9+
declare -A arr_copyr=()
10+
declare -A arr_deps=()
11+
12+
# Horizontal delimiter between packages in the output
13+
#
14+
DELIM='-------------------------'
15+
16+
# Regex for removing the hash from names like
17+
# syb-0.7.2.4-FBa2dfZrzzu7owkvhCx23j
18+
#
19+
STRIP_HASH_REGEX='^([-[:lower:]]+[[:digit:]]+.[[:digit:]][.[:digit:]]*)-[[:alnum:]][[:alnum:]][[:alnum:]][[:alnum:]]+$'
20+
21+
# Function to add a package to the database and follow its dependencies
22+
#
23+
add_pkg() {
24+
local PKG_ID
25+
local PKG_NAME
26+
local PKG_VER
27+
local PKG_LIC
28+
local PKG_COPYR
29+
local PKG_DEPS
30+
31+
#echo "Looking up $1"
32+
33+
PKG_ID=`ghc-pkg field $1 id --simple-output`
34+
35+
if [[ ${PKG_ID} =~ ${STRIP_HASH_REGEX} ]] ; then
36+
#echo "stripping ${PKG_ID} => ${BASH_REMATCH[1]}"
37+
PKG_NAME=${BASH_REMATCH[1]}
38+
else
39+
PKG_NAME=${PKG_ID}
40+
fi
41+
42+
if [[ ! -v arr_id[${PKG_NAME}] ]] ; then
43+
PKG_VER=`ghc-pkg field $1 version --simple-output`
44+
PKG_LIC=`ghc-pkg field $1 license --simple-output`
45+
PKG_COPYR=`ghc-pkg field $1 copyright --simple-output`
46+
PKG_DEPS=`ghc-pkg field $1 depends --simple-output`
47+
48+
if [ "${PKG_LIC}" != "BSD-3-Clause" ] ; then
49+
if [ "${PKG_LIC}" != "BSD-2-Clause" ] ; then
50+
echo "Unexpected license for ${PKG_ID}: ${PKG_LIC}"
51+
exit 1
52+
fi
53+
fi
54+
55+
arr_id[${PKG_NAME}]="${PKG_ID}"
56+
arr_ver[${PKG_NAME}]="${PKG_VER}"
57+
arr_lic[${PKG_NAME}]="${PKG_LIC}"
58+
arr_copyr[${PKG_NAME}]="${PKG_COPYR}"
59+
arr_deps[${PKG_NAME}]="${PKG_DEPS}"
60+
61+
for dep in ${PKG_DEPS}
62+
do
63+
#echo "Following dep: $dep"
64+
if [[ ${dep} =~ ${STRIP_HASH_REGEX} ]] ; then
65+
#echo "stripping ${dep} => ${BASH_REMATCH[1]}"
66+
dep=${BASH_REMATCH[1]}
67+
fi
68+
add_pkg "${dep}"
69+
done
70+
fi
71+
}
72+
73+
# Add the packages from the command line (and their dependencies)
74+
for i in ${PACKAGES}
75+
do
76+
add_pkg "$i"
77+
done
78+
79+
# Generate the output, starting with a delimiter
80+
echo $DELIM
81+
82+
# For each package in the database
83+
sorted_keys=`echo ${!arr_id[@]} | tr ' ' '\012' | sort | tr '\012' ' '`
84+
for i in ${sorted_keys}
85+
do
86+
STRIP_VER_REGEX="^([-[:lower:]]+)-${arr_ver[$i]}"
87+
if [[ $i =~ ${STRIP_VER_REGEX} ]] ; then
88+
pkg=${BASH_REMATCH[1]}
89+
else
90+
pkg=$i
91+
fi
92+
93+
echo
94+
echo "package: $pkg"
95+
#echo "id: ${arr_id[$i]}"
96+
echo "version: ${arr_ver[$i]}"
97+
echo "license: ${arr_lic[$i]}"
98+
if [[ -n "${arr_copyr[$i]}" ]]; then
99+
echo "copyright: ${arr_copyr[$i]}"
100+
fi
101+
echo
102+
echo $DELIM
103+
done
104+
105+
# Done
106+
exit 0

0 commit comments

Comments
 (0)