Skip to content

Commit f7f28a6

Browse files
authored
Merge branch 'master' into upgrade-nixpkgs-module
2 parents 87df70c + 2ccda50 commit f7f28a6

File tree

9 files changed

+107
-143
lines changed

9 files changed

+107
-143
lines changed

.bazelrc.bzlmod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ common --noenable_bzlmod
33

44
common:bzlmod --enable_bzlmod
55
# Note, have to use /// to make Bazel not crash on Windows
6-
common --registry=file:///%workspace%/registry --registry=https://bcr.bazel.build
6+
common:common --registry=file:///%workspace%/registry --registry=https://bcr.bazel.build
7+

.bazelrc.common

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Global Configuration
44
# --------------------
55

6+
# enable common config by default (needed for renovate to ignore the file: registry)
7+
common --config common
8+
69
# Force TLS 1.2. With TLS 1.3, we run into the following error on Darwin.
710
# > No subject alternative DNS name matching github-releases.githubusercontent.com found.
811
# It looks like this is a result of SNI being broken on TLS 1.3 which results

.github/update-ghc.py

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,44 +78,23 @@ def main():
7878

7979
print("found update:", latest_release, file=sys.stderr)
8080

81-
replace = re.compile(
82-
r'^(?P<indent>\s+)\{\s*"version"\s*:\s*"'
83-
+ re.escape(GHC_MAJOR_MINOR + "."),
84-
re.MULTILINE,
85-
)
86-
87-
print(" 1. modify haskell/gen_ghc_bindist.py", file=sys.stderr)
88-
89-
gen_script_path = SCRIPT_PATH.parent.parent.joinpath(
90-
"haskell/gen_ghc_bindist.py"
91-
)
92-
with open(gen_script_path, "r+") as gen:
93-
gen_script = gen.read()
94-
95-
added_version = replace.sub(
96-
rf"""\g<indent>{{ "version": { repr(latest_release) },
97-
\g<indent> "ignore_suffixes": [".bz2", ".lz", ".zip"] }},
98-
\g<0>""",
99-
gen_script,
100-
count=1,
101-
)
102-
103-
if added_version is gen_script:
104-
sys.exit(
105-
f"could not add new version {latest_release} using regex {replace}"
106-
)
107-
108-
gen.truncate(0)
109-
gen.seek(0)
110-
gen.write(added_version)
111-
112-
print(" 2. call haskell/gen_ghc_bindist.py", file=sys.stderr)
113-
114-
check_call([sys.executable, "haskell/gen_ghc_bindist.py"])
115-
116-
if "GITHUB_OUTPUT" in os.environ:
117-
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
118-
print(f"latest={ latest_release }", file=output)
81+
print(" 1. modify haskell/private/ghc_bindist_generated.json", file=sys.stderr)
82+
83+
bindists[latest_release] = {}
84+
85+
bindist_json.truncate(0)
86+
bindist_json.seek(0)
87+
json.dump(bindists, bindist_json)
88+
89+
gen_script_path = SCRIPT_PATH.parent.parent.joinpath("haskell/gen_ghc_bindist.py")
90+
91+
print(" 2. call haskell/gen_ghc_bindist.py", file=sys.stderr)
92+
93+
check_call([sys.executable, "haskell/gen_ghc_bindist.py"])
94+
95+
if "GITHUB_OUTPUT" in os.environ:
96+
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
97+
print(f"latest={ latest_release }", file=output)
11998

12099

121100
if __name__ == "__main__":

.github/workflows/update-ghc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ jobs:
1616
- '9.2'
1717
- '9.4'
1818
- '9.6'
19+
- '9.8'
1920
steps:
2021
- uses: actions/checkout@v4
22+
with:
23+
ref: master
2124
- uses: cachix/install-nix-action@v23
2225
with:
2326
nix_path: nixpkgs=nixpkgs/default.nix

examples/.bazelrc.bzlmod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
common:bzlmod --enable_bzlmod
2-
common --registry=file://%workspace%/../registry --registry=https://bcr.bazel.build
2+
common:common --registry=file://%workspace%/../registry --registry=https://bcr.bazel.build

haskell/gen_ghc_bindist.py

Lines changed: 78 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -10,180 +10,158 @@
1010
from urllib.request import urlopen
1111
from distutils.version import StrictVersion
1212

13-
# All GHC versions we generate.
14-
# `version` is the version number
15-
# `distribution_version` is a corrected name
16-
# (sometimes bindists have errors and are updated by new bindists)
17-
# `ignore_prefixes` is the prefix of files to ignore
18-
# `ignore_suffixes` is the suffix of files to ignore
19-
VERSIONS = [
20-
{ "version": '9.6.3',
21-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
22-
{ "version": "9.6.2",
23-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
24-
{ "version": "9.6.1",
25-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
26-
{ "version": '9.4.6',
27-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
28-
{ "version": '9.4.7',
29-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
30-
{ "version": "9.4.5",
31-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
32-
{ "version": '9.2.8',
33-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
34-
{ "version": "9.2.5",
35-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
36-
{ "version": "9.2.4",
37-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
38-
{ "version": "9.2.3",
39-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
40-
{ "version": "9.2.1",
41-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
42-
{ "version": "9.0.2",
43-
"ignore_prefixes": ["ghc-9.0.2a"],
44-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
45-
{ "version": "9.0.1",
46-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
47-
{ "version": "8.10.7",
48-
"ignore_suffixes": [".bz2", ".lz", ".zip"] },
49-
{ "version": "8.10.4" },
50-
{ "version": "8.10.3" },
51-
{ "version": "8.8.4" },
52-
{ "version": "8.6.5" },
53-
{ "version": "8.4.4" },
54-
{ "version": "8.4.3" },
55-
{ "version": "8.4.2" },
56-
{ "version": "8.4.1" },
57-
{ "version": "8.2.2" },
58-
]
13+
# Sometimes bindists have errors and are updated by new bindists.
14+
# This dict is used to keep a version -> corrected_version mapping.
15+
VERSIONS_CORRECTED = {}
5916

6017
# All architectures we generate.
6118
# bazel: bazel name
6219
# upstream: list of download.haskell.org name
6320
ARCHES = [
64-
{ "bazel": "linux_amd64",
65-
"upstream": ["x86_64-deb8-linux", "x86_64-deb9-linux", "x86_64-deb10-linux"], },
66-
{ "bazel": "linux_arm64",
67-
"upstream": ["aarch64-deb10-linux"], },
68-
{ "bazel": "darwin_amd64",
69-
"upstream": ["x86_64-apple-darwin"] },
70-
{ "bazel": "darwin_arm64",
71-
"upstream": ["aarch64-apple-darwin"] },
72-
{ "bazel": "windows_amd64",
73-
"upstream": ["x86_64-unknown-mingw32"] },
21+
{
22+
"bazel": "linux_amd64",
23+
"upstream": ["x86_64-deb8-linux", "x86_64-deb9-linux", "x86_64-deb10-linux"],
24+
},
25+
{
26+
"bazel": "linux_arm64",
27+
"upstream": ["aarch64-deb10-linux"],
28+
},
29+
{"bazel": "darwin_amd64", "upstream": ["x86_64-apple-darwin"]},
30+
{"bazel": "darwin_arm64", "upstream": ["aarch64-apple-darwin"]},
31+
{"bazel": "windows_amd64", "upstream": ["x86_64-unknown-mingw32"]},
7432
]
7533

7634

7735
# An url to a bindist tarball.
7836
def link_for_tarball(arch, version):
7937
return "https://downloads.haskell.org/~ghc/{ver}/ghc-{ver}-{arch}.tar.xz".format(
80-
ver = version,
81-
arch = arch,
38+
ver=version,
39+
arch=arch,
8240
)
8341

42+
8443
# An url to a version's tarball hashsum file.
8544
# The files contain the hashsums for all arches.
8645
def link_for_sha256_file(version):
87-
return "https://downloads.haskell.org/~ghc/{ver}/SHA256SUMS".format(
88-
ver = version
89-
)
46+
return "https://downloads.haskell.org/~ghc/{ver}/SHA256SUMS".format(ver=version)
47+
9048

9149
# Parses the tarball hashsum file for a distribution version.
9250
def parse_sha256_file(content, version, url):
9351
res = {}
94-
errs = []
52+
53+
prefix = "ghc-{ver}-".format(ver=VERSIONS_CORRECTED.get(version, version))
54+
suffix = ".tar.xz"
55+
9556
for line in content:
9657
# f5763983a26dedd88b65a0b17267359a3981b83a642569b26334423f684f8b8c ./ghc-8.4.3-i386-deb8-linux.tar.xz
9758
(hash, file_) = line.decode().strip().split(" ./")
98-
prefix = "ghc-{ver}-".format(ver = version.get("distribution_version", version['version']))
99-
suffix = ".tar.xz"
100-
101-
# filter ignored files
102-
if any([file_.startswith(p) for p in version.get("ignore_prefixes", [])]) \
103-
or any([file_.endswith(s) for s in version.get("ignore_suffixes", [])]):
104-
continue
10559

10660
if file_.startswith(prefix) and file_.endswith(suffix):
10761
# i386-deb8-linux
108-
name = file_[len(prefix):-len(suffix)]
62+
name = file_[len(prefix) : -len(suffix)]
10963
res[name] = hash
110-
else:
111-
errs.append("Can't parse the sha256 field for {ver}: {entry}".format(
112-
ver = version['version'], entry = line.strip()))
11364

114-
if errs:
115-
eprint("Errors parsing file at " + url + ". Either fix or ignore the lines (ignore_suffixes/ignore_prefixes).")
116-
for e in errs:
117-
eprint(e)
65+
if not res:
66+
eprint(
67+
f"Errors parsing file at {url}. Could not find entries for {prefix}{suffix}"
68+
)
11869
exit(1)
11970

12071
return res
12172

73+
12274
# Print to stderr.
12375
def eprint(mes):
124-
print(mes, file = sys.stderr)
76+
print(mes, file=sys.stderr)
77+
12578

12679
def select_one(xs, ys):
12780
"""Select a single item from xs, prefer the first item also in ys."""
12881
items = [x for x in xs if x in ys]
12982
return items[0] if items else xs[0]
13083

131-
# Main.
132-
if __name__ == "__main__":
84+
85+
def fetch_hashsums(versions):
13386
# Fetch all hashsum files
13487
# grab : { version: { arch: sha256 } }
13588
grab = {}
136-
for ver in VERSIONS:
137-
eprint("fetching " + ver['version'])
138-
url = link_for_sha256_file(ver['version'])
89+
for ver in versions:
90+
eprint("fetching " + ver)
91+
url = link_for_sha256_file(ver)
13992
res = urlopen(url)
14093
if res.getcode() != 200:
14194
eprint("download of {} failed with status {}".format(url, res.getcode()))
14295
sys.exit(1)
14396
else:
144-
grab[ver['version']] = parse_sha256_file(res, ver, url)
97+
grab[ver] = parse_sha256_file(res, ver, url)
14598

14699
# check whether any version is missing arches we need
147100
# errs : { version: set(missing_arches) }
148101
errs = {}
149102
for ver, hashes in grab.items():
150-
real_arches = frozenset(hashes.keys())
151-
upstreams = [select_one(a['upstream'], real_arches) for a in ARCHES]
152-
needed_arches = frozenset(upstreams)
153-
missing_arches = needed_arches.difference(real_arches)
154-
if missing_arches:
155-
errs[ver] = missing_arches
103+
real_arches = frozenset(hashes.keys())
104+
upstreams = [select_one(a["upstream"], real_arches) for a in ARCHES]
105+
needed_arches = frozenset(upstreams)
106+
missing_arches = needed_arches.difference(real_arches)
107+
if missing_arches:
108+
errs[ver] = missing_arches
156109
if errs:
157110
for ver, missing in errs.items():
158111
print(
159112
"WARN: version {ver} is missing hashes for architectures {arches}".format(
160-
ver = ver,
161-
arches = ','.join(missing)),
162-
file=sys.stderr
113+
ver=ver, arches=",".join(missing)
114+
),
115+
file=sys.stderr,
163116
)
164117

118+
return grab
119+
120+
121+
def fetch_bindists(grab):
165122
# fetch the arches we need and create the GHC_BINDISTS dict
166123
# ghc_bindists : { version: { bazel_arch: (tarball_url, sha256_hash) } }
167124
ghc_bindists = {}
168125
for ver, hashes in grab.items():
169126
# { bazel_arch: (tarball_url, sha256_hash) }
170127
arch_dists = {}
171128
for arch in ARCHES:
172-
upstream = select_one(arch['upstream'], hashes)
129+
upstream = select_one(arch["upstream"], hashes)
173130

174131
if upstream in hashes:
175-
arch_dists[arch['bazel']] = (
132+
arch_dists[arch["bazel"]] = (
176133
link_for_tarball(upstream, ver),
177-
hashes[upstream]
134+
hashes[upstream],
178135
)
179136
ghc_bindists[ver] = arch_dists
180137

181-
ghc_versions = { version: ghc_bindists[version] for version in sorted(ghc_bindists.keys(), key=StrictVersion) }
138+
return ghc_bindists
139+
182140

141+
# Main.
142+
if __name__ == "__main__":
183143
working_directory = os.environ.get("BUILD_WORKING_DIRECTORY", ".")
184144

185-
with open(os.path.join(working_directory, "haskell/private/ghc_bindist_generated.json"), "w", encoding="utf-8") as json_file:
186-
json.dump(ghc_versions, json_file, indent=4)
187-
json_file.write('\n')
145+
with open(
146+
os.path.join(working_directory, "haskell/private/ghc_bindist_generated.json"),
147+
"r+",
148+
encoding="utf-8",
149+
) as json_file:
150+
ghc_versions = json.load(json_file)
151+
152+
# All GHC versions we generate.
153+
versions = ghc_versions.keys()
188154

155+
grab = fetch_hashsums(versions)
189156

157+
ghc_bindists = fetch_bindists(grab)
158+
159+
ghc_versions = {
160+
version: ghc_bindists[version]
161+
for version in sorted(ghc_bindists.keys(), key=StrictVersion)
162+
}
163+
164+
json_file.truncate(0)
165+
json_file.seek(0)
166+
json.dump(ghc_versions, json_file, indent=4)
167+
json_file.write("\n")

rules_haskell_nix/.bazelrc.bzlmod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
common:bzlmod --enable_bzlmod
22

33
# Note, have to use /// to make Bazel not crash on Windows
4-
common --registry=file:///%workspace%/../registry --registry=https://bcr.bazel.build
4+
common:common --registry=file:///%workspace%/../registry --registry=https://bcr.bazel.build

rules_haskell_tests/.bazelrc.bzlmod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ common --noenable_bzlmod
44
common:bzlmod --enable_bzlmod
55

66
# Note, have to use /// to make Bazel not crash on Windows
7-
common --registry=file:///%workspace%/../registry --registry=https://bcr.bazel.build
7+
common:common --registry=file:///%workspace%/../registry --registry=https://bcr.bazel.build

tutorial/.bazelrc.bzlmod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
common:bzlmod --enable_bzlmod
2-
common --registry=file://%workspace%/../registry --registry=https://bcr.bazel.build
2+
common:common --registry=file://%workspace%/../registry --registry=https://bcr.bazel.build

0 commit comments

Comments
 (0)