|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const child_process = require('child_process'); |
| 4 | +const fs = require('fs'); |
| 5 | +const path = require('path'); |
| 6 | +const lldb = require('./lldb'); |
| 7 | + |
| 8 | +/** |
| 9 | + * Find the lldb to use in the installation of LLVM. |
| 10 | + * @returns {string} Path to the lldb executable or undefined |
| 11 | + */ |
| 12 | +function getLldbExecutable() { |
| 13 | + if (process.env.npm_config_lldb_exe !== undefined) { |
| 14 | + return process.env.npm_config_lldb_exe; |
| 15 | + } |
| 16 | + |
| 17 | + const lldbDir = lldb.findWindowsExeDir('lldb.exe'); |
| 18 | + if (lldbDir) { |
| 19 | + return path.join(lldbDir, 'lldb.exe'); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +/** |
| 24 | + * Get the directory containing the lldb library. |
| 25 | + * @param {string} lldbExe Path to the corresponding lldb executable |
| 26 | + * @returns {{dir:string, name:string}} |
| 27 | + */ |
| 28 | +function getLib(lldbExe) { |
| 29 | + const libName = 'liblldb.lib'; |
| 30 | + const libDir = path.resolve(path.dirname(lldbExe), '..', 'lib'); |
| 31 | + |
| 32 | + if (!fs.existsSync(path.join(libDir, libName))) { |
| 33 | + return { |
| 34 | + dir: undefined, |
| 35 | + name: libName |
| 36 | + }; |
| 37 | + } |
| 38 | + |
| 39 | + return { |
| 40 | + dir: libDir, |
| 41 | + name: libName |
| 42 | + }; |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * Get the lldb installation. If prefix is undefined, the headers need to |
| 47 | + * be downloaded. |
| 48 | + * The version string will be in the form like '3.9' |
| 49 | + */ |
| 50 | +function getLldbInstallation() { |
| 51 | + console.log('Looking for lldb executable...'); |
| 52 | + const lldbExe = getLldbExecutable(); |
| 53 | + if (!lldbExe) { |
| 54 | + console.log('Could not find any usable lldb executable'); |
| 55 | + console.log('Please see the README.md on how to install lldb'); |
| 56 | + process.exit(1); |
| 57 | + } |
| 58 | + console.log(`Found lldb executable ${lldbExe}`); |
| 59 | + |
| 60 | + console.log('\nReading lldb version...'); |
| 61 | + const lldbVersion = lldb.getLldbVersion(lldbExe); |
| 62 | + if (!lldbVersion) { |
| 63 | + console.log(`Unable to get the version from the lldb binary ${lldbExe}`); |
| 64 | + process.exit(1); |
| 65 | + } |
| 66 | + console.log(`Installing llnode for ${lldbExe}, lldb version ${lldbVersion}`); |
| 67 | + |
| 68 | + console.log(`\nLooking for shared libraries for lldb ${lldbVersion}...`); |
| 69 | + const lib = getLib(lldbExe); |
| 70 | + if (!lib.dir) { |
| 71 | + console.log(`Could not find ${lib.name} in the same path as the lldb executable`); |
| 72 | + process.exit(1); |
| 73 | + } else { |
| 74 | + console.log(`Found ${lib.name} in ${lib.dir}`); |
| 75 | + } |
| 76 | + |
| 77 | + return { |
| 78 | + executable: lldbExe, |
| 79 | + version: lldbVersion, |
| 80 | + includeDir: undefined, // Windows binary distribution does not contain headers |
| 81 | + libDir: lib.dir, |
| 82 | + libName: lib.name |
| 83 | + }; |
| 84 | +} |
| 85 | + |
| 86 | +module.exports = { |
| 87 | + getLldbInstallation |
| 88 | +}; |
0 commit comments