-
Notifications
You must be signed in to change notification settings - Fork 14
/
gen_gnat_manifests.py
executable file
·131 lines (109 loc) · 4.17 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
import wget
import subprocess
import sys
import tempfile
import os
import shutil
PKG_VERSION = "14.1.0-3"
CRATE_VERSION = "14.1.3"
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)
if target == "x86_64":
environment = """
[environment."case(os)".linux."case(host-arch)".x86-64]
PATH.prepend = "${CRATE_ROOT}/bin"
LIBRARY_PATH.prepend = "${CRATE_ROOT}/lib64"
LD_LIBRARY_PATH.prepend = "${CRATE_ROOT}/lib64"
LD_RUN_PATH.prepend = "${CRATE_ROOT}/lib64"
[environment."case(os)".windows."case(host-arch)".x86-64]
PATH.prepend = "${CRATE_ROOT}/bin"
LIBRARY_PATH.prepend = "${CRATE_ROOT}/lib"
LD_LIBRARY_PATH.prepend = "${CRATE_ROOT}/lib"
LD_RUN_PATH.prepend = "${CRATE_ROOT}/lib"
[environment."case(os)".macos."case(host-arch)".x86-64]
PATH.prepend = "${CRATE_ROOT}/bin"
LIBRARY_PATH.prepend = "${CRATE_ROOT}/lib"
LD_LIBRARY_PATH.prepend = "${CRATE_ROOT}/lib"
LD_RUN_PATH.prepend = "${CRATE_ROOT}/lib"
"""
else:
environment = """
[environment]
PATH.prepend = "${CRATE_ROOT}/bin"
"""
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}
[origin."case(os)".linux."case(host-arch)".x86-64]
binary = true
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]
binary = true
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]
binary = true
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)