Refactor and fixup generate-build-script API
This commit is contained in:
parent
491eb12e4c
commit
ddd5f44d0a
12
Makefile
12
Makefile
|
@ -95,17 +95,7 @@ endif
|
|||
|
||||
script: # L=<lang> T=<type> : Generate a packaging script
|
||||
@: $${L} $${T}
|
||||
ifeq ($(T),install)
|
||||
@echo >&2 "use 'make script L=$(L) T=lang' instead"
|
||||
@exit 1
|
||||
endif
|
||||
mkdir -p $(BUILD)
|
||||
node tools/generate-build-script.js --lang $(L) --type $(T) > $(BUILD)/build.bash
|
||||
chmod +x $(BUILD)/build.bash
|
||||
ifeq ($(T),lang)
|
||||
node tools/generate-build-script.js --lang $(L) --type install > $(BUILD)/install.bash
|
||||
chmod +x $(BUILD)/install.bash
|
||||
endif
|
||||
node tools/generate-build-script.js --lang $(L) --type $(T)
|
||||
|
||||
all-scripts: # Generate packaging scripts for all languages
|
||||
node tools/write-all-build-scripts.js
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { promises as fs } from "fs";
|
||||
import nodePath from "path";
|
||||
import process from "process";
|
||||
import url from "url";
|
||||
|
@ -413,15 +414,32 @@ set -euxo pipefail`);
|
|||
}
|
||||
|
||||
export async function generateBuildScript({ lang, type }) {
|
||||
const scriptMaker = {
|
||||
lang: async () => makeLangScript(await readLangConfig(lang)),
|
||||
shared: async () => makeSharedScript(await readSharedDepConfig(lang)),
|
||||
install: async () => makeInstallScript(await readLangConfig(lang)),
|
||||
}[type];
|
||||
if (!scriptMaker) {
|
||||
const funcs = {
|
||||
lang: {
|
||||
cfg: readLangConfig,
|
||||
make: makeLangScript,
|
||||
},
|
||||
shared: {
|
||||
cfg: readSharedDepConfig,
|
||||
make: makeSharedScript,
|
||||
},
|
||||
};
|
||||
if (!funcs[type]) {
|
||||
throw new Error(`unsupported script type ${type}`);
|
||||
}
|
||||
return scriptMaker();
|
||||
const { cfg, make } = funcs[type];
|
||||
const langConfig = await cfg(lang);
|
||||
const buildScript = await make(langConfig);
|
||||
const installScript = await makeInstallScript(langConfig);
|
||||
await fs.mkdir(`build/${type}/${lang}`, { recursive: true, mode: 0o755 });
|
||||
const buildScriptPath = `build/${type}/${lang}/build.bash`;
|
||||
const installScriptPath = `build/${type}/${lang}/install.bash`;
|
||||
await Promise.all([
|
||||
fs.writeFile(buildScriptPath, buildScript + "\n")
|
||||
.then(() => fs.chmod(buildScriptPath, 0o755)),
|
||||
fs.writeFile(installScriptPath, installScript + "\n")
|
||||
.then(() => fs.chmod(installScriptPath, 0o755)),
|
||||
]);
|
||||
}
|
||||
|
||||
// Parse command-line arguments, run main functionality, and exit.
|
||||
|
@ -431,10 +449,10 @@ async function main() {
|
|||
.requiredOption("--lang <id>", "language ID")
|
||||
.requiredOption(
|
||||
"--type <value>",
|
||||
"package category (lang, shared, install)"
|
||||
"package category (lang or shared)"
|
||||
);
|
||||
program.parse(process.argv);
|
||||
console.log(await generateBuildScript(program.opts()));
|
||||
await generateBuildScript(program.opts());
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,23 +12,7 @@ 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()) {
|
||||
const buildScriptPath = `build/${type}/${lang}/build.bash`;
|
||||
const installScriptPath = `build/${type}/${lang}/install.bash`;
|
||||
await fs.mkdir(nodePath.dirname(buildScriptPath), { recursive: true });
|
||||
await fs.writeFile(
|
||||
buildScriptPath,
|
||||
(await generateBuildScript({ lang, type })) + "\n"
|
||||
);
|
||||
await fs.chmod(buildScriptPath, 0o755);
|
||||
if (type === "lang") {
|
||||
await fs.writeFile(
|
||||
installScriptPath,
|
||||
(await generateBuildScript({ lang, type: "install" })) + "\n"
|
||||
);
|
||||
await fs.chmod(installScriptPath, 0o755);
|
||||
}
|
||||
}
|
||||
await Promise.all((await getPackages()).map(generateBuildScript));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue