-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildDeb.py
264 lines (209 loc) · 8.48 KB
/
BuildDeb.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/usr/bin/env python3
import sys
import struct
import re
import os
from itertools import chain
import warnings
import tarfile
import sh
from tqdm import tqdm
from pydebhelper import *
from getLatestVersionAndURLWithGitHubAPI import getTargets
def genGraalProvides(start=6, end=8): # java 12 still not supported yet
graalvmProvides = ["default-jre", "default-jre-headless", "java-compiler"]
for i in range(start, end + 1):
si = str(i)
graalvmProvides += ["openjdk-" + si + "-jre", "openjdk-" + si + "-jre-headless", "java" + si + "-runtime", "java" + si + "-runtime-headless", "java" + si + "-sdk-headless"]
return graalvmProvides
config = OrderedDict()
config["llvm"] = {
"descriptionLong": "LLVM engine for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/languages/llvm/",
"rip": {
"bin": ["lli"],
"other": ["jre/languages/llvm"]
}
}
config["js"] = {
"descriptionLong": "JavaScript engine & node.js runtime for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/languages/js/",
"rip": {
"bin": ["js", "node", "npm"],
"other": ["jre/languages/js", "jre/lib/graalvm/graaljs-launcher.jar"]
}
}
config["python"] = {
"descriptionLong": "python runtime for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/languages/python/",
"rip": {
"bin": ["graalpython"],
"other": ["jre/languages/python", "jre/lib/graalvm/graalpython-launcher.jar", "LICENSE_GRAALPYTHON", "jre/languages/python/LICENSE_GRAALPYTHON"]
}
}
config["ruby"] = {
"descriptionLong": "ruby runtime for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/languages/ruby/",
"rip": {
"bin": ["truffleruby", "ruby", "bundle", "bundler", "gem", "irb", "rake", "rdoc", "ri"],
"other": ["jre/languages/ruby", "jre/lib/boot/truffleruby-services.jar", "jre/lib/graalvm/truffleruby-launcher.jar", "LICENSE_TRUFFLERUBY.md", "3rd_party_licenses_truffleruby.txt"]
}
}
config["r"] = {
"descriptionLong": "R runtime for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/languages/R/",
"rip": {
"bin": ["R", "Rscript"],
"other": ["jre/languages/R", "LICENSE_FASTR", "3rd_party_licenses_fastr.txt"]
}
}
config["gu"] = {
"descriptionLong": "Package manager for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/graal-updater/",
"rip": {
"bin": ["gu"],
"other": ["jre/lib/installer", "bin/gu"]
}
}
config["polyglot"] = {
"descriptionLong": "Polyglot for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/polyglot/",
"rip": {
"bin": ["polyglot"],
"other": ["jre/lib/polyglot"]
}
}
config["samples"] = {
"descriptionLong": "Example code for GraalVM",
"homepage": "https://www.graalvm.org/",
"rip": {
"other": ["sample"]
}
}
config["visualvm"] = {
"descriptionLong": "VisualVM for GraalVM",
"homepage": "https://www.graalvm.org/docs/reference-manual/tools/#heap-viewer",
"rip": {
"bin": ["jvisualvm"],
"other": ["lib/visualvm"]
}
}
def removeUnneededSources(unpackedDir):
for f in chain(unpackedDir.glob("**/src.zip"), unpackedDir.glob("**/*.src.zip")):
f.unlink()
def ripGraalPackage(unpackedDir, packagesDir, version, maintainer, builtDir):
mainPackageName = "graalvm"
systemPrefix = "usr/lib/jvm/graalvm-ce-amd64"
removeUnneededSources(unpackedDir)
results = []
for pkgPostfix, pkgCfg in config.items():
pkgCfg = type(pkgCfg)(pkgCfg)
rip = pkgCfg["rip"]
del pkgCfg["rip"]
with Package(mainPackageName + "-" + pkgPostfix, packagesDir, version=version, section="java", maintainer=maintainer, builtDir=builtDir, **pkgCfg) as pkg:
if "other" in rip:
for el in rip["other"]:
pkg.rip(unpackedDir / el, systemPrefix + "/" + el)
if "bin" in rip:
for el in rip["bin"]:
a = "bin/" + el
aUnp = unpackedDir / a
if aUnp.exists() or aUnp.is_symlink():
pkg.rip(aUnp, systemPrefix + "/" + a)
else:
warnings.warn(str(aUnp) + " doesn't exist")
b = "jre/" + a
bUnp = unpackedDir / b
if aUnp.exists() or aUnp.is_symlink():
pkg.rip(bUnp, systemPrefix + "/" + b)
else:
warnings.warn(str(bUnp) + " doesn't exist")
results.append(pkg)
with Package(mainPackageName, packagesDir, version=version, section="java", homepage="https://github.com/oracle/graal/releases", provides=genGraalProvides(), descriptionShort="graalvm", descriptionLong="GraalVM is a high-performance, embeddable, polyglot virtual machine for running applications written in JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Kotlin, and LLVM-based languages such as C and C++. \nAdditionally, GraalVM allows efficient interoperability between programming languages and compiling Java applications ahead-of-time into native executables for faster startup time and lower memory overhead.", maintainer=maintainer, builtDir=builtDir) as graalVM:
graalVM.rip(unpackedDir, systemPrefix)
results.append(graalVM)
return results
def isSubdir(parent: Path, child: Path) -> bool:
parent = parent.absolute().resolve()
child = child.absolute().resolve().relative_to(parent)
for p in child.parts:
if p == "..":
return False
return True
def unpack(archPath, extrDir):
extrDir = extrDir.resolve()
packedSize = archPath.stat().st_size
with archPath.open("rb") as arch:
arch.seek(packedSize - 4)
unpackedSize = struct.unpack("<I", arch.read(4))[0]
with tarfile.open(archPath, "r:gz") as arch:
with tqdm(total=unpackedSize, unit="B", unit_divisor=1024, unit_scale=True) as pb:
for f in arch:
fp = (extrDir / f.name).absolute()
if isSubdir(extrDir, fp):
if fp.is_file() or fp.is_symlink():
fp.unlink()
fp.parent.mkdir(parents=True, exist_ok=True)
arch.extract(f, extrDir, set_attrs=True)
pb.set_postfix(file=str(fp.relative_to(extrDir)), refresh=False)
pb.update(f.size)
currentProcFileDescriptors = Path("/proc") / str(os.getpid()) / "fd"
fj = sh.firejail.bake(noblacklist=str(currentProcFileDescriptors), _fg=True)
aria2c = fj.aria2c.bake(_fg=True, **{"continue": "true", "check-certificate": "true", "enable-mmap": "true", "optimize-concurrent-downloads": "true", "j": 16, "x": 16, "file-allocation": "falloc"})
def download(targets):
args = []
for dst, uri in targets.items():
args += [uri, linesep, " ", "out=", str(dst), linesep]
pO, pI = os.pipe()
with os.fdopen(pI, "w") as pIF:
pIF.write("".join(args))
pIF.flush()
try:
aria2c(**{"input-file": str(currentProcFileDescriptors / str(pO))})
finally:
os.close(pO)
try:
os.close(pI)
except:
pass
vmTagRx = re.compile("^vm-((?:\\d+\\.){2}\\d+(?:-rc\\d+))?$")
vmTitleMarker = "GraalVM Community Edition .+$"
platformMarker = "linux-amd64"
versionFileNameMarker = "[\\w\\.-]+"
releaseFileNameMarker = versionFileNameMarker + "-" + platformMarker
def getLatestGraalVMRelease():
downloadFileNameRx = re.compile("^" + releaseFileNameMarker + "\\.tar\\.gz$")
return max(getTargets("oracle/graal", re.compile("^" + vmTitleMarker), vmTagRx, downloadFileNameRx))
def getLatestGraalRuntimeRelease(repoPath):
downloadFileNameRx = re.compile(".+installable-ce-" + releaseFileNameMarker + "\\.jar$")
return max(getTargets(repoPath, re.compile(".+- " + vmTitleMarker), vmTagRx, downloadFileNameRx))
def doBuild():
thisDir = Path(".")
downloadDir = Path(thisDir / "downloads")
archPath = Path(downloadDir / "graalvm-github.tar.gz")
unpackDir = thisDir / "graalvm-unpacked"
packagesRootsDir = thisDir / "packagesRoots"
builtDir = thisDir / "packages"
repoDir = thisDir / "public" / "repo"
selT = getLatestGraalVMRelease()
print("Selected release:", selT, file=sys.stderr)
runtimesRepos = {"python": "graalvm/graalpython", "ruby": "oracle/truffleruby", "R": "oracle/fastr"}
runtimeReleases = {k: getLatestGraalRuntimeRelease(v) for k, v in runtimesRepos.items()}
runtimeFiles = {(downloadDir / (k + ".jar")): v.uri for k, v in runtimeReleases.items()}
downloadTargets = {archPath: selT.uri, **runtimeFiles}
download(downloadTargets)
unpack(archPath, unpackDir)
graalUnpackedRoot = unpackDir / ("graalvm-ce-" + selT.version)
guCmd = fj.bake(str(graalUnpackedRoot / "bin/gu"), _fg=True)
guCmd("-L", "install", *runtimeFiles.keys())
builtDir.mkdir(parents=True, exist_ok=True)
maintainer = Maintainer()
pkgs = ripGraalPackage(graalUnpackedRoot, packagesRootsDir, selT.version, maintainer=maintainer, builtDir=builtDir)
for pkg in pkgs:
pkg.build()
with Repo(root=repoDir, descr=maintainer.name+"'s repo for apt with GraalVM binary packages, built from the official builds on GitHub") as r:
for pkg in pkgs:
r += pkg
print(r.packages2add)
if __name__ == "__main__":
doBuild()