From 36a0a86bd365a723ad5f63830c90a1b5e0ecef87 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sun, 17 Jan 2021 21:26:20 -0800 Subject: [PATCH] Fix dependency error in plan-publish.js --- tools/config.js | 2 + tools/plan-publish.js | 154 +++++++++++++++++++++++------------------- 2 files changed, 85 insertions(+), 71 deletions(-) diff --git a/tools/config.js b/tools/config.js index 89879c0..07b01a0 100644 --- a/tools/config.js +++ b/tools/config.js @@ -31,6 +31,8 @@ export async function getSharedDeps() { // Return a list of objects representing the packages to be built. See // the function implementation for the full list of keys. export async function getPackages() { + // The order (shared, lang, config) is important to get dependencies + // correct due to poor abstractions in plan-publish.js. const packages = []; for (const lang of await getSharedDeps()) { const type = "shared"; diff --git a/tools/plan-publish.js b/tools/plan-publish.js index 15423a6..a0b3fe8 100644 --- a/tools/plan-publish.js +++ b/tools/plan-publish.js @@ -92,80 +92,92 @@ async function planDebianPackages(opts) { (await getLangs()).map(async (id) => [id, await readLangConfig(id)]) ) ); - return _.sortBy( - await Promise.all( - packages.map(async ({ lang, type, name, buildScriptPath, debPath }) => { - const desired = crypto - .createHash("sha1") - .update(await fs.readFile(buildScriptPath, "utf-8")) - .digest("hex"); - let debExists = true; - try { - await fs.access(debPath); - } catch (err) { - debExists = false; - } - let local = null; - if (debExists) { - local = - ( - await runCommand(`dpkg-deb -f ${debPath} Riju-Script-Hash`, { - getStdout: true, - }) - ).stdout.trim() || null; - } - const remote = remoteHashes[name] || null; - let sharedDeps = []; - if (type === "lang") { - const cfg = langConfigs[lang]; - sharedDeps = ((cfg.install && cfg.install.riju) || []).map( - (id) => sharedUUIDs[id] + const plan = await Promise.all( + packages.map(async ({ lang, type, name, buildScriptPath, debPath }) => { + const desired = crypto + .createHash("sha1") + .update(await fs.readFile(buildScriptPath, "utf-8")) + .digest("hex"); + let debExists = true; + try { + await fs.access(debPath); + } catch (err) { + debExists = false; + } + let local = null; + if (debExists) { + local = + ( + await runCommand(`dpkg-deb -f ${debPath} Riju-Script-Hash`, { + getStdout: true, + }) + ).stdout.trim() || null; + } + const remote = remoteHashes[name] || null; + let sharedDeps = []; + if (type === "lang") { + const cfg = langConfigs[lang]; + sharedDeps = ((cfg.install && cfg.install.riju) || []).map( + (id) => sharedUUIDs[id] + ); + } + return { + id: uuids[name], + deps: [ + ...(deps || []), + ...(type === "config" ? [langUUIDs[lang]] : []), + ...sharedDeps, + ], + artifact: "Debian package", + name, + desired, + local, + remote, + download: async () => { + await runCommand(`make download L=${lang} T=${type}`); + }, + build: async () => { + await runCommand( + `make shell I=packaging CMD="make pkg L=${lang} T=${type}"` ); - } - return { - id: uuids[name], - deps: [ - ...(deps || []), - ...(type === "config" ? [langUUIDs[lang]] : []), - ...sharedDeps, - ], - artifact: "Debian package", - name, - desired, - local, - remote, - download: async () => { - await runCommand(`make download L=${lang} T=${type}`); - }, - build: async () => { - await runCommand( - `make shell I=packaging CMD="make pkg L=${lang} T=${type}"` - ); - }, - upload: async () => { - if (type === "config") { - const clauses = []; - for (const dep of (langConfigs[lang].install || {}).riju || []) { - clauses.push(`make install T=shared L=${dep}`); - } - clauses.push(`make installs L=${lang}`); - clauses.push("make test"); - await runCommand( - `make shell I=runtime CMD="${clauses.join(" && ")}"` - ); + }, + upload: async () => { + if (type === "config") { + const clauses = []; + for (const dep of (langConfigs[lang].install || {}).riju || []) { + clauses.push(`make install T=shared L=${dep}`); } - await runCommand(`make upload L=${lang} T=${type}`); - }, - type, - }; - }) - ), - ({ type, desired, local, remote }) => { - // If *not* a shared package, and all we have to do is download - // it, then sort to the end. - return type !== "shared" && local !== desired && remote === desired; - } + clauses.push(`make installs L=${lang}`); + clauses.push("make test"); + await runCommand( + `make shell I=runtime CMD="${clauses.join(" && ")}"` + ); + } + await runCommand(`make upload L=${lang} T=${type}`); + }, + type, + }; + }) ); + const lazilyDownloadedLanguages = new Set(); + for (const { type, lang, desired, local, remote } of plan) { + if (type === "shared") { + continue; + } + // If *not* a shared package, and all we have to do is download + // it, then sort to the end. Unless of course this is the lang + // package, and we need to rebuild the config package, in which + // case the config package (which comes later) will remove that + // lang from the set again. + if (local !== desired && remote === desired) { + lazilyDownloadedLanguages.add(lang); + } else { + lazilyDownloadedLanguages.delete(lang); + } + } + return _.sortBy(plan, ({ type, lang }) => { + return type !== "shared" && lazilyDownloadedLanguages.has(lang); + }); } async function computePlan() {