From 825aa534c2231187136782a1fb687546d2b3feac Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Thu, 17 Dec 2020 21:43:55 -0800 Subject: [PATCH] Leave behind build artifacts for debugging --- .gitignore | 3 +- Makefile | 2 +- builder/build.js | 66 ++++++++++++++++++++-------------- package.json | 1 - yarn.lock | 93 ------------------------------------------------ 5 files changed, 43 insertions(+), 122 deletions(-) diff --git a/.gitignore b/.gitignore index b46737b..b01cda1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -*.deb *.log +debs node_modules +work diff --git a/Makefile b/Makefile index c1ea720..92834f2 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ export PATH := bin:$(PATH) .PHONY: debug debug: - node builder/build.js python riju-lang-python.deb + node builder/build.js python .PHONY: build-image build-image: diff --git a/builder/build.js b/builder/build.js index 8df0106..522ae89 100644 --- a/builder/build.js +++ b/builder/build.js @@ -3,7 +3,6 @@ const fs = require("fs").promises; const path = require("path"); const process = require("process"); -const tmp = require("tmp-promise"); const YAML = require("yaml"); // The build scripts in the language configs assume a specific build @@ -12,14 +11,20 @@ const YAML = require("yaml"); // * the working directory starts out empty // * the ${pkg} environment variable has been set to an absolute path // to the directory where the package should be built -// * we are using bash with 'set -euxo pipefail' - -tmp.setGracefulCleanup(); +// * we are using bash with 'set -euo pipefail' // Read the YAML config file for the language with the given string ID // and return it as an object. async function readLangConfig(lang) { - return YAML.parse(await fs.readFile(`langs/${lang}.yaml`, "utf-8")); + const langConfig = YAML.parse( + await fs.readFile(`langs/${lang}.yaml`, "utf-8") + ); + if (langConfig.id !== lang) { + throw new Error( + `lang config id ${langConfig.id} doesn't match expected ${lang}` + ); + } + return langConfig; } // Used to log all progress messages. Not sure what this should do @@ -32,9 +37,13 @@ function log(message) { async function runCommand(cmd) { log(`$ ${cmd}`); return new Promise((resolve, reject) => { - const proc = child_process.spawn("bash", ["-c", cmd], { - stdio: "inherit", - }); + const proc = child_process.spawn( + "bash", + ["-c", `set -euo pipefail; ${cmd}`], + { + stdio: "inherit", + } + ); proc.on("error", reject); proc.on("close", (code) => { if (code === 0) { @@ -57,7 +66,7 @@ async function buildPackage(langConfig, debPath) { install: { apt, pip, manual }, } = langConfig; const timestamp = new Date().getTime(); - const pkgDir = process.env.pkg; + const pkgdir = process.env.pkg; log(); log(`Building package riju-lang-${id}...`); let debianControlData = `\ @@ -74,9 +83,9 @@ Depends: ${apt.join(", ")} } log("Writing Debian control file:"); log(debianControlData.replaceAll(/^/gm, " ")); - await fs.mkdir(`${pkgDir}/DEBIAN`); - await fs.writeFile(`${pkgDir}/DEBIAN/control`, debianControlData); - await runCommand(`fakeroot dpkg-deb --build ${pkgDir} ${debPath}`); + await fs.mkdir(`${pkgdir}/DEBIAN`); + await fs.writeFile(`${pkgdir}/DEBIAN/control`, debianControlData); + await runCommand(`fakeroot dpkg-deb --build ${pkgdir} ${debPath}`); log(`Finished building package riju-lang-${id}.`); log(); } @@ -99,23 +108,28 @@ async function withTempDir(cb) { // process environment destructively. async function main() { const args = process.argv.slice(2); - if (args.length !== 2) { - console.error("usage: build.js LANG DEB"); + if (args.length !== 1) { + console.error("usage: build.js LANG"); process.exit(1); } - let [lang, debPath] = args; - debPath = path.resolve(process.cwd(), debPath); + const [lang] = args; + const cwd = process.cwd(); + const srcdir = `${cwd}/work/${lang}/src`; + const pkgdir = `${cwd}/work/${lang}/pkg`; + const debPath = `${cwd}/debs/riju-lang-${lang}.deb`; const langConfig = await readLangConfig(lang); - await withTempDir(async (srcDir) => { - await withTempDir(async (pkgDir) => { - log(`Source directory: ${srcDir}`); - log(`Package directory: ${pkgDir}`); - log(`Will write .deb file to: ${debPath}`); - process.chdir(srcDir); - process.env.pkg = pkgDir; - await buildPackage(langConfig, debPath); - }); - }); + log(`Source directory: ${srcdir}`); + log(`Package directory: ${pkgdir}`); + log(`Will write .deb file to: ${debPath}`); + await fs.rmdir(srcdir, { recursive: true }); + await fs.rmdir(pkgdir, { recursive: true }); + await fs.rm(debPath, { force: true }); + await fs.mkdir(srcdir, { recursive: true }); + await fs.mkdir(pkgdir, { recursive: true }); + await fs.mkdir(path.dirname(debPath), { recursive: true }); + process.chdir(srcdir); + process.env.pkg = pkgdir; + await buildPackage(langConfig, debPath); } main().catch((err) => { diff --git a/package.json b/package.json index d414df1..7b0e167 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "license": "MIT", "private": true, "dependencies": { - "tmp-promise": "^3.0.2", "yaml": "^1.10.0" } } diff --git a/yarn.lock b/yarn.lock index 5ecae73..a24537e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,99 +2,6 @@ # yarn lockfile v1 -balanced-match@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" - integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= - -brace-expansion@^1.1.7: - version "1.1.11" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" - integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== - dependencies: - balanced-match "^1.0.0" - concat-map "0.0.1" - -concat-map@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= - -fs.realpath@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" - integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= - -glob@^7.1.3: - version "7.1.6" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" - integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.4" - once "^1.3.0" - path-is-absolute "^1.0.0" - -inflight@^1.0.4: - version "1.0.6" - resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" - integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= - dependencies: - once "^1.3.0" - wrappy "1" - -inherits@2: - version "2.0.4" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" - integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== - -minimatch@^3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== - dependencies: - brace-expansion "^1.1.7" - -once@^1.3.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" - integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= - dependencies: - wrappy "1" - -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" - integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= - -rimraf@^3.0.0: - version "3.0.2" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" - integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== - dependencies: - glob "^7.1.3" - -tmp-promise@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-3.0.2.tgz#6e933782abff8b00c3119d63589ca1fb9caaa62a" - integrity sha512-OyCLAKU1HzBjL6Ev3gxUeraJNlbNingmi8IrHHEsYH8LTmEuhvYfqvhn2F/je+mjf4N58UmZ96OMEy1JanSCpA== - dependencies: - tmp "^0.2.0" - -tmp@^0.2.0: - version "0.2.1" - resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14" - integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ== - dependencies: - rimraf "^3.0.0" - -wrappy@1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" - integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= - yaml@^1.10.0: version "1.10.0" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"