generate: Add option to run jobs in parallel

This commit is contained in:
Danny Lin 2021-12-18 02:41:22 -08:00
parent 400298178b
commit b25e93bd2c
2 changed files with 22 additions and 5 deletions

View file

@ -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)
}
}

View file

@ -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)