From b25e93bd2c86437a1b2feca8578d0c4d9282208b Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sat, 18 Dec 2021 02:41:22 -0800 Subject: [PATCH] generate: Add option to run jobs in parallel --- src/commands/generate-all.ts | 16 +++++++++++++--- src/commands/generate-prep.ts | 11 +++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/commands/generate-all.ts b/src/commands/generate-all.ts index 1c55a77..9cb3a58 100644 --- a/src/commands/generate-all.ts +++ b/src/commands/generate-all.ts @@ -135,7 +135,8 @@ export default class GenerateFull extends Command { customSrc: flags.string({char: 'c', description: 'path to AOSP build output directory (out/) or JSON state file', default: 'out'}), factoryZip: flags.string({char: 'f', description: 'path to stock factory images zip (for extracting firmware if stockSrc is not factory images)'}), skipCopy: flags.boolean({char: 'k', description: 'skip file copying and only generate build files', default: false}), - useTemp: flags.boolean({char: 't', description: 'use a temporary directory for all extraction (prevents reusing extracted files across runs)', default: false}) + useTemp: flags.boolean({char: 't', description: 'use a temporary directory for all extraction (prevents reusing extracted files across runs)', default: false}), + parallel: flags.boolean({char: 'p', description: 'generate devices in parallel (causes buggy progress spinners)', default: false}), } static args = [ @@ -151,10 +152,12 @@ export default class GenerateFull extends Command { factoryZip, skipCopy, useTemp, + parallel, }, args: {config: configPath}} = this.parse(GenerateFull) let devices = await loadDeviceConfigs(configPath) + let jobs = [] for (let config of devices) { if (devices.length > 1) { this.log(` @@ -163,8 +166,15 @@ ${chalk.bold(chalk.blueBright(config.device.name))} `) } - await doDevice(config, stockSrc, customSrc, aapt2Path, buildId, factoryZip, - skipCopy, useTemp) + let job = doDevice(config, stockSrc, customSrc, aapt2Path, buildId, + factoryZip, skipCopy, useTemp) + if (parallel) { + jobs.push(job) + } else { + await job + } } + + await Promise.all(jobs) } } diff --git a/src/commands/generate-prep.ts b/src/commands/generate-prep.ts index 2879c2d..55552d7 100644 --- a/src/commands/generate-prep.ts +++ b/src/commands/generate-prep.ts @@ -66,7 +66,8 @@ export default class GeneratePrep extends Command { buildId: flags.string({char: 'b', description: 'build ID of the stock images'}), stockSrc: flags.string({char: 's', description: 'path to (extracted) factory images, (mounted) images, (extracted) OTA package, OTA payload, or directory containing any such files (optionally under device and/or build ID directory)', required: true}), skipCopy: flags.boolean({char: 'k', description: 'skip file copying and only generate build files', default: false}), - useTemp: flags.boolean({char: 't', description: 'use a temporary directory for all extraction (prevents reusing extracted files across runs)', default: false}) + useTemp: flags.boolean({char: 't', description: 'use a temporary directory for all extraction (prevents reusing extracted files across runs)', default: false}), + parallel: flags.boolean({char: 'p', description: 'generate devices in parallel (causes buggy progress spinners)', default: false}), } static args = [ @@ -79,6 +80,7 @@ export default class GeneratePrep extends Command { stockSrc, skipCopy, useTemp, + parallel, }, args: {config: configPath}} = this.parse(GeneratePrep) let devices = await loadDeviceConfigs(configPath) @@ -92,7 +94,12 @@ ${chalk.bold(chalk.blueBright(config.device.name))} `) } - jobs.push(doDevice(config, stockSrc, buildId, skipCopy, useTemp)) + let job = doDevice(config, stockSrc, buildId, skipCopy, useTemp) + if (parallel) { + jobs.push(job) + } else { + await job + } } await Promise.all(jobs)