extract: Handle module name conflicts

This commit is contained in:
Danny Lin 2021-11-07 05:01:15 -08:00
parent 4c815172d4
commit 783129d138

View file

@ -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<string, SoongModule>()
let conflictCounters = new Map<string, number>()
for (let entry of entries) {
let ext = path.extname(entry.path)
@ -32,11 +33,21 @@ 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)) {
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)
namedModules.set(name, module)
} else {