collect-state: Move logic to config/system-state
This commit is contained in:
parent
eb02404e94
commit
3a267498f2
2 changed files with 57 additions and 56 deletions
|
@ -1,16 +1,7 @@
|
|||
import { Command, flags } from '@oclif/command'
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
import { listPart } from '../blobs/file-list'
|
||||
import { parsePartOverlayApks } from '../blobs/overlays'
|
||||
import { loadPartitionProps } from '../blobs/props'
|
||||
import { loadPartVintfInfo } from '../blobs/vintf'
|
||||
import { parseModuleInfo } from '../build/soong-info'
|
||||
import { serializeSystemState, SystemState } from '../config/system-state'
|
||||
import { parsePartContexts } from '../selinux/contexts'
|
||||
import { withSpinner } from '../util/cli'
|
||||
import { readFile } from '../util/fs'
|
||||
import { ALL_SYS_PARTITIONS } from '../util/partitions'
|
||||
import { collectSystemState, serializeSystemState } from '../config/system-state'
|
||||
|
||||
export default class CollectState extends Command {
|
||||
static description = 'collect built system state for use with other commands'
|
||||
|
@ -19,7 +10,7 @@ export default class CollectState extends Command {
|
|||
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}),
|
||||
root: 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'}),
|
||||
}
|
||||
|
||||
static args = [
|
||||
|
@ -27,47 +18,9 @@ export default class CollectState extends Command {
|
|||
]
|
||||
|
||||
async run() {
|
||||
let {flags: {aapt2: aapt2Path, device, root}, args: {output_path: outPath}} = this.parse(CollectState)
|
||||
let {flags: {aapt2: aapt2Path, device, outRoot}, args: {output_path: outPath}} = this.parse(CollectState)
|
||||
|
||||
let systemRoot = `${root}/target/product/${device}`
|
||||
let moduleInfoPath = `${systemRoot}/module-info.json`
|
||||
let state = {
|
||||
partitionFiles: {},
|
||||
} as SystemState
|
||||
|
||||
// Files
|
||||
await withSpinner('Enumerating files', async (spinner) => {
|
||||
for (let partition of ALL_SYS_PARTITIONS) {
|
||||
spinner.text = partition
|
||||
|
||||
let files = await listPart(partition, systemRoot)
|
||||
if (files == null) continue
|
||||
|
||||
state.partitionFiles[partition] = files
|
||||
}
|
||||
})
|
||||
|
||||
// Props
|
||||
state.partitionProps = await withSpinner('Extracting properties', () =>
|
||||
loadPartitionProps(systemRoot))
|
||||
|
||||
// SELinux contexts
|
||||
state.partitionSecontexts = await withSpinner('Extracting SELinux contexts', () =>
|
||||
parsePartContexts(systemRoot))
|
||||
|
||||
// Overlays
|
||||
state.partitionOverlays = await withSpinner('Extracting overlays', (spinner) =>
|
||||
parsePartOverlayApks(aapt2Path, systemRoot, path => {
|
||||
spinner.text = path
|
||||
}))
|
||||
|
||||
// vintf info
|
||||
state.partitionVintfInfo = await withSpinner('Extracting vintf manifests', () =>
|
||||
loadPartVintfInfo(systemRoot))
|
||||
|
||||
// Module info
|
||||
state.moduleInfo = await withSpinner('Parsing module info', async () =>
|
||||
parseModuleInfo(await readFile(moduleInfoPath)))
|
||||
let state = await collectSystemState(device, outRoot, aapt2Path)
|
||||
|
||||
// Write
|
||||
await fs.writeFile(outPath, serializeSystemState(state))
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { PartResValues } from "../blobs/overlays"
|
||||
import { PartitionProps } from "../blobs/props"
|
||||
import { PartitionVintfInfo } from "../blobs/vintf"
|
||||
import { minimizeModules, SoongModuleInfo } from "../build/soong-info"
|
||||
import { SelinuxPartContexts } from "../selinux/contexts"
|
||||
import { listPart } from "../blobs/file-list"
|
||||
import { parsePartOverlayApks, PartResValues } from "../blobs/overlays"
|
||||
import { loadPartitionProps, PartitionProps } from "../blobs/props"
|
||||
import { loadPartVintfInfo, PartitionVintfInfo } from "../blobs/vintf"
|
||||
import { minimizeModules, parseModuleInfo, SoongModuleInfo } from "../build/soong-info"
|
||||
import { parsePartContexts, SelinuxPartContexts } from "../selinux/contexts"
|
||||
import { withSpinner } from "../util/cli"
|
||||
import { readFile } from "../util/fs"
|
||||
import { ALL_SYS_PARTITIONS } from "../util/partitions"
|
||||
|
||||
const STATE_VERSION = 1
|
||||
|
||||
|
@ -54,3 +58,47 @@ export function parseSystemState(json: string) {
|
|||
|
||||
return diskState as SystemState
|
||||
}
|
||||
|
||||
export async function collectSystemState(device: string, outRoot: string, aapt2Path: string) {
|
||||
let systemRoot = `${outRoot}/target/product/${device}`
|
||||
let moduleInfoPath = `${systemRoot}/module-info.json`
|
||||
let state = {
|
||||
partitionFiles: {},
|
||||
} as SystemState
|
||||
|
||||
// Files
|
||||
await withSpinner('Enumerating files', async (spinner) => {
|
||||
for (let partition of ALL_SYS_PARTITIONS) {
|
||||
spinner.text = partition
|
||||
|
||||
let files = await listPart(partition, systemRoot)
|
||||
if (files == null) continue
|
||||
|
||||
state.partitionFiles[partition] = files
|
||||
}
|
||||
})
|
||||
|
||||
// Props
|
||||
state.partitionProps = await withSpinner('Extracting properties', () =>
|
||||
loadPartitionProps(systemRoot))
|
||||
|
||||
// SELinux contexts
|
||||
state.partitionSecontexts = await withSpinner('Extracting SELinux contexts', () =>
|
||||
parsePartContexts(systemRoot))
|
||||
|
||||
// Overlays
|
||||
state.partitionOverlays = await withSpinner('Extracting overlays', (spinner) =>
|
||||
parsePartOverlayApks(aapt2Path, systemRoot, path => {
|
||||
spinner.text = path
|
||||
}))
|
||||
|
||||
// vintf info
|
||||
state.partitionVintfInfo = await withSpinner('Extracting vintf manifests', () =>
|
||||
loadPartVintfInfo(systemRoot))
|
||||
|
||||
// Module info
|
||||
state.moduleInfo = await withSpinner('Parsing module info', async () =>
|
||||
parseModuleInfo(await readFile(moduleInfoPath)))
|
||||
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue