Skip to content

Commit

Permalink
Scripts to generate Alire manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-Chouteau committed Oct 20, 2023
1 parent 44b0294 commit 4b92814
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
106 changes: 106 additions & 0 deletions utils/gen_gnat_manifests.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4b92814

Please sign in to comment.