Skip to content

Commit 4b92814

Browse files
Scripts to generate Alire manifests
1 parent 44b0294 commit 4b92814

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ write a spec is to start from an existing one. A good starting point would be
4444
- First, change the `version`, `tarball` and, `source_pkg_build` url
4545
- Modify the list of `build_deps`, you probably need at least `gcc`.
4646
- Change the configure/make options
47+
48+
# Publishing to the Alire index
49+
50+
A [little script](utils/gen_gnat_manifests.py) is available to speedup the
51+
process of publising GNAT FSF package to the Alire index.
52+
53+
Edit the PKG_VERSION and CRATE_VERSION constant and then run the script to
54+
generate all the GNAT manifests. The script also checks the correctness of
55+
sha256 hashes.

utils/gen_gnat_manifests.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python3
2+
3+
import wget
4+
import subprocess
5+
import sys
6+
import tempfile
7+
import os
8+
import shutil
9+
10+
PKG_VERSION = "13.2.0-1"
11+
CRATE_VERSION = "13.2.1"
12+
13+
targets = {
14+
"x86_64": {"crate": "gnat_native", "description": "Native"},
15+
"arm-elf": {"crate": "gnat_arm_elf", "description": "ARM cross-compiler"},
16+
"avr-elf": {"crate": "gnat_avr_elf", "description": "RISC-V cross-compiler"},
17+
"riscv64-elf": {"crate": "gnat_riscv64_elf", "description": "AVR cross-compiler"},
18+
}
19+
20+
21+
def check_sha256(package):
22+
base_url = f"https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/"
23+
pkg_url = base_url + package
24+
sha_file = package + ".sha256"
25+
sha_url = base_url + sha_file
26+
27+
parent_dir = os.getcwd()
28+
temp_dir = tempfile.mkdtemp()
29+
try:
30+
os.chdir(temp_dir)
31+
print(f"Downloading {pkg_url}")
32+
wget.download(pkg_url)
33+
print()
34+
print(f"Downloading {sha_url}")
35+
wget.download(sha_url)
36+
print()
37+
38+
sha256_hash = (
39+
subprocess.check_output(["sha256sum", package])
40+
.decode("utf-8")
41+
.split(" ")[0]
42+
)
43+
44+
with open(sha_file, "r", encoding="utf-8") as file:
45+
sha256_hash_from_release = file.read()
46+
47+
if sha256_hash != sha256_hash_from_release:
48+
print(f"invalid sha256 for {package}:")
49+
print(f" From GitHub release: {sha256_hash_from_release}")
50+
print(f" Actual : {sha256_hash}")
51+
sys.exit(1)
52+
finally:
53+
os.chdir(parent_dir)
54+
shutil.rmtree(temp_dir)
55+
56+
return sha256_hash
57+
58+
59+
for target, params in targets.items():
60+
CRATE = params["crate"]
61+
TARGET_DESC = params["description"]
62+
63+
linux_host = "linux" if target == "x86_64" else "linux64"
64+
linux_package = f"gnat-{target}-{linux_host}-{PKG_VERSION}.tar.gz"
65+
windows_package = f"gnat-{target}-windows64-{PKG_VERSION}.tar.gz"
66+
macos_package = f"gnat-{target}-darwin-{PKG_VERSION}.tar.gz"
67+
68+
linux_sha256 = check_sha256(linux_package)
69+
windows_sha256 = check_sha256(windows_package)
70+
macos_sha256 = check_sha256(macos_package)
71+
72+
MANIFEST_CONTENT = f"""
73+
name = "{CRATE}"
74+
version = "{CRATE_VERSION}"
75+
provides = ["gnat={CRATE_VERSION}"]
76+
description = "The GNAT Ada compiler - {TARGET_DESC}"
77+
maintainers = ["[email protected]"]
78+
maintainers-logins = ["Fabien-Chouteau"]
79+
licenses = "GPL-3.0-or-later AND GPL-3.0-or-later WITH GCC-exception-3.1"
80+
81+
auto-gpr-with = false
82+
83+
[configuration]
84+
disabled = true
85+
86+
[environment]
87+
PATH.prepend = "${{CRATE_ROOT}}/bin"
88+
89+
[origin."case(os)".linux."case(host-arch)".x86-64]
90+
url = "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/{linux_package}"
91+
hashes = ["sha256:{linux_sha256}"]
92+
93+
[origin."case(os)".windows."case(host-arch)".x86-64]
94+
url = "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/{windows_package}"
95+
hashes = ["sha256:{windows_sha256}"]
96+
97+
[origin."case(os)".macos."case(host-arch)".x86-64]
98+
url = "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-{PKG_VERSION}/{macos_package}"
99+
hashes = ["sha256:{macos_sha256}"]
100+
"""
101+
102+
MANIFEST_DIR = os.path.join("index", CRATE[0:2], CRATE)
103+
MANIFEST_FILE = os.path.join(MANIFEST_DIR, f"{CRATE}-{CRATE_VERSION}.toml")
104+
os.makedirs(MANIFEST_DIR, exist_ok=True)
105+
with open(MANIFEST_FILE, "w", encoding="utf-8") as file:
106+
file.write(MANIFEST_CONTENT)

0 commit comments

Comments
 (0)