frontend: source: Propagate extracted factory images path

This commit is contained in:
Danny Lin 2021-12-18 03:06:37 -08:00
parent 860c21c077
commit 6b98117f76
3 changed files with 33 additions and 33 deletions

View file

@ -19,10 +19,19 @@ const doDevice = (
customSrc: string,
aapt2Path: string,
buildId: string | undefined,
factoryZip: string | undefined,
factoryPath: string | undefined,
skipCopy: boolean,
useTemp: boolean,
) => withTempDir(async (tmp) => {
// Prepare stock system source
let wrapBuildId = buildId == undefined ? null : buildId
let wrapped = await withSpinner('Extracting stock system source', (spinner) =>
wrapSystemSrc(stockSrc, config.device.name, wrapBuildId, useTemp, tmp, spinner))
stockSrc = wrapped.src!
if (wrapped.factoryPath != null && factoryPath == undefined) {
factoryPath = wrapped.factoryPath
}
// customSrc can point to a system state JSON or out/
let customState: SystemState
if ((await fs.stat(customSrc)).isFile()) {
@ -31,15 +40,6 @@ const doDevice = (
customState = await collectSystemState(config.device.name, customSrc, aapt2Path)
}
// Prepare stock system source
let wrapBuildId = buildId == undefined ? null : buildId
let wrapped = await withSpinner('Extracting stock system source', (spinner) =>
wrapSystemSrc(stockSrc, config.device.name, wrapBuildId, useTemp, tmp, spinner))
stockSrc = wrapped.src!
if (wrapped.factoryZip != null && factoryZip == undefined) {
factoryZip = wrapped.factoryZip
}
// Each step will modify this. Key = combined part path
let namedEntries = new Map<string, BlobEntry>()
@ -109,13 +109,13 @@ const doDevice = (
// 10. Firmware
let fwPaths: Array<string> | null = null
if (config.generate.factory_firmware && factoryZip != undefined) {
if (config.generate.factory_firmware && factoryPath != undefined) {
if (propResults == null) {
throw new Error('Factory firmware extraction depends on properties')
}
fwPaths = await withSpinner('Extracting firmware', () =>
extractFirmware(config, dirs, propResults!.stockProps, factoryZip!))
extractFirmware(config, dirs, propResults!.stockProps, factoryPath!))
}
// 11. Build files
@ -133,7 +133,7 @@ export default class GenerateFull extends Command {
buildId: flags.string({char: 'b', description: 'build ID of the stock images'}),
stockSrc: flags.string({char: 's', description: 'path to (extracted) factory images, (mounted) images, (extracted) OTA package, OTA payload, or directory containing any such files (optionally under device and/or build ID directory)', required: true}),
customSrc: flags.string({char: 'c', description: 'path to AOSP build output directory (out/) or JSON state file', default: 'out'}),
factoryZip: flags.string({char: 'f', description: 'path to stock factory images zip (for extracting firmware if stockSrc is not factory images)'}),
factoryPath: flags.string({char: 'f', description: 'path to stock factory images zip (for extracting firmware if stockSrc is not factory images)'}),
skipCopy: flags.boolean({char: 'k', description: 'skip file copying and only generate build files', default: false}),
useTemp: flags.boolean({char: 't', description: 'use a temporary directory for all extraction (prevents reusing extracted files across runs)', default: false}),
parallel: flags.boolean({char: 'p', description: 'generate devices in parallel (causes buggy progress spinners)', default: false}),
@ -149,7 +149,7 @@ export default class GenerateFull extends Command {
buildId,
stockSrc,
customSrc,
factoryZip,
factoryPath,
skipCopy,
useTemp,
parallel,
@ -167,7 +167,7 @@ ${chalk.bold(chalk.blueBright(config.device.name))}
}
let job = doDevice(config, stockSrc, customSrc, aapt2Path, buildId,
factoryZip, skipCopy, useTemp)
factoryPath, skipCopy, useTemp)
if (parallel) {
jobs.push(job)
} else {

View file

@ -237,9 +237,9 @@ export async function extractFirmware(
config: DeviceConfig,
dirs: VendorDirectories,
stockProps: PartitionProps,
factoryZip: string,
factoryPath: string,
) {
let fwImages = await extractFactoryFirmware(factoryZip)
let fwImages = await extractFactoryFirmware(factoryPath)
let fwPaths = await writeFirmwareImages(fwImages, dirs.firmware)
// Generate android-info.txt from device and versions

View file

@ -10,7 +10,7 @@ import { listZipFiles } from '../util/zip'
export interface WrappedSource {
src: string | null
factoryZip: string | null
factoryPath: string | null
}
async function containsParts(src: string, suffix: string = '') {
@ -97,7 +97,7 @@ class SourceResolver {
private async wrapLeafFile(
file: string,
factoryZip: string | null,
factoryPath: string | null,
): Promise<WrappedSource> {
let imagesTmp = await this.createDynamicTmp(
`src_images/${path.basename(file)}`,
@ -114,7 +114,7 @@ class SourceResolver {
let extractedDir = (await fs.readdir(imagesTmp.dir))[0]
let imagesPath = `${imagesTmp.dir}/${extractedDir}`
return await this.searchLeafDir(imagesPath, factoryZip)
return await this.searchLeafDir(imagesPath, factoryPath)
}
let files = await listZipFiles(file)
@ -135,7 +135,7 @@ class SourceResolver {
this.spinner.text = `extracting OTA payload: ${file}`
let payloadFile = `${imagesTmp.dir}/payload.bin`
await run(`unzip -d ${imagesTmp.dir} ${file} payload.bin`)
return await this.wrapLeafFile(payloadFile, factoryZip)
return await this.wrapLeafFile(payloadFile, factoryPath)
} else if (files.find(f => f.endsWith('.img') && ALL_SYS_PARTITIONS.has(f.replace('.img', '')))) {
// Images zip
@ -145,7 +145,7 @@ class SourceResolver {
if (file.startsWith(this.tmp.dir)) {
await fs.rm(file)
}
return await this.searchLeafDir(imagesTmp.dir, factoryZip)
return await this.searchLeafDir(imagesTmp.dir, factoryPath)
} else {
throw new Error(`File '${file}' has unknown format`)
}
@ -153,37 +153,37 @@ class SourceResolver {
private async searchLeafDir(
src: string,
factoryZip: string | null,
factoryPath: string | null,
): Promise<WrappedSource> {
if (!(await exists(src))) {
return {
src: null,
factoryZip: null,
factoryPath: null,
}
}
if (await containsParts(src)) {
// Root of mounted images
return { src, factoryZip }
return { src, factoryPath }
} else if (await containsParts(src, '.img.raw')) {
// Mount raw images: <images>.img.raw
// Mount the images
let mountTmp = await createSubTmp(this.tmp, `sysroot/${path.basename(src)}`)
await this.mountParts(src, mountTmp, '.img.raw')
return { src: mountTmp.dir, factoryZip }
return { src: mountTmp.dir, factoryPath: factoryPath || src }
} else if (await containsParts(src, '.img')) {
// Mount potentially-sparse images: <images>.img
// Mount the images
let mountTmp = await createSubTmp(this.tmp, `sysroot/${path.basename(src)}`)
await this.mountParts(src, mountTmp)
return { src: mountTmp.dir, factoryZip }
return { src: mountTmp.dir, factoryPath: factoryPath || src }
} else if (this.device != null && this.buildId != null) {
let imagesZip = `${src}/image-${this.device}-${this.buildId}.zip`
if (await exists(imagesZip)) {
// Factory images - nested images package: image-$device-$buildId.zip
return await this.wrapLeafFile(imagesZip, factoryZip)
return await this.wrapLeafFile(imagesZip, factoryPath || src)
}
let factoryPath = (await fs.readdir(src))
@ -196,7 +196,7 @@ class SourceResolver {
return {
src: null,
factoryZip: null,
factoryPath: null,
}
}
@ -224,10 +224,10 @@ class SourceResolver {
}
for (let dir of tryDirs) {
let { src: wrapped, factoryZip } = await this.searchLeafDir(dir, null)
let { src: wrapped, factoryPath } = await this.searchLeafDir(dir, null)
if (wrapped != null) {
this.spinner.text = wrapped.startsWith(this.tmp.dir) ? path.relative(this.tmp.dir, wrapped) : wrapped
return { src: wrapped, factoryZip }
return { src: wrapped, factoryPath }
}
}
@ -236,10 +236,10 @@ class SourceResolver {
// File
// Attempt to extract factory images or OTA
let { src: wrapped, factoryZip } = await this.wrapLeafFile(src, null)
let { src: wrapped, factoryPath } = await this.wrapLeafFile(src, null)
if (wrapped != null) {
this.spinner.text = wrapped.startsWith(this.tmp.dir) ? path.relative(this.tmp.dir, wrapped) : wrapped
return { src: wrapped, factoryZip }
return { src: wrapped, factoryPath }
}
}