From 8572903b3e44684f33cd1cf6c508a8309f08e343 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sat, 18 Dec 2021 18:26:23 -0800 Subject: [PATCH] collect-state: Add multi-device support --- src/commands/collect-state.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/commands/collect-state.ts b/src/commands/collect-state.ts index 53591c7..5c5e0a9 100644 --- a/src/commands/collect-state.ts +++ b/src/commands/collect-state.ts @@ -2,6 +2,7 @@ import { Command, flags } from '@oclif/command' import { promises as fs } from 'fs' import { collectSystemState, serializeSystemState } from '../config/system-state' +import { forEachDevice } from '../frontend/devices' export default class CollectState extends Command { static description = 'collect built system state for use with other commands' @@ -9,20 +10,29 @@ export default class CollectState extends Command { static flags = { help: flags.help({char: 'h'}), aapt2: flags.string({char: 'a', description: 'path to aapt2 executable', default: 'out/host/linux-x86/bin/aapt2'}), - device: flags.string({char: 'd', description: 'name of target device', required: true}), + device: flags.string({char: 'd', description: 'name of target device', required: true, multiple: true}), outRoot: flags.string({char: 'r', description: 'path to AOSP build output directory (out/)', default: 'out'}), + parallel: flags.boolean({char: 'p', description: 'generate devices in parallel (causes buggy progress spinners)', default: false}), } static args = [ - {name: 'output_path', description: 'output path for system state JSON file', required: true}, + {name: 'output_path', description: 'output path for system state JSON file(s)', required: true}, ] async run() { - let {flags: {aapt2: aapt2Path, device, outRoot}, args: {output_path: outPath}} = this.parse(CollectState) + let {flags: { + aapt2: aapt2Path, + device: devices, + outRoot, + parallel, + }, args: {output_path: outPath}} = this.parse(CollectState) - let state = await collectSystemState(device, outRoot, aapt2Path) + await forEachDevice(devices, parallel, async (device) => { + let state = await collectSystemState(device, outRoot, aapt2Path) - // Write - await fs.writeFile(outPath, serializeSystemState(state)) + // Write + let devicePath = devices.length > 1 ? `${outPath}/${device}.json` : outPath + await fs.writeFile(devicePath, serializeSystemState(state)) + }) } }