Successfully build .deb
This commit is contained in:
parent
3670c78cb1
commit
9a828c8a5d
|
@ -1,2 +1,3 @@
|
||||||
|
*.deb
|
||||||
*.log
|
*.log
|
||||||
node_modules
|
node_modules
|
||||||
|
|
|
@ -14,16 +14,27 @@ const YAML = require("yaml");
|
||||||
// to the directory where the package should be built
|
// to the directory where the package should be built
|
||||||
// * we are using bash with 'set -euxo pipefail'
|
// * we are using bash with 'set -euxo pipefail'
|
||||||
|
|
||||||
|
tmp.setGracefulCleanup();
|
||||||
|
|
||||||
// Read the YAML config file for the language with the given string ID
|
// Read the YAML config file for the language with the given string ID
|
||||||
// and return it as an object.
|
// and return it as an object.
|
||||||
async function readLangConfig(lang) {
|
async function readLangConfig(lang) {
|
||||||
return YAML.parse(await fs.readFile(`langs/${lang}.yaml`, "utf-8"));
|
return YAML.parse(await fs.readFile(`langs/${lang}.yaml`, "utf-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to log all progress messages. Not sure what this should do
|
||||||
|
// quite yet.
|
||||||
|
function log(message) {
|
||||||
|
console.error(message ? message.trimEnd() : "");
|
||||||
|
}
|
||||||
|
|
||||||
// Given a shell command as a string, execute it with Bash.
|
// Given a shell command as a string, execute it with Bash.
|
||||||
async function runCommand(cmd) {
|
async function runCommand(cmd) {
|
||||||
|
log(`$ ${cmd}`);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const proc = child_process.spawn("bash", ["-c", ...cmd]);
|
const proc = child_process.spawn("bash", ["-c", cmd], {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
proc.on("error", reject);
|
proc.on("error", reject);
|
||||||
proc.on("close", (code) => {
|
proc.on("close", (code) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
|
@ -46,6 +57,9 @@ async function buildPackage(langConfig, debPath) {
|
||||||
install: { apt, pip, manual },
|
install: { apt, pip, manual },
|
||||||
} = langConfig;
|
} = langConfig;
|
||||||
const timestamp = new Date().getTime();
|
const timestamp = new Date().getTime();
|
||||||
|
const pkgDir = process.env.pkg;
|
||||||
|
log();
|
||||||
|
log(`Building package riju-lang-${id}...`);
|
||||||
let debianControlData = `\
|
let debianControlData = `\
|
||||||
Package: riju-lang-${id}
|
Package: riju-lang-${id}
|
||||||
Version: ${timestamp}
|
Version: ${timestamp}
|
||||||
|
@ -58,17 +72,31 @@ Description: The ${name} language packaged for Riju
|
||||||
Depends: ${apt.join(", ")}
|
Depends: ${apt.join(", ")}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
await fs.mkdir("DEBIAN");
|
log("Writing Debian control file:");
|
||||||
await fs.writeFile("DEBIAN/control", debianControlData);
|
log(debianControlData.replaceAll(/^/gm, " "));
|
||||||
await runCommand([
|
await fs.mkdir(`${pkgDir}/DEBIAN`);
|
||||||
"fakeroot",
|
await fs.writeFile(`${pkgDir}/DEBIAN/control`, debianControlData);
|
||||||
"dpkg-deb",
|
await runCommand(`fakeroot dpkg-deb --build ${pkgDir} ${debPath}`);
|
||||||
"--build",
|
log(`Finished building package riju-lang-${id}.`);
|
||||||
process.env.pkg,
|
log();
|
||||||
debPath,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a temporary directory and call the given sync or async
|
||||||
|
// function with its path as a string. Once the function returns, make
|
||||||
|
// sure the directory and its contents are deleted.
|
||||||
|
async function withTempDir(cb) {
|
||||||
|
return await tmp.withDir(
|
||||||
|
async (o) => {
|
||||||
|
await cb(o.path);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
unsafeCleanup: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse command line and run main functionality. This changes the
|
||||||
|
// process environment destructively.
|
||||||
async function main() {
|
async function main() {
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
if (args.length !== 2) {
|
if (args.length !== 2) {
|
||||||
|
@ -76,13 +104,14 @@ async function main() {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
let [lang, debPath] = args;
|
let [lang, debPath] = args;
|
||||||
debPath = path.join(process.cwd(), debPath);
|
debPath = path.resolve(process.cwd(), debPath);
|
||||||
const langConfig = await readLangConfig(lang);
|
const langConfig = await readLangConfig(lang);
|
||||||
await tmp.withDir(async (o) => {
|
await withTempDir(async (srcDir) => {
|
||||||
const buildDir = o.path;
|
await withTempDir(async (pkgDir) => {
|
||||||
await tmp.withDir(async (o) => {
|
log(`Source directory: ${srcDir}`);
|
||||||
const pkgDir = o.path;
|
log(`Package directory: ${pkgDir}`);
|
||||||
process.chdir(buildDir);
|
log(`Will write .deb file to: ${debPath}`);
|
||||||
|
process.chdir(srcDir);
|
||||||
process.env.pkg = pkgDir;
|
process.env.pkg = pkgDir;
|
||||||
await buildPackage(langConfig, debPath);
|
await buildPackage(langConfig, debPath);
|
||||||
});
|
});
|
||||||
|
@ -90,6 +119,7 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
main().catch((err) => {
|
||||||
|
console.error();
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue