diff --git a/src/build/overrides.ts b/src/build/overrides.ts index e77958e..53b0d34 100644 --- a/src/build/overrides.ts +++ b/src/build/overrides.ts @@ -1,3 +1,4 @@ +import { setIntersection } from '../util/data' import { parseLines } from '../util/parse' import { SoongModuleInfo, TargetModuleInfo } from './soong-info' @@ -20,11 +21,19 @@ export function parseOverrides(list: string) { } export function findOverrideModules(overridePaths: Iterable, modulesMap: SoongModuleInfo) { + // Build index of multilib modules + let multilibs = new Set() + for (let [name, module] of modulesMap.entries()) { + if (name.endsWith('_32')) { + multilibs.add(module.module_name) + } + } + // Build installed path->module index - let pathMap = new Map() - for (let module of modulesMap.values()) { + let pathMap = new Map() + for (let [key, module] of modulesMap.entries()) { for (let path of module.installed) { - pathMap.set(path, module) + pathMap.set(path, [key, module.module_name]) } } @@ -32,16 +41,51 @@ export function findOverrideModules(overridePaths: Iterable, modulesMap: let buildModules = new Set() let builtPaths = [] let missingPaths = [] + // Defer multlib modules (these are module_names without _32 or :32/:64) + let multilib32 = new Set() + let multilib64 = new Set() for (let path of overridePaths) { - let module = pathMap.get(path) - if (module != null) { - buildModules.add(module.module_name) + let value = pathMap.get(path) + if (value != null) { + let [key, module] = value + + if (multilibs.has(module)) { + // If this module is multilib, add it to the respective arch set instead + if (key.endsWith('_32')) { + // 32-bit only + multilib32.add(module) + } else { + // 64-bit only + multilib64.add(module) + } + } else { + // Otherwise, just build the module normally + buildModules.add(module) + } + + // Always add the path builtPaths.push(path) } else { missingPaths.push(path) } } + // Now resolve the multilib modules. Example: + // Both = libX + let multilibBoth = setIntersection(multilib32, multilib64) + // Then separate the remaining arch-specific modules (faster than new set difference) + multilibBoth.forEach(m => { + // 32 = libX:32 + multilib32.delete(m) + // 64 = libX:64 + multilib64.delete(m) + }) + + // Add final multilib modules + multilibBoth.forEach(m => buildModules.add(m)) + multilib32.forEach(m => buildModules.add(m + ':32')) + multilib64.forEach(m => buildModules.add(m + ':64')) + return { modules: Array.from(buildModules).sort((a, b) => a.localeCompare(b)), builtPaths: builtPaths,