From a395464aa6c0b9ecf030e1a9d07306d84faa19a8 Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Fri, 20 Sep 2024 14:50:22 -0700 Subject: [PATCH] Use tar instead of tarfile to create toolchain tarball --- .github/workflows/package-action.yml | 2 +- CHANGELOG.md | 5 ++++ src/ppbt/__init__.py | 4 +-- src/ppbt/build.py | 44 ++++++++++++---------------- src/ppbt/common.py | 9 ++++-- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/.github/workflows/package-action.yml b/.github/workflows/package-action.yml index 21d68e6..b3652a9 100644 --- a/.github/workflows/package-action.yml +++ b/.github/workflows/package-action.yml @@ -1,4 +1,4 @@ -name: Relenv Python Package +name: Build ppbt python package on: workflow_call: diff --git a/CHANGELOG.md b/CHANGELOG.md index b9e47fb..4592e1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +0.1.7 +===== +- Use tar instead of tarfile to create toolchain tarballs + + 0.1.6 ===== diff --git a/src/ppbt/__init__.py b/src/ppbt/__init__.py index ec6daea..e134309 100644 --- a/src/ppbt/__init__.py +++ b/src/ppbt/__init__.py @@ -3,8 +3,6 @@ """ Portable Python Build Toolchains. """ -from .common import environ, extract - -__version__ = "0.1.6" +from .common import __version__, environ, extract ALL = ("environ", "extract") diff --git a/src/ppbt/build.py b/src/ppbt/build.py index 339b45a..abfe83f 100644 --- a/src/ppbt/build.py +++ b/src/ppbt/build.py @@ -24,7 +24,6 @@ CT_NG_VER = "1.26.0" CT_URL = "http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-{version}.tar.bz2" CT_GIT_REPO = "https://github.com/crosstool-ng/crosstool-ng.git" -TC_URL = "https://{hostname}/relenv/{version}/toolchain/{host}/{triplet}.tar.xz" CICD = "CI" in os.environ PATCHELF_VERSION = "0.18.0" PATCHELF_SOURCE = ( @@ -308,37 +307,32 @@ def build_ppbt(branch=None, use_tempdir=True): subprocess.run(["make"]) shutil.copy(source / "src" / "patchelf", build / triplet / "bin" / "patchelf") - os.chdir(build) archive = f"{ triplet }.tar.xz" record = f"{ triplet }.tar.xz.record" - print(f"Archive is {archive}") + cmd = ["tar", "-C", f"{ build }", "-cJf", f"{ archive }", f"{ triplet }"] + subprocess.run(cmd) + + # XXX: Figure out why things break when using the tarfile module. with open(record, "w") as rfp: rwriter = csv.writer(rfp) - with tarfile.open(archive, mode="w:xz", dereference=True) as fp: - for root, _dirs, files in os.walk(archdir): - relroot = pathlib.Path(root).relative_to(build) - for f in files: - print(f"Archive {relroot} / {f}") - relpath = relroot / f - with open(relpath, "rb") as dfp: - data = dfp.read() - hsh = ( - base64.urlsafe_b64encode(hashlib.sha256(data).digest()) - .rstrip(b"=") - .decode() - ) - hashpath = str( - pathlib.Path("ppbt") / "_toolchain" / relpath - ) - rwriter.writerow([hashpath, f"sha256={hsh}", len(data)]) - try: - fp.add(relpath, relpath, recursive=False) - except FileNotFoundError: - print(f"File not found while archiving: {relpath}") + for root, _dirs, files in os.walk(archdir): + relroot = pathlib.Path(root).relative_to(build) + for f in files: + print(f"Archive {relroot} / {f}") + relpath = relroot / f + with open(relpath, "rb") as fp: + data = fp.read() + hsh = ( + base64.urlsafe_b64encode(hashlib.sha256(data).digest()) + .rstrip(b"=") + .decode() + ) + hashpath = str(pathlib.Path("ppbt") / "_toolchain" / relpath) + rwriter.writerow([hashpath, f"sha256={hsh}", len(data)]) print(f"Copying {archive} to {toolchain}") - print(f"Copying {record} to {toolchain}") shutil.copy(archive, toolchain) + print(f"Copying {record} to {toolchain}") shutil.copy(record, toolchain) finally: # if archdir and archdir.exists(): diff --git a/src/ppbt/common.py b/src/ppbt/common.py index a544ba6..b377ef2 100644 --- a/src/ppbt/common.py +++ b/src/ppbt/common.py @@ -11,14 +11,18 @@ from .build import build_arch, extract_archive, get_triplet +__version__ = "0.1.7" + triplet = get_triplet(build_arch()) archive = pathlib.Path(__file__).parent / "_toolchain" / f"{triplet}.tar.xz" toolchain = pathlib.Path(__file__).parent / "_toolchain" / triplet toolchain_root = pathlib.Path(__file__).parent / "_toolchain" - -distinfo = pathlib.Path(__file__).resolve().parent.parent / "ppbt-0.1.0.dist-info" +# This is not reliable, the version can be modified by setuptools at build time. +distinfo = ( + pathlib.Path(__file__).resolve().parent.parent / f"ppbt-{__version__}.dist-info" +) log = logging.getLogger(__name__) @@ -35,6 +39,7 @@ def extract(overwrite=False): record = distinfo / "RECORD" if record.exists(): records = [] + log.info("Update pkg metadata") with open(record, "r") as fp: for row in csv.reader(fp): records.append(row)