forked from alire-project/GNAT-FSF-builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_gnat_manifests.py
executable file
·106 lines (84 loc) · 3.37 KB
/
gen_gnat_manifests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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 = ["[email protected]"]
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)