/
index.ts
executable file
·274 lines (240 loc) · 11.5 KB
/
index.ts
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
265
266
267
268
269
270
271
272
273
274
/*
plasma-mobile-nightly-build-script: Sineware ProLinux project to produce nightly development packages of Plasma Mobile
Copyright (C) 2022 Seshan Ravikumar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
require('dotenv').config()
import path from "path";
import { parsePackageDependencies } from "./apkbuild-parser/parser";
import { repository, globalPatches } from "./apkbuild-parser/repo";
import exec from "./helpers/exec";
import { Package } from "./helpers/types";
const WORKDIR = path.join(process.cwd(), "workdir");
const ABUILD_WRAPPER = path.join(__dirname, "abuild-wrapper.sh");
const ALPINE_APORTS_REPO = "https://gitlab.alpinelinux.org/alpine/aports.git";
const ARCH = process.env.BUILD_ARCH ?? exec("uname -m", false).toString().trim();
let builtList: string[] = [];
console.log("WORKDIR: " + WORKDIR);
console.log("ABUILD_WRAPPER: " + ABUILD_WRAPPER);
console.log("ALPINE_APORTS_REPO: " + ALPINE_APORTS_REPO);
console.log("ARCH: " + ARCH);
let buildStep = "";
(async () => {
try {
console.log("💤 Starting Plasma Mobile Nightly build at " + new Date().toLocaleString());
exec("mkdir -pv " + WORKDIR);
process.chdir(WORKDIR);
console.log("🔧 Upgrading Alpine");
exec("sudo apk upgrade");
// Clone aports repository from git, or pull if it already exists
console.log("📦 Cloning aports repository");
buildStep = "clone-aports";
exec(`git -C aports pull || git clone ${ALPINE_APORTS_REPO} aports`);
exec("mkdir -pv prolinux-nightly");
if(process.env.BUILD_SINGLE_PACKAGE) {
console.log("📦 Building single package " + process.env.BUILD_SINGLE_PACKAGE);
buildStep = "build-single-package";
if(!repository.has(process.env.BUILD_SINGLE_PACKAGE)) {
throw new Error("Package not found in repo.ts");
}
await buildPackage(repository.get(process.env.BUILD_SINGLE_PACKAGE)!);
} else {
// Get list from repository or the environment variable PACKAGE_LIST
let packages: string[] = [];
if(process.env.PACKAGE_LIST) {
packages = process.env.PACKAGE_LIST.split(",");
} else {
packages = Array.from(repository.keys());
}
console.log("📦 Package list: " + packages.join(", "));
let repoTotal = 0;
for (const pkg of packages) {
let fullList = parsePackageDependencies(pkg).filter((p) => repository.has(p));
// Also parse dependencies of extraDepends and add them to fullList
if(repository.get(pkg)?.extraDepends) {
for (const extraDepend of repository.get(pkg)!.extraDepends!) {
fullList = [...fullList, ...parsePackageDependencies(extraDepend).filter((p) => repository.has(p))];
}
}
console.log("📦 Building " + pkg + " with dependencies: " + fullList.join(", "));
let total = 0;
for (const d of fullList) {
await buildPackage(repository.get(d)!);
total++;
console.log("⏳ Built " + total + " of " + fullList.length + " dependencies for target " + pkg + " (" + repoTotal + "/" + repository.size + ")");
}
console.log("✅ Built " + total + " packages for target " + pkg);
repoTotal++;
}
}
// Deploy files
buildStep = "deploy";
console.log("🚀 Deploying files");
exec(`rsync -aHAXxv --delete --progress ~/packages/prolinux-nightly/${ARCH} espimac:/var/www/sineware/repo/alpine/prolinux-nightly/`);
buildStep = `finish`;
} catch (e) {
console.error("❌ Build failed at step " + buildStep + ": " + e);
process.exit(1);
}
})();
async function buildPackage(pkg: Package) {
try {
console.log("📦 -> Building " + pkg.name);
// return if already built
if (builtList.includes(pkg.name)) {
console.log("📦 -> Already built, skipping");
return;
}
// return if skipBuild is true
if (pkg.skipBuild && !process.env.PACKAGE_LIST?.split(",").includes(pkg.name) && !process.env.BUILD_SINGLE_PACKAGE) {
console.log("📦 -> Skip build is true, skipping");
return;
}
buildStep = `build-${pkg.name}-begin`;
// clone the package repository
const pkgDir = path.join(WORKDIR, "prolinux-nightly", pkg.name);
const aportsPkgDir = path.join(WORKDIR, "aports", pkg.aports_repo, pkg.name);
// check if rebuilding is necessary by compare rev-parse of local and remote
/*try {
exec(`git -C ${pkgDir}/src/${pkg.name} fetch`);
try {
exec(`git -C ${pkgDir}/src/${pkg.name} checkout kf5`);
console.log("🔧 -> Using kf5 branch");
} catch {
console.log("🔧 -> Using master branch");
}
const remoteRev = exec(`git -C ${pkgDir}/src/${pkg.name} rev-parse @{u}`, false).toString().trim();
const localRev = exec(`git -C ${pkgDir}/src/${pkg.name} rev-parse @`, false).toString().trim();
if (remoteRev === localRev) {
console.log("📦 -> Already up to date (upstream), skipping");
//return;
} else {
console.log("📦 -> New commits found, rebuilding");
console.log(` ->Deleting ${pkgDir}`)
exec(`rm -rf ${pkgDir}`);
}
} catch {
console.log("📦 -> Not cloned, cloning");
}*/
console.log(`📦 -> Deleting ${pkgDir}`)
exec(`rm -rf ${pkgDir}`);
console.log("🔧 -> Clone package repository");
buildStep = `build-${pkg.name}-clone`;
try {
exec(`mkdir -pv ${pkgDir}/src/${pkg.name}`);
exec(`git clone ${pkg.repo} ${pkgDir}/src/${pkg.name}`);
} catch (e) {
console.log(e);
console.log("🔧 -> Clone failed?");
}
// check if the "kf5" branch exists, if so, use it
try {
exec(`git -C ${pkgDir}/src/${pkg.name} checkout kf5`);
console.log("🔧 -> Using kf5 branch");
} catch {
console.log("🔧 -> Using master branch");
}
// Check if git commit message contains GIT_SILENT
/*const gitLog = exec(`git -C ${pkgDir}/src/${pkg.name} log -1 --pretty=%B`, false).toString().trim();
if (gitLog.includes("GIT_SILENT") && process.env.IGNORE_GIT_SILENT !== "true") {
console.log("📦 -> GIT_SILENT found, skipping");
return;
}*/
buildStep = `build-${pkg.name}-pre-patch`;
// copy patches/extra files from aports to src
exec(`cp -rv ${aportsPkgDir}/* ${pkgDir}/src/`);
exec(`cp -v ${aportsPkgDir}/APKBUILD ${pkgDir}/APKBUILD`);
const pkgVer = "9999_git" + (exec(`cd ${pkgDir}/src/${pkg.name} && git show -s --format=%ct`, false).toString().trim());
console.log("🔧 -> Patching APKBUILD with pkgver " + pkgVer);
buildStep = `build-${pkg.name}-patch`;
exec(`sed -i '/pkgver=/c\pkgver=${pkgVer}' ${pkgDir}/APKBUILD`);
exec(`sed -i 's/$pkgname-lang//g' ${pkgDir}/APKBUILD`);
// run global patches
for (const patch of globalPatches) {
console.log("🔧 -> Patching with " + patch.cmd);
if(patch.runInDir) {
exec(`cd ${pkgDir} && ${patch.cmd}`);
} else {
exec(patch.cmd);
}
}
// per package patch set
if(pkg.patches) {
for (const patch of pkg.patches) {
console.log("🔧 -> Patching" + " with " + patch.cmd);
exec(patch.cmd);
}
}
buildStep = `build-${pkg.name}-repolink`;
exec(`ln -svf ${pkgDir}/src/${pkg.name} ${pkgDir}/src/${pkg.name}-${pkgVer}`);
// build the package
console.log("🔧 -> Building package");
buildStep = `build-${pkg.name}-apk-pre-abuild`;
// prepare, deps, build, rootpkg, index
exec(`sudo apk update`); // ensures we are using the latest packages we compiled earlier
// apk add packages from extraDepends
if(pkg.extraDepends) {
for (const dep of pkg.extraDepends) {
console.log("🔧 -> Installing extra dependency " + dep);
exec(`sudo apk add ${dep}`);
}
}
// abuild
buildStep = `build-${pkg.name}-abuild`;
exec(`cd ${pkgDir} && abuild -F prepare`);
exec(`cd ${pkgDir} && abuild -F deps`);
exec(`cd ${pkgDir} && abuild -F build`, true, (process.env.DISTCC_SETTINGS === "true" && !pkg.dontDistcc) ? {
"ARCH": ARCH,
"CMAKE_BUILD_PARALLEL_LEVEL": "40",
"MAKEFLAGS": "-j40",
"CC": "ccache distcc",
"CXX": "ccache distcc g++",
} : (pkg.name === "kio") ? {
"ARCH": ARCH,
} : {
"ARCH": ARCH,
"CC": "ccache gcc",
"CXX": "ccache g++",
});
// clear old packages from ~/packages/prolinux-nightly/${ARCH}
console.log("📦 -> Clearing old packages");
// todo this matches wrong (breeze-* matches breeze-grub etc)
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/${pkg.name}-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/${pkg.name}-dev-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/${pkg.name}-libs-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/${pkg.name}-doc-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/${pkg.name}-lang-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/${pkg.name}-dbg-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/plasma-nm-mobile-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/knetattach-9999*`);
exec(`rm -rfv ~/packages/prolinux-nightly/${ARCH}/kio-kwallet-9999*`);
exec(`cd ${pkgDir} && abuild -F rootpkg`);
exec(`cd ${pkgDir} && abuild -F index`);
exec(`cd ${pkgDir} && abuild -F undeps`);
// apk del packages from extraDepends
buildStep = `build-${pkg.name}-apk-post-abuild`;
if(pkg.extraDepends) {
for (const dep of pkg.extraDepends) {
console.log("🔧 -> Removing extra dependency " + dep);
exec(`sudo apk del ${dep}`);
}
}
builtList.push(pkg.name);
} catch (e) {
console.error("❌ (buildPackage()) Failed to compile " + pkg.name);
// remove pkg folder
exec(`sudo apk del .makedepends-${pkg.name}`);
const pkgDir = path.join(WORKDIR, "prolinux-nightly", pkg.name);
//exec(`rm -rf ${pkgDir}`);
throw e;
}
}