Fix dependency error in plan-publish.js

This commit is contained in:
Radon Rosborough 2021-01-17 21:26:20 -08:00
parent a29329f71c
commit 36a0a86bd3
2 changed files with 85 additions and 71 deletions

View File

@ -31,6 +31,8 @@ export async function getSharedDeps() {
// Return a list of objects representing the packages to be built. See // Return a list of objects representing the packages to be built. See
// the function implementation for the full list of keys. // the function implementation for the full list of keys.
export async function getPackages() { 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 = []; const packages = [];
for (const lang of await getSharedDeps()) { for (const lang of await getSharedDeps()) {
const type = "shared"; const type = "shared";

View File

@ -92,80 +92,92 @@ async function planDebianPackages(opts) {
(await getLangs()).map(async (id) => [id, await readLangConfig(id)]) (await getLangs()).map(async (id) => [id, await readLangConfig(id)])
) )
); );
return _.sortBy( const plan = await Promise.all(
await Promise.all( packages.map(async ({ lang, type, name, buildScriptPath, debPath }) => {
packages.map(async ({ lang, type, name, buildScriptPath, debPath }) => { const desired = crypto
const desired = crypto .createHash("sha1")
.createHash("sha1") .update(await fs.readFile(buildScriptPath, "utf-8"))
.update(await fs.readFile(buildScriptPath, "utf-8")) .digest("hex");
.digest("hex"); let debExists = true;
let debExists = true; try {
try { await fs.access(debPath);
await fs.access(debPath); } catch (err) {
} catch (err) { debExists = false;
debExists = false; }
} let local = null;
let local = null; if (debExists) {
if (debExists) { local =
local = (
( await runCommand(`dpkg-deb -f ${debPath} Riju-Script-Hash`, {
await runCommand(`dpkg-deb -f ${debPath} Riju-Script-Hash`, { getStdout: true,
getStdout: true, })
}) ).stdout.trim() || null;
).stdout.trim() || null; }
} const remote = remoteHashes[name] || null;
const remote = remoteHashes[name] || null; let sharedDeps = [];
let sharedDeps = []; if (type === "lang") {
if (type === "lang") { const cfg = langConfigs[lang];
const cfg = langConfigs[lang]; sharedDeps = ((cfg.install && cfg.install.riju) || []).map(
sharedDeps = ((cfg.install && cfg.install.riju) || []).map( (id) => sharedUUIDs[id]
(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 { upload: async () => {
id: uuids[name], if (type === "config") {
deps: [ const clauses = [];
...(deps || []), for (const dep of (langConfigs[lang].install || {}).riju || []) {
...(type === "config" ? [langUUIDs[lang]] : []), clauses.push(`make install T=shared L=${dep}`);
...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(" && ")}"`
);
} }
await runCommand(`make upload L=${lang} T=${type}`); clauses.push(`make installs L=${lang}`);
}, clauses.push("make test");
type, await runCommand(
}; `make shell I=runtime CMD="${clauses.join(" && ")}"`
}) );
), }
({ type, desired, local, remote }) => { await runCommand(`make upload L=${lang} T=${type}`);
// If *not* a shared package, and all we have to do is download },
// it, then sort to the end. type,
return type !== "shared" && local !== desired && remote === desired; };
} })
); );
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() { async function computePlan() {