From 59ee9628112e110b9926447c976f80d574cae38d Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Mon, 13 Dec 2021 10:30:23 -0800 Subject: [PATCH] state: Add minimized module info --- src/build/soong-info.ts | 34 ++++++++++++++------ src/commands/collect-state.ts | 59 +++++++++++++++++++---------------- src/config/system-state.ts | 4 +++ 3 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/build/soong-info.ts b/src/build/soong-info.ts index a1e41dc..8cae11f 100644 --- a/src/build/soong-info.ts +++ b/src/build/soong-info.ts @@ -3,16 +3,18 @@ export interface TargetModuleInfo { path: Array tags: Array installed: Array - compatibility_suites: Array - auto_test_config: Array - module_name: string - test_config: Array - dependencies: Array srcs: Array - srcjars: Array - classes_jar: Array - test_mainline_modules: Array - is_unit_test: string + + // Removed to reduce size in SystemState + compatibility_suites?: Array + auto_test_config?: Array + module_name?: string + test_config?: Array + dependencies?: Array + srcjars?: Array + classes_jar?: Array + test_mainline_modules?: Array + is_unit_test?: string } export type SoongModuleInfo = Map @@ -30,3 +32,17 @@ export function removeSelfModules(modulesMap: SoongModuleInfo, proprietaryDir: s } } } + +export function minimizeModules(info: SoongModuleInfo) { + for (let module of info.values()) { + delete module.compatibility_suites + delete module.auto_test_config + delete module.module_name + delete module.test_config + delete module.dependencies + delete module.srcjars + delete module.classes_jar + delete module.test_mainline_modules + delete module.is_unit_test + } +} diff --git a/src/commands/collect-state.ts b/src/commands/collect-state.ts index bc71d75..03aeb1e 100644 --- a/src/commands/collect-state.ts +++ b/src/commands/collect-state.ts @@ -5,9 +5,11 @@ 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 { startActionSpinner, stopActionSpinner } from '../util/cli' +import { withSpinner } from '../util/cli' +import { readFile } from '../util/fs' import { ALL_SYS_PARTITIONS } from '../util/partitions' export default class CollectState extends Command { @@ -16,7 +18,8 @@ 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'}), - customRoot: flags.string({char: 'c', description: 'path to root of custom compiled system (out/target/product/$device)', required: true}), + 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'}), } static args = [ @@ -24,45 +27,47 @@ export default class CollectState extends Command { ] async run() { - let {flags: {aapt2: aapt2Path, customRoot}, args: {output_path: outPath}} = this.parse(CollectState) + let {flags: {aapt2: aapt2Path, device, root}, 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 - let spinner = startActionSpinner('Enumerating files') - for (let partition of ALL_SYS_PARTITIONS) { - spinner.text = partition - - let files = await listPart(partition, customRoot) - if (files == null) continue - - state.partitionFiles[partition] = files - } - stopActionSpinner(spinner) + 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 - spinner = startActionSpinner('Extracting properties') - state.partitionProps = await loadPartitionProps(customRoot) - stopActionSpinner(spinner) + state.partitionProps = await withSpinner('Extracting properties', () => + loadPartitionProps(systemRoot)) // SELinux contexts - spinner = startActionSpinner('Extracting SELinux contexts') - state.partitionSecontexts = await parsePartContexts(customRoot) - stopActionSpinner(spinner) + state.partitionSecontexts = await withSpinner('Extracting SELinux contexts', () => + parsePartContexts(systemRoot)) // Overlays - spinner = startActionSpinner('Extracting overlays') - state.partitionOverlays = await parsePartOverlayApks(aapt2Path, customRoot, path => { - spinner.text = path - }) - stopActionSpinner(spinner) + state.partitionOverlays = await withSpinner('Extracting overlays', (spinner) => + parsePartOverlayApks(aapt2Path, systemRoot, path => { + spinner.text = path + })) // vintf info - spinner = startActionSpinner('Extracting vintf manifests') - state.partitionVintfInfo = await loadPartVintfInfo(customRoot) - stopActionSpinner(spinner) + state.partitionVintfInfo = await withSpinner('Extracting vintf manifests', () => + loadPartVintfInfo(systemRoot)) + + // Module info + state.moduleInfo = await withSpinner('Parsing module info', async () => + parseModuleInfo(await readFile(moduleInfoPath))) // Write await fs.writeFile(outPath, serializeSystemState(state)) diff --git a/src/config/system-state.ts b/src/config/system-state.ts index e6de55e..5a276cc 100644 --- a/src/config/system-state.ts +++ b/src/config/system-state.ts @@ -1,6 +1,7 @@ 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" const STATE_VERSION = 1 @@ -11,6 +12,7 @@ export interface SystemState { partitionSecontexts: SelinuxPartContexts partitionOverlays: PartResValues partitionVintfInfo: PartitionVintfInfo + moduleInfo: SoongModuleInfo } type SerializedSystemState = { @@ -18,6 +20,8 @@ type SerializedSystemState = { } & SystemState export function serializeSystemState(state: SystemState) { + minimizeModules(state.moduleInfo) + let diskState = { version: STATE_VERSION, ...state,