-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8b9a8e
commit d77699f
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/env python3 | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import hashlib | ||
import io | ||
import os.path | ||
import secrets | ||
import subprocess | ||
import tarfile | ||
import tempfile | ||
import urllib.request | ||
|
||
# matches libxml2 from lxml==5.3.0 | ||
XML2_URL = "https://download.gnome.org/sources/libxml2/2.12/libxml2-2.12.9.tar.xz" | ||
XML2_SHA256 = "59912db536ab56a3996489ea0299768c7bcffe57169f0235e7f962a91f483590" | ||
# matches xmlsec from xmlsec==1.3.14 | ||
XMLSEC_URL = ( | ||
"https://github.com/lsh123/xmlsec/releases/download/1.3.4/xmlsec1-1.3.4.tar.gz" | ||
) | ||
XMLSEC_SHA256 = "45ad9078d41ae76844ad2f8651600ffeec0fdd128ead988a8d69e907c57aee75" | ||
|
||
|
||
def _join_env( | ||
*, | ||
name: str, | ||
value: str, | ||
sep: str, | ||
) -> str: | ||
if name in os.environ: | ||
return f"{value}{sep}{os.environ[name]}" | ||
else: | ||
return value | ||
|
||
|
||
def main() -> int: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("prefix") | ||
args = parser.parse_args() | ||
|
||
os.environ["PATH"] = _join_env( | ||
name="PATH", | ||
value=os.path.join(args.prefix, "bin"), | ||
sep=os.pathsep, | ||
) | ||
os.environ["CPPFLAGS"] = _join_env( | ||
name="CPPFLAGS", | ||
value=f'-I{os.path.join(args.prefix, "include")}', | ||
sep=" ", | ||
) | ||
os.environ["LDFLAGS"] = _join_env( | ||
name="LDFLAGS", | ||
value=f'-L{os.path.join(args.prefix, "lib")}', | ||
sep=" ", | ||
) | ||
os.environ["LD_LIBRARY_PATH"] = _join_env( | ||
name="LD_LIBRARY_PATH", | ||
value=os.path.join(args.prefix, "lib"), | ||
sep=os.pathsep, | ||
) | ||
os.environ["PKG_CONFIG_PATH"] = _join_env( | ||
name="PKG_CONFIG_PATH", | ||
value=os.path.join(args.prefix, "lib", "pkgconfig"), | ||
sep=os.pathsep, | ||
) | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
resp = urllib.request.urlopen(XML2_URL) | ||
bts = resp.read() | ||
h = hashlib.sha256(bts).hexdigest() | ||
if not secrets.compare_digest(h, XML2_SHA256): | ||
raise SystemExit(f"checksum mismatch: {(XML2_SHA256, h)=}") | ||
|
||
with tarfile.open(fileobj=io.BytesIO(bts)) as tarf: | ||
tarf.extractall(tmpdir) | ||
h = hashlib.sha256(bts).hexdigest() | ||
|
||
srcroot = os.path.join(tmpdir, "libxml2-2.12.9") | ||
subprocess.check_call( | ||
( | ||
"./configure", | ||
f"--prefix={args.prefix}", | ||
"--disable-silent-rules", | ||
"--with-history", | ||
"--with-icu", | ||
"--without-python", | ||
"--without-lzma", | ||
), | ||
cwd=srcroot, | ||
) | ||
subprocess.check_call(("make", "install"), cwd=srcroot) | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
resp = urllib.request.urlopen(XMLSEC_URL) | ||
bts = resp.read() | ||
h = hashlib.sha256(bts).hexdigest() | ||
if not secrets.compare_digest(h, XMLSEC_SHA256): | ||
raise SystemExit(f"checksum mismatch: {(XMLSEC_SHA256, h)=}") | ||
|
||
with tarfile.open(fileobj=io.BytesIO(bts)) as tarf: | ||
tarf.extractall(tmpdir) | ||
|
||
srcroot = os.path.join(tmpdir, "xmlsec1-1.3.4") | ||
subprocess.check_call( | ||
( | ||
"./configure", | ||
"--disable-dependency-tracking", | ||
f"--prefix={args.prefix}", | ||
"--disable-crypto-dl", | ||
"--disable-apps-crypto-dl", | ||
"--with-nss=no", | ||
"--with-nspr=no", | ||
"--enable-mscrypto=no", | ||
"--enable-mscng=no", | ||
), | ||
cwd=srcroot, | ||
) | ||
subprocess.check_call(("make", "install"), cwd=srcroot) | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
raise SystemExit(main()) |