From 4b9281427ec64daecac04f781ba0a3b2f16af6bd Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Thu, 19 Oct 2023 13:34:09 +0200 Subject: [PATCH] Scripts to generate Alire manifests --- README.md | 9 +++ utils/gen_gnat_manifests.py | 106 ++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100755 utils/gen_gnat_manifests.py diff --git a/README.md b/README.md index f43085b..e5af352 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,12 @@ write a spec is to start from an existing one. A good starting point would be - First, change the `version`, `tarball` and, `source_pkg_build` url - Modify the list of `build_deps`, you probably need at least `gcc`. - Change the configure/make options + +# Publishing to the Alire index + +A [little script](utils/gen_gnat_manifests.py) is available to speedup the +process of publising GNAT FSF package to the Alire index. + +Edit the PKG_VERSION and CRATE_VERSION constant and then run the script to +generate all the GNAT manifests. The script also checks the correctness of +sha256 hashes. diff --git a/utils/gen_gnat_manifests.py b/utils/gen_gnat_manifests.py new file mode 100755 index 0000000..f67fa91 --- /dev/null +++ b/utils/gen_gnat_manifests.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 + +import wget +import subprocess +import sys +import tempfile +import os +import shutil + +PKG_VERSION = "13.2.0-1" +CRATE_VERSION = "13.2.1" + +targets = { + "x86_64": {"crate": "gnat_native", "description": "Native"}, + "arm-elf": {"crate": "gnat_arm_elf", "description": "ARM cross-compiler"}, + "avr-elf": {"crate": "gnat_avr_elf", "description": "RISC-V cross-compiler"}, + "riscv64-elf": {"crate": "gnat_riscv64_elf", "description": "AVR cross-compiler"}, +} + + +def check_sha256(package): + base_url = f"https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/" + pkg_url = base_url + package + sha_file = package + ".sha256" + sha_url = base_url + sha_file + + parent_dir = os.getcwd() + temp_dir = tempfile.mkdtemp() + try: + os.chdir(temp_dir) + print(f"Downloading {pkg_url}") + wget.download(pkg_url) + print() + print(f"Downloading {sha_url}") + wget.download(sha_url) + print() + + sha256_hash = ( + subprocess.check_output(["sha256sum", package]) + .decode("utf-8") + .split(" ")[0] + ) + + with open(sha_file, "r", encoding="utf-8") as file: + sha256_hash_from_release = file.read() + + if sha256_hash != sha256_hash_from_release: + print(f"invalid sha256 for {package}:") + print(f" From GitHub release: {sha256_hash_from_release}") + print(f" Actual : {sha256_hash}") + sys.exit(1) + finally: + os.chdir(parent_dir) + shutil.rmtree(temp_dir) + + return sha256_hash + + +for target, params in targets.items(): + CRATE = params["crate"] + TARGET_DESC = params["description"] + + linux_host = "linux" if target == "x86_64" else "linux64" + linux_package = f"gnat-{target}-{linux_host}-{PKG_VERSION}.tar.gz" + windows_package = f"gnat-{target}-windows64-{PKG_VERSION}.tar.gz" + macos_package = f"gnat-{target}-darwin-{PKG_VERSION}.tar.gz" + + linux_sha256 = check_sha256(linux_package) + windows_sha256 = check_sha256(windows_package) + macos_sha256 = check_sha256(macos_package) + + MANIFEST_CONTENT = f""" +name = "{CRATE}" +version = "{CRATE_VERSION}" +provides = ["gnat={CRATE_VERSION}"] +description = "The GNAT Ada compiler - {TARGET_DESC}" +maintainers = ["chouteau@adacore.com"] +maintainers-logins = ["Fabien-Chouteau"] +licenses = "GPL-3.0-or-later AND GPL-3.0-or-later WITH GCC-exception-3.1" + +auto-gpr-with = false + +[configuration] +disabled = true + +[environment] +PATH.prepend = "${{CRATE_ROOT}}/bin" + +[origin."case(os)".linux."case(host-arch)".x86-64] +url = "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/{linux_package}" +hashes = ["sha256:{linux_sha256}"] + +[origin."case(os)".windows."case(host-arch)".x86-64] +url = "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/{windows_package}" +hashes = ["sha256:{windows_sha256}"] + +[origin."case(os)".macos."case(host-arch)".x86-64] +url = "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/{macos_package}" +hashes = ["sha256:{macos_sha256}"] +""" + + MANIFEST_DIR = os.path.join("index", CRATE[0:2], CRATE) + MANIFEST_FILE = os.path.join(MANIFEST_DIR, f"{CRATE}-{CRATE_VERSION}.toml") + os.makedirs(MANIFEST_DIR, exist_ok=True) + with open(MANIFEST_FILE, "w", encoding="utf-8") as file: + file.write(MANIFEST_CONTENT)