Commit 5cd6d059 authored by Ben Gamari's avatar Ben Gamari 🐢

build-repo: Avoid contradictory constraints

Fixes #7.
parent f7d0cf4c
Pipeline #10787 failed with stages
in 96 minutes and 42 seconds
......@@ -29,12 +29,15 @@ let
cabal-install ghc
hackage-repo-tool overlay-tool
];
in runCommand "repo" {
nativeBuildInputs = [ makeWrapper ];
} ''
mkdir -p $out/bin
makeWrapper ${./build-repo.sh} $out/bin/build-repo.sh \
--prefix PATH : ${stdenv.lib.makeBinPath deps}
'';
in
runCommand "repo" {
nativeBuildInputs = [ makeWrapper ];
} ''
mkdir -p $out/bin
makeWrapper ${./build-repo.sh} $out/bin/build-repo.sh \
--prefix PATH : ${stdenv.lib.makeBinPath deps}:$out/bin
makeWrapper ${./gen-constraints.py} $out/bin/gen-constraints.py \
--prefix PATH : ${stdenv.lib.makeBinPath deps}:$out/bin
'';
in
build-repo
......@@ -138,24 +138,8 @@ $(cat repo/cabal.project.local)
EOF
}
split_pkg_version() {
package=$(echo $1 | sed 's/\(.\+\)-\([0-9]\+\(\.[0-9]\+\)*\)/\1/')
version=$(echo $1 | sed 's/\(.\+\)-\([0-9]\+\(\.[0-9]\+\)*\)/\2/')
}
build_constraints() {
cat <<EOF
allow-newer: *:base
allow-newer: *:template-haskell
allow-newer: *:time
allow-newer: *:Cabal
allow-newer: *:ghc
EOF
echo "constraints:"
for f in $(ls patches); do
split_pkg_version $(basename $(basename $f .patch) .cabal)
echo " $package ==$version"
done
python3 gen-constraints.py
}
# Build the hackage repository
......
#!/usr/bin/env python3
import re
from pathlib import Path
from typing import NewType, Dict, Set, List
Version = NewType("Version", str)
PkgName = NewType("PkgName", str)
BOOT_PKGS = {
"base",
"template-haskell",
"time",
"Cabal",
"ghc",
} # type: Set[PkgName]
PATCHES = Path('patches')
def split_pkg_version(pkg_name_ver: str):
m = re.match(r'(.+)-([0-9]+(.[0-9]+)*)', pkg_name_ver)
if m is None:
return None
else:
return (m.group(1), m.group(2))
def get_pkg_versions(patches: Path) -> Dict[PkgName, Set[Version]]:
res = {} # type: Dict[PkgName, Set[Version]]
for filename in patches.iterdir():
pkg_name, version = split_pkg_version(filename.stem)
if pkg_name not in res:
res[pkg_name] = set() # type: Set[Version]
res[pkg_name].add(version)
return res
def main():
for pkg in BOOT_PKGS:
print(f"allow-newer: *:{pkg}")
print('constraints:')
pkg_versions = get_pkg_versions(PATCHES)
constraints = [] # type: List[str]
for pkg_name, versions in pkg_versions.items():
versions_str = ' || '.join(f'=={ver}' for ver in versions)
constraints.append(f' {pkg_name} {versions_str}')
print(',\n'.join(constraints))
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment