collect-state: support specifying device names with DeviceList(s)

For example, `collect-state -d pixel-gen{6,7} barbet`
This commit is contained in:
Dmitry Muhomor 2023-08-30 08:47:22 +03:00 committed by Daniel Micay
parent 40354ec422
commit 9750841f3d

View file

@ -1,7 +1,8 @@
import { Command, flags } from '@oclif/command' import { Command, flags } from '@oclif/command'
import { promises as fs } from 'fs' import { promises as fs } from 'fs'
import { COLLECTED_SYSTEM_STATE_DIR } from '../config/paths'
import { DEVICE_CONFIG_FLAGS, loadDeviceConfigs } from '../config/device'
import { COLLECTED_SYSTEM_STATE_DIR } from '../config/paths'
import { collectSystemState, serializeSystemState } from '../config/system-state' import { collectSystemState, serializeSystemState } from '../config/system-state'
import { forEachDevice } from '../frontend/devices' import { forEachDevice } from '../frontend/devices'
@ -15,7 +16,6 @@ export default class CollectState extends Command {
description: 'path to aapt2 executable', description: 'path to aapt2 executable',
default: 'out/host/linux-x86/bin/aapt2', default: 'out/host/linux-x86/bin/aapt2',
}), }),
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' }), outRoot: flags.string({ char: 'r', description: 'path to AOSP build output directory (out/)', default: 'out' }),
parallel: flags.boolean({ parallel: flags.boolean({
char: 'p', char: 'p',
@ -28,20 +28,28 @@ export default class CollectState extends Command {
required: true, required: true,
default: COLLECTED_SYSTEM_STATE_DIR, default: COLLECTED_SYSTEM_STATE_DIR,
}), }),
...DEVICE_CONFIG_FLAGS,
} }
async run() { async run() {
let { let {
flags: { aapt2: aapt2Path, device: devices, outRoot, parallel, outPath }, flags: { aapt2: aapt2Path, devices, outRoot, parallel, outPath },
} = this.parse(CollectState) } = this.parse(CollectState)
let isDir = (await fs.stat(outPath)).isDirectory() let configs = await loadDeviceConfigs(devices)
await forEachDevice(devices, parallel, async device => {
let state = await collectSystemState(device, outRoot, aapt2Path)
// Write let isDir = (await fs.stat(outPath)).isDirectory()
let devicePath = isDir ? `${outPath}/${device}.json` : outPath await forEachDevice(
await fs.writeFile(devicePath, serializeSystemState(state)) configs,
}) parallel,
async config => {
let state = await collectSystemState(config.device.name, outRoot, aapt2Path)
// Write
let devicePath = isDir ? `${outPath}/${config}.json` : outPath
await fs.writeFile(devicePath, serializeSystemState(state))
},
c => c.device.name,
)
} }
} }