(filePath)
| 1196 | } |
| 1197 | |
| 1198 | async function modifyNativeDebugSymbolsArchive (filePath) { |
| 1199 | let allowExtraDebugSymbols = false; |
| 1200 | |
| 1201 | const tdlibPath = path.join(settings.TGX_SOURCE_PATH, 'tdlib'); |
| 1202 | const extraNativeDebugSymbolsPath = settings.TDLIB_SYMBOLS_PATH || path.join(tdlibPath, 'source', 'build', 'native-debug-symbols'); |
| 1203 | if (settings.add_tdlib_debug_symbols === true && fs.existsSync(extraNativeDebugSymbolsPath)) { |
| 1204 | // Make sure tdlib/version.txt and tdlib/source/build/native-debug-symbols/version.txt match |
| 1205 | const tdlibVersionPath = path.join(tdlibPath, 'version.txt'); |
| 1206 | const extraNativeDebugSymbolsVersionPath = path.join(extraNativeDebugSymbolsPath, 'version.txt'); |
| 1207 | if (fs.existsSync(tdlibVersionPath) && fs.existsSync(extraNativeDebugSymbolsVersionPath)) { |
| 1208 | const tdlibVersion = fs.readFileSync(tdlibVersionPath); |
| 1209 | const extraNativeDebugSymbolsVersion = fs.readFileSync(extraNativeDebugSymbolsVersionPath); |
| 1210 | allowExtraDebugSymbols = tdlibVersion.equals(extraNativeDebugSymbolsVersion); |
| 1211 | console.log('TDLib and native-debug-symbols match:', allowExtraDebugSymbols); |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | if (settings.modify_debug_symbols !== true && !allowExtraDebugSymbols) { |
| 1216 | console.log('Using original native-debug-symbols.zip'); |
| 1217 | return filePath; |
| 1218 | } |
| 1219 | |
| 1220 | const existingArchivePath = path.parse(filePath); |
| 1221 | const temporaryExtractedDirPath = path.join(existingArchivePath.dir, existingArchivePath.name + '-unzipped-temp'); |
| 1222 | const modifiedArchivePath = path.join(existingArchivePath.dir, existingArchivePath.name + '-modified' + existingArchivePath.ext); |
| 1223 | |
| 1224 | const existingZip = new AdmZip(filePath); |
| 1225 | |
| 1226 | if (fs.existsSync(modifiedArchivePath)) { |
| 1227 | fs.unlinkSync(modifiedArchivePath) |
| 1228 | } |
| 1229 | if (fs.existsSync(temporaryExtractedDirPath)) { |
| 1230 | fs.rmdirSync(temporaryExtractedDirPath, { recursive: true, force: true }); |
| 1231 | } |
| 1232 | |
| 1233 | existingZip.extractAllTo(temporaryExtractedDirPath, true); |
| 1234 | |
| 1235 | if (fs.existsSync(temporaryExtractedDirPath)) { |
| 1236 | let addedCount = 0; |
| 1237 | if (allowExtraDebugSymbols) { |
| 1238 | // Copy *.so.dbg related to TDLib to extracted directory |
| 1239 | const copyFiles = (dirPath, relativeDirPath) => { |
| 1240 | const files = fs.readdirSync(dirPath); |
| 1241 | files.forEach((fileName) => { |
| 1242 | const childFilePath = path.join(dirPath, fileName); |
| 1243 | if (fs.statSync(childFilePath).isDirectory()) { |
| 1244 | copyFiles(childFilePath, relativeDirPath ? path.join(relativeDirPath, fileName) : fileName); |
| 1245 | } else if (fileName.match(/^.+\.so\.dbg$/g)) { |
| 1246 | const toFilePath = relativeDirPath ? |
| 1247 | path.join(temporaryExtractedDirPath, relativeDirPath, fileName) : |
| 1248 | path.join(temporaryExtractedDirPath, fileName); |
| 1249 | if (!fs.existsSync(toFilePath)) { |
| 1250 | fs.copyFileSync(childFilePath, toFilePath); |
| 1251 | addedCount++; |
| 1252 | } |
| 1253 | } |
| 1254 | }); |
| 1255 | }; |
no test coverage detected