From 783129d138fa5627f1ac0d1052ba089bda601a9b Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sun, 7 Nov 2021 05:01:15 -0800 Subject: [PATCH] extract: Handle module name conflicts --- src/commands/extract.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/commands/extract.ts b/src/commands/extract.ts index 430cbac..9f9c67c 100644 --- a/src/commands/extract.ts +++ b/src/commands/extract.ts @@ -3,7 +3,7 @@ import {promises as fs} from 'fs' import * as path from 'path' import * as chalk from 'chalk' -import { blobToSoongModule, serializeBlueprint, SoongModule } from '../build/soong' +import { blobToSoongModule, serializeBlueprint, SharedLibraryModule, SoongModule } from '../build/soong' import { BlobEntry } from '../blobs/entry' import { parseFileList } from '../blobs/file_list' import { copyBlobs } from '../blobs/copy' @@ -22,6 +22,7 @@ async function generateBuild( // Create Soong modules and Make rules let copyFiles = [] let namedModules = new Map() + let conflictCounters = new Map() for (let entry of entries) { let ext = path.extname(entry.path) @@ -32,9 +33,19 @@ async function generateBuild( // Module name = file name let name = path.basename(entry.path, ext) - // Skip if already done (e.g. other lib arch) + // If already exists: skip if it's the other arch variant of a library, + // otherwise rename the module to avoid conflict if (namedModules.has(name)) { - continue + let conflictModule = namedModules.get(name)! + if (conflictModule._type == 'cc_prebuilt_library_shared' && + (conflictModule as SharedLibraryModule).compile_multilib == 'both') { + continue + } + + // Increment conflict counter and append to name + let conflictNum = (conflictCounters.get(name) ?? 1) + 1 + conflictCounters.set(name, conflictNum) + name += `__${conflictNum}` } let module = blobToSoongModule(name, ext, vendor, entry, entrySrcPaths)