Skip to content

Instantly share code, notes, and snippets.

@jeremyd2019
Created April 22, 2024 19:45
Show Gist options
  • Save jeremyd2019/27f079c5134390353123543f58655f7c to your computer and use it in GitHub Desktop.
Save jeremyd2019/27f079c5134390353123543f58655f7c to your computer and use it in GitHub Desktop.
Script to convert msys2's mingw-w64-rust PKGBUILD to build latest beta
#!/usr/bin/env python
import fileinput
import pprint
import re
import tomli
from urllib.request import urlopen
with urlopen("https://static.rust-lang.org/dist/channel-rust-beta.toml") as f:
x = tomli.load(f)
a = [y for y in x['artifacts']['source-code']['target']['*'] if y['url'].endswith('.gz')]
assert(len(a) == 1)
obj = a[0]
obj['version'] = x['pkg']['rustc']['version']
pprint.pprint(obj)
newpkgver = re.sub(r'^(\d+\.\d+\.\d+)-(beta\.\d+) \([^)]*\)$', r'\1\2', obj['version'])
pkgverre = re.compile(r'^(pkgver=)\S*(\s*)$')
pkgrelre = re.compile(r'^(pkgrel=)\S*(\s*)$')
shasumre = re.compile(r"^(sha256sums=\(')[0-9a-fA-F]{64}('\s*)$")
realnamecsrcre = re.compile(r'(\$\{_realname\}c-)\$\{pkgver\}(-src)')
with fileinput.input("mingw-w64-rust/PKGBUILD", encoding="utf-8", inplace=True) as f:
for line in f:
print(realnamecsrcre.sub(r'\g<1>beta\g<2>', shasumre.sub(r'\g<1>' + obj['hash-sha256'] + r'\g<2>', pkgrelre.sub(r'\g<1>1\g<2>', pkgverre.sub(r'\g<1>' + newpkgver + r'\g<2>', line)))), end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment