(generatedModules: W2CGeneratedModule[])
| 3 | import { HEADER } from './common.js'; |
| 4 | |
| 5 | export function buildLoaderSource(generatedModules: W2CGeneratedModule[]) { |
| 6 | const moduleBagType = new cpp.TypeBuilder('ModuleBag'); |
| 7 | |
| 8 | function makeModuleFactoryDecl(module: W2CGeneratedModule) { |
| 9 | return `std::shared_ptr<Module> ${module.moduleFactoryFunctionName}();`; |
| 10 | } |
| 11 | |
| 12 | const moduleEntries = generatedModules.map((m) => |
| 13 | cpp.exprs.initializerListOf([ |
| 14 | cpp.exprs.string(m.name), |
| 15 | cpp.exprs.string(m.checksum.toString('hex')), |
| 16 | cpp.exprs.symbol(m.moduleFactoryFunctionName), |
| 17 | ]) |
| 18 | ); |
| 19 | |
| 20 | const moduleBagVar = new cpp.VariableBuilder('moduleBag') |
| 21 | .withType(moduleBagType.asConst()) |
| 22 | .withInitializer((v) => v.listOf(moduleEntries, true), true); |
| 23 | |
| 24 | const moduleBagGetterFunc = new cpp.FunctionBuilder('getModuleBag') |
| 25 | .withReturnType(moduleBagVar.type.asRef()) |
| 26 | .withBody((b) => b.return_(moduleBagVar.name)); |
| 27 | |
| 28 | const builder = new cpp.SourceFileBuilder(true); |
| 29 | builder |
| 30 | .insertRaw(HEADER) |
| 31 | .includeSystem('ReactNativePolygen/Loader.h') |
| 32 | .spacing(1) |
| 33 | .namespace('callstack::polygen::generated', (builder) => |
| 34 | builder |
| 35 | .writeManyLines(generatedModules, makeModuleFactoryDecl) |
| 36 | .spacing(1) |
| 37 | .defineVariable(moduleBagVar) |
| 38 | .defineFunction(moduleBagGetterFunc) |
| 39 | ); |
| 40 | |
| 41 | return builder.toString(); |
| 42 | } |
nothing calls this directly
no test coverage detected