From 455b85146dcb528f8a0eb8d8ec13232856267d07 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Tue, 9 Nov 2021 19:53:43 -0800 Subject: [PATCH] blobs: file_list: Switch to new helpers and add serialization --- src/blobs/file_list.ts | 58 +++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/blobs/file_list.ts b/src/blobs/file_list.ts index e255e9e..0bf01b3 100644 --- a/src/blobs/file_list.ts +++ b/src/blobs/file_list.ts @@ -1,10 +1,10 @@ import * as path from 'path' -import * as chalk from 'chalk' -import * as ora from 'ora' import { EXT_PARTITIONS } from '../util/partitions' -import { BlobEntry } from './entry' +import { BlobEntry, partPathToSrcPath, srcPathToPartPath } from './entry' import { exists, listFilesRecursive } from '../util/fs' +import { MAKEFILE_HEADER } from '../build/make' +import { createActionSpinner, stopActionSpinner } from '../util/cli' import { parseLines } from '../util/parse' // Sub-partition directories to ignore @@ -184,15 +184,7 @@ export function parseFileList(list: string) { } // Split path into partition and sub-partition path - let pathParts = srcPath.split('/') - let partition = pathParts[0] - let path: string - if (EXT_PARTITIONS.has(partition)) { - path = pathParts.slice(1).join('/') - } else { - partition = 'system' - path = srcPath - } + let [partition, path] = srcPathToPartPath(srcPath) entries.push({ partition: partition, @@ -219,10 +211,7 @@ export async function listPart(partition: string, systemRoot: string, showSpinne } let refRoot = path.dirname(partRoot) - let spinner = ora({ - prefixText: chalk.bold(chalk.greenBright(`Listing ${partition}`)), - color: 'green', - }) + let spinner = createActionSpinner(`Listing ${partition}`) if (showSpinner) { spinner.start() } @@ -247,9 +236,44 @@ export async function listPart(partition: string, systemRoot: string, showSpinne }) if (showSpinner) { - spinner.stopAndPersist() + stopActionSpinner(spinner) } // Sort and return raw path list return files.sort((a, b) => a.localeCompare(b)) } + +export function serializeBlobList(entries: Iterable) { + let lines = [] + for (let entry of entries) { + let depFlag = entry.isNamedDependency ? '-' : '' + let suffixFlags = entry.isPresigned ? ';PRESIGNED' : '' + lines.push(depFlag + entry.srcPath + suffixFlags) + } + + return `${MAKEFILE_HEADER} + +${lines.join('\n')}` +} + +export function diffLists(filesRef: Array, filesNew: Array) { + let setRef = new Set(filesRef) + return filesNew.filter(f => !setRef.has(f)).sort((a, b) => a.localeCompare(b)) +} + +export function combinedPartPathToEntry(partition: string, combinedPartPath: string) { + // Decompose into 2-part partition path + let partPath = combinedPartPath.split('/').slice(1).join('/') + + // Convert to source path + let srcPath = partPathToSrcPath(partition, partPath) + + return { + partition: partition, + path: partPath, + srcPath: srcPath, + isPresigned: false, + // TODO + isNamedDependency: false, + } +}