From 31a18c6697f12fc05983a90fd8380250ad428373 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sun, 21 Nov 2021 19:43:39 -0800 Subject: [PATCH] util: Add general subprocess helper --- src/blobs/overlays.ts | 2 +- src/blobs/presigned.ts | 2 +- src/util/{aapt2.ts => process.ts} | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) rename src/util/{aapt2.ts => process.ts} (63%) diff --git a/src/blobs/overlays.ts b/src/blobs/overlays.ts index 9ad9171..622aaf9 100644 --- a/src/blobs/overlays.ts +++ b/src/blobs/overlays.ts @@ -3,7 +3,7 @@ import * as path from 'path' import * as xml2js from 'xml2js' import { serializeBlueprint } from '../build/soong' -import { aapt2 } from '../util/aapt2' +import { aapt2 } from '../util/process' import { exists, listFilesRecursive } from '../util/fs' import { XML_HEADER } from '../util/headers' import { parseLines } from '../util/parse' diff --git a/src/blobs/presigned.ts b/src/blobs/presigned.ts index 7307c7c..9a7fc0a 100644 --- a/src/blobs/presigned.ts +++ b/src/blobs/presigned.ts @@ -2,7 +2,7 @@ import { promises as fs } from 'fs' import * as path from 'path' import { parseSeappContexts } from '../sepolicy/seapp' -import { aapt2 } from '../util/aapt2' +import { aapt2 } from '../util/process' import { listFilesRecursive } from '../util/fs' import { BlobEntry } from './entry' diff --git a/src/util/aapt2.ts b/src/util/process.ts similarity index 63% rename from src/util/aapt2.ts rename to src/util/process.ts index 4e61957..24211d0 100644 --- a/src/util/aapt2.ts +++ b/src/util/process.ts @@ -3,8 +3,12 @@ import { exec as execCb } from 'child_process' const exec = util.promisify(execCb) -export async function aapt2(path: string, ...args: Array) { +export async function run(command: string) { // TODO: stop using shell - let { stdout, stderr } = await exec(`${path} ${args.join(' ')}`) + let { stdout } = await exec(command) return stdout.trim() } + +export async function aapt2(path: string, ...args: Array) { + return await run(`${path} ${args.join(' ')}`) +}