From 3534880f64e3c47e22eee2ca3e0022c95ea389b9 Mon Sep 17 00:00:00 2001 From: casey langen Date: Thu, 17 Feb 2022 19:41:07 -0800 Subject: [PATCH] Rough version of standalone dependency scanner. Hardcoded and Linux only now, but will be easy to port to macOS. --- script/.prettierrc | 5 +++ script/scan-standalone.js | 69 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 script/.prettierrc create mode 100644 script/scan-standalone.js diff --git a/script/.prettierrc b/script/.prettierrc new file mode 100644 index 000000000..e97ea1bfa --- /dev/null +++ b/script/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 2, + "useTabs": false, + "singleQuote": true +} diff --git a/script/scan-standalone.js b/script/scan-standalone.js new file mode 100644 index 000000000..0c2692a36 --- /dev/null +++ b/script/scan-standalone.js @@ -0,0 +1,69 @@ +const { promisify } = require('util'); +const exec = promisify(require('child_process').exec); +const readdir = promisify(require('fs').readdir); + +const validLibraries = new Set([ + 'linux-vdso.so.1', + 'libstdc++.so.6', + 'libm.so.6', + 'libgcc_s.so.1', + 'libc.so.6', + 'libz.so.1', + 'libdl.so.2', + '/lib64/ld-linux-x86-64.so.2', +]); + +let errors = 0; +const path = 'dist/0.96.14/musikcube_standalone_linux_x86_64_0.96.14'; + +async function ls(leaf) { + const output = await readdir(`${path}/${leaf}`); + const files = output.filter((fn) => fn.indexOf('.so') !== -1); + return files; +} + +async function ldd(fn) { + const output = await exec(`ldd ${path}/${fn}`); + const problems = output.stdout + .split('\n') + .map((line) => line.trim()) + /* libraries resolved properly will exist in the current path; exclude */ + .filter((line) => !!line && line.indexOf(path) === -1) + .filter((line) => line !== 'statically linked') + /* libraries are formatted as " [=> ] <(offset)>". if there's + a fat arrow, just grab everything to the left of it. then, if there's + still an offset, strip that as well */ + .map((line) => line.split(' => ')[0].split(' ')[0].trim()) + .filter((line) => !validLibraries.has(line)); + if (!problems.length) { + console.log(`${fn}: ok`); + } else { + console.log(`${fn}: potential problems found`); + problems.forEach((line) => console.log(` * ${line}`)); + ++errors; + } +} + +async function lddDir(leaf) { + const files = await ls(leaf); + await Promise.allSettled(files.map((fn) => ldd(`${leaf}/${fn}`))); +} + +const main = async () => { + await ldd('musikcube'); + await ldd('musikcubed'); + await ldd('libmusikcore.so'); + await lddDir('plugins'); + await lddDir('lib'); + + if (errors) { + console.log( + `\n\n\n ***** ${errors} problematic files detected! ***** \n\n\n` + ); + process.exit(1); + } + + console.log('\neverything looks good!\n'); +}; + +main();