partitions: Describe partitions with TypeScript types

This commit is contained in:
Danny Lin 2021-11-28 18:47:02 -08:00
parent 53520850f9
commit 5ad4cad307
6 changed files with 42 additions and 12 deletions

View file

@ -2,7 +2,7 @@ import { promises as fs } from 'fs'
import { exists } from '../util/fs'
import { parseLines } from '../util/parse'
import { ALL_PARTITIONS } from '../util/partitions'
import { ALL_SYS_PARTITIONS } from '../util/partitions'
export type PartitionProps = Map<string, Map<string, string>>
@ -30,7 +30,7 @@ export function parseProps(file: string) {
export async function loadPartitionProps(sourceRoot: string) {
let partProps = new Map<string, Map<string, string>>() as PartitionProps
for (let partition of ALL_PARTITIONS) {
for (let partition of ALL_SYS_PARTITIONS) {
let propPath = `${sourceRoot}/${partition}/build.prop`
if (partition == 'system' && !(await exists(propPath))) {
// System-as-root

View file

@ -8,7 +8,7 @@ import { loadPartVintfInfo } from '../blobs/vintf'
import { serializeSystemState, SystemState } from '../config/system-state'
import { parsePartContexts } from '../selinux/contexts'
import { startActionSpinner, stopActionSpinner } from '../util/cli'
import { ALL_PARTITIONS } from '../util/partitions'
import { ALL_SYS_PARTITIONS } from '../util/partitions'
export default class CollectState extends Command {
static description = 'collect built system state for use with other commands'
@ -32,7 +32,7 @@ export default class CollectState extends Command {
// Files
let spinner = startActionSpinner('Enumerating files')
for (let partition of ALL_PARTITIONS) {
for (let partition of ALL_SYS_PARTITIONS) {
spinner.text = partition
let files = await listPart(partition, customRoot)

View file

@ -2,7 +2,7 @@ import { Command, flags } from '@oclif/command'
import chalk from 'chalk'
import { diffLists, listPart } from '../blobs/file_list'
import { ALL_PARTITIONS } from '../util/partitions'
import { ALL_SYS_PARTITIONS } from '../util/partitions'
export default class DiffFiles extends Command {
static description = 'find missing system files compared to a reference system'
@ -20,7 +20,7 @@ export default class DiffFiles extends Command {
async run() {
let {flags: {all}, args: {sourceRef, sourceNew}} = this.parse(DiffFiles)
for (let partition of ALL_PARTITIONS) {
for (let partition of ALL_SYS_PARTITIONS) {
let filesRef = await listPart(partition, sourceRef)
if (filesRef == null) {
continue

View file

@ -20,7 +20,7 @@ import { diffPartContexts, parseContextsRecursive, parsePartContexts, resolvePar
import { generateFileContexts } from '../selinux/labels'
import { startActionSpinner, stopActionSpinner } from '../util/cli'
import { withTempDir } from '../util/fs'
import { ALL_PARTITIONS } from '../util/partitions'
import { ALL_SYS_PARTITIONS } from '../util/partitions'
export default class GenerateFull extends Command {
static description = 'generate all vendor parts automatically'
@ -57,7 +57,7 @@ export default class GenerateFull extends Command {
// 1. Diff files
let spinner = startActionSpinner('Enumerating files')
for (let partition of ALL_PARTITIONS) {
for (let partition of ALL_SYS_PARTITIONS) {
let filesRef = await listPart(partition, stockRoot)
if (filesRef == null) continue
let filesNew = customState != null ? customState.partitionFiles[partition] :

View file

@ -2,7 +2,7 @@ import { Command, flags } from '@oclif/command'
import { promises as fs } from 'fs'
import { listPart } from '../blobs/file_list'
import { ALL_PARTITIONS } from '../util/partitions'
import { ALL_SYS_PARTITIONS } from '../util/partitions'
export default class ListFiles extends Command {
static description = 'list system files and symlinks important for blobs'
@ -21,7 +21,7 @@ export default class ListFiles extends Command {
await fs.mkdir(out, { recursive: true })
for (let partition of ALL_PARTITIONS) {
for (let partition of ALL_SYS_PARTITIONS) {
let files = await listPart(partition, systemRoot, true)
if (files == null) {
continue

View file

@ -1,4 +1,30 @@
export enum Partition {
// System
System = 'system',
SystemExt = 'system_ext',
Product = 'product',
Vendor = 'vendor',
VendorDlkm = 'vendor_dlkm',
Odm = 'odm',
OdmDlkm = 'odm_dlkm',
// Boot
Boot = 'boot',
Dt = 'dt',
Dtbo = 'dtbo',
PvmFw = 'pvmfw',
Recovery = 'recovery',
Vbmeta = 'vbmeta',
VbmetaSystem = 'vbmeta_system',
VbmetaVendor = 'vbmeta_vendor',
VendorBoot = 'vendor_boot',
}
// Android system partitions, excluding "system"
export type ExtSysPartition = Partition.SystemExt |
Partition.Product |
Partition.Vendor |
Partition.Odm
export const EXT_SYS_PARTITIONS = new Set([
'system_ext',
'product',
@ -7,15 +33,19 @@ export const EXT_SYS_PARTITIONS = new Set([
])
// GKI DLKM partitions
export type DlkmPartition = Partition.VendorDlkm |
Partition.OdmDlkm
export const DLKM_PARTITIONS = new Set([
'vendor_dlkm',
'odm_dlkm',
])
export type ExtPartition = ExtSysPartition | DlkmPartition
export const EXT_PARTITIONS = new Set([
...EXT_SYS_PARTITIONS,
...DLKM_PARTITIONS,
])
// All partitions
export const ALL_PARTITIONS = new Set(['system', ...EXT_PARTITIONS])
// All system partitions
export type SysPartition = Partition.System | ExtPartition
export const ALL_SYS_PARTITIONS = new Set(['system', ...EXT_PARTITIONS])