diff --git a/src/commands/generate-prep.ts b/src/commands/generate-prep.ts index 55fc630..ed80264 100644 --- a/src/commands/generate-prep.ts +++ b/src/commands/generate-prep.ts @@ -6,6 +6,7 @@ import { BlobEntry } from '../blobs/entry' import { loadDeviceConfig } from '../config/device' import { enumerateFiles, extractProps, generateBuildFiles, PropResults } from '../frontend/generate' import { withSpinner } from '../util/cli' +import { withTempDir } from '../util/fs' export default class GeneratePrep extends Command { static description = 'generate vendor parts to prepare for reference AOSP build (e.g. for collect-state)' @@ -25,38 +26,41 @@ export default class GeneratePrep extends Command { let config = await loadDeviceConfig(configPath) - // Each step will modify this. Key = combined part path - let namedEntries = new Map() + // tmp may be needed for mounting/extracting stock images + await withTempDir(async (tmp) => { + // Each step will modify this. Key = combined part path + let namedEntries = new Map() - // Prepare output directories - let dirs = await createVendorDirs(config.device.vendor, config.device.name) + // Prepare output directories + let dirs = await createVendorDirs(config.device.vendor, config.device.name) - // 1. Diff files - await withSpinner('Enumerating files', (spinner) => - enumerateFiles(spinner, config.filters.dep_files, null, namedEntries, null, - stockSrc, null)) + // 1. Diff files + await withSpinner('Enumerating files', (spinner) => + enumerateFiles(spinner, config.filters.dep_files, null, namedEntries, null, + stockSrc)) - // After this point, we only need entry objects - let entries = Array.from(namedEntries.values()) + // After this point, we only need entry objects + let entries = Array.from(namedEntries.values()) - // 2. Extract - // Copy blobs (this has its own spinner) - if (config.generate.files && !skipCopy) { - await copyBlobs(entries, stockSrc, dirs.proprietary) - } + // 2. Extract + // Copy blobs (this has its own spinner) + if (config.generate.files && !skipCopy) { + await copyBlobs(entries, stockSrc, dirs.proprietary) + } - // 3. Props - let propResults: PropResults | null = null - if (config.generate.props) { - propResults = await withSpinner('Extracting properties', () => - extractProps(config, null, stockSrc, null)) - delete propResults.missingProps - delete propResults.fingerprint - } + // 3. Props + let propResults: PropResults | null = null + if (config.generate.props) { + propResults = await withSpinner('Extracting properties', () => + extractProps(config, null, stockSrc)) + delete propResults.missingProps + delete propResults.fingerprint + } - // 4. Build files - await withSpinner('Generating build files', () => - generateBuildFiles(config, dirs, entries, [], propResults, null, null, null, - stockSrc, false, true)) + // 4. Build files + await withSpinner('Generating build files', () => + generateBuildFiles(config, dirs, entries, [], propResults, null, null, null, + stockSrc, false, true)) + }) } } diff --git a/src/frontend/generate.ts b/src/frontend/generate.ts index 4c4d29f..f3016e4 100644 --- a/src/frontend/generate.ts +++ b/src/frontend/generate.ts @@ -34,13 +34,13 @@ export async function enumerateFiles( filters: Filters, forceIncludeFilters: Filters | null, namedEntries: Map, - customState: SystemState, + customState: SystemState | null, stockSrc: string, ) { for (let partition of ALL_SYS_PARTITIONS) { let filesRef = await listPart(partition, stockSrc, filters) if (filesRef == null) continue - let filesNew = customState.partitionFiles[partition] + let filesNew = customState?.partitionFiles[partition] ?? [] if (filesNew == undefined) continue let missingFiles = diffLists(filesNew, filesRef) @@ -117,11 +117,11 @@ export async function flattenApexs( export async function extractProps( config: DeviceConfig, - customState: SystemState, + customState: SystemState | null, stockSrc: string, ) { let stockProps = await loadPartitionProps(stockSrc) - let customProps = customState.partitionProps + let customProps = customState?.partitionProps ?? new Map>() // Filters for (let props of stockProps.values()) {