Skip to content

Commit

Permalink
add latest xmlsec
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile-sentry committed Nov 11, 2024
1 parent f8b9a8e commit d77699f
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,10 @@ brew_requires =
pkg-config
custom_prebuild = prebuild/libxmlsec1-macos
python_versions = <3.13
[xmlsec==1.3.14]
apt_requires = pkg-config
brew_requires = pkg-config
custom_prebuild = prebuild/xmlsec-1-3-14-deps

[yamlfix==1.3.0]

Expand Down
124 changes: 124 additions & 0 deletions prebuild/xmlsec-1-3-14-deps
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())

0 comments on commit d77699f

Please sign in to comment.