Write all build scripts at once

This commit is contained in:
Radon Rosborough 2021-01-17 13:34:58 -08:00
parent 5ef6c0ff51
commit 33edf76b93
3 changed files with 54 additions and 21 deletions

View File

@ -57,7 +57,7 @@ scripts:
node tools/make-foreach.js --types script L=$(L)
all-scripts:
node tools/make-foreach.js --pkgs script
node tools/write-all-build-scripts.js
pkg-clean:
@: $${L} $${T}

View File

@ -1,5 +1,6 @@
import nodePath from "path";
import process from "process";
import url from "url";
import { Command } from "commander";
import YAML from "yaml";
@ -321,6 +322,22 @@ function makeSharedScript(langConfig) {
return makeLangScript(langConfig, true);
}
export async function generateBuildScript({ lang, type }) {
const scriptMaker = {
lang: makeLangScript,
config: makeConfigScript,
shared: makeSharedScript,
}[type];
if (!scriptMaker) {
throw new Error(`unsupported script type ${type}`);
}
return scriptMaker(
type === "shared"
? await readSharedDepConfig(lang)
: await readLangConfig(lang)
);
}
// Parse command-line arguments, run main functionality, and exit.
async function main() {
const program = new Command();
@ -331,26 +348,13 @@ async function main() {
"package category (lang, config, shared)"
);
program.parse(process.argv);
const scriptMaker = {
lang: makeLangScript,
config: makeConfigScript,
shared: makeSharedScript,
}[program.type];
if (!scriptMaker) {
console.error(`make-script.js: unsupported --type ${program.type}`);
process.exit(1);
}
console.log(
scriptMaker(
program.type === "shared"
? await readSharedDepConfig(program.lang)
: await readLangConfig(program.lang)
)
);
console.log(generateBuildScript({ lang: program.lang, type: program.type }));
process.exit(0);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
main().catch((err) => {
console.error(err);
process.exit(1);
});
}

View File

@ -0,0 +1,29 @@
// This script is not really needed per se, but it's a bit slow to run
// Make/Node.js several hundred times in order to 'make all-scripts',
// hence having a single script that does the whole thing.
import { promises as fs } from "fs";
import process from "process";
import url from "url";
import { getPackages } from "./config.js";
import { generateBuildScript } from "./generate-build-script.js";
// Parse command-line arguments, run main functionality, and exit.
async function main() {
for (const { lang, type } of await getPackages()) {
await fs.mkdir(`build/${type}/${lang}`, { recursive: true });
await fs.writeFile(
`build/${type}/${lang}/build.bash`,
await generateBuildScript({ lang, type })
);
}
process.exit(0);
}
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
main().catch((err) => {
console.error(err);
process.exit(1);
});
}