-
-
Notifications
You must be signed in to change notification settings - Fork 103
package.json: Make llnode installable via npm #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a131fd9
package.json: Make llnode installable via npm
hhellyer 76cbbfb
Improve detection of lldb executable on Linux.
hhellyer 848005f
package.json: test install from npmjs.org
hhellyer 2e5461d
Run eslint and fix code formatting issues.
hhellyer 7813eb0
Restore version to 1.4.1
hhellyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| llnode.gyp.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| { | ||
| "variables": { | ||
| # gyp does not appear to let you test for undefined variables, so define | ||
| # lldb_build_dir as empty so we can test it later. | ||
| "lldb_build_dir%": "" | ||
| }, | ||
|
|
||
| "targets": [{ | ||
| "target_name": "llnode", | ||
| "type": "shared_library", | ||
| "product_prefix": "", | ||
|
|
||
| "include_dirs": [ | ||
| ".", | ||
| "<(lldb_dir)/include", | ||
| ], | ||
|
|
||
| "sources": [ | ||
| "src/llnode.cc", | ||
| "src/llv8.cc", | ||
| "src/llv8-constants.cc", | ||
| "src/llscan.cc", | ||
| ], | ||
|
|
||
| "conditions": [ | ||
| [ "OS == 'mac'", { | ||
| "conditions": [ | ||
| [ "lldb_build_dir == ''", { | ||
| "variables": { | ||
| "mac_shared_frameworks": "/Applications/Xcode.app/Contents/SharedFrameworks", | ||
| }, | ||
| "xcode_settings": { | ||
| "OTHER_LDFLAGS": [ | ||
| "-F<(mac_shared_frameworks)", | ||
| "-Wl,-rpath,<(mac_shared_frameworks)", | ||
| "-framework LLDB", | ||
| ], | ||
| }, | ||
| }, | ||
| # lldb_builddir != "" | ||
| { | ||
| "xcode_settings": { | ||
| "OTHER_LDFLAGS": [ | ||
| "-Wl,-rpath,<(lldb_build_dir)/lib", | ||
| "-L<(lldb_build_dir)/lib", | ||
| "-l<(lldb_lib)", | ||
| ], | ||
| }, | ||
| }], | ||
| ], | ||
| }], | ||
| ] | ||
| }], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 'use strict'; | ||
|
|
||
| const os = require('os'); | ||
| const child_process = require('child_process'); | ||
|
|
||
| const cwd = process.cwd(); | ||
| const osName = os.type(); | ||
| var libExt = 'so'; | ||
|
|
||
| if (osName === 'Darwin') { | ||
| libExt = 'dylib'; | ||
| } | ||
|
|
||
| const llnodeLib = `llnode.${libExt}`; | ||
|
|
||
| // Move the library somewhere easy to remember. | ||
| console.log(`Copying ${cwd}/out/Release/${llnodeLib} to ${cwd}/${llnodeLib}`); | ||
| child_process.execSync(`mv ${cwd}/out/Release/${llnodeLib} ${cwd}/${llnodeLib}`); | ||
|
|
||
| console.log(`${os.EOL}llnode plugin installed, load in lldb with:`); | ||
| console.log(`(lldb) plugin load ${cwd}/${llnodeLib}${os.EOL}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| 'use strict'; | ||
|
|
||
| const os = require('os'); | ||
| const fs = require('fs'); | ||
| const child_process = require('child_process'); | ||
|
|
||
| const lldbReleases = { | ||
| '4.0': 'master', | ||
| '3.9': 'release_39', | ||
| '3.8': 'release_38', | ||
| '3.7': 'release_37', | ||
| '3.6': 'release_36', | ||
| '3.5': 'release_35', | ||
| '3.4': 'release_34', | ||
| }; | ||
|
|
||
| const buildDir = process.cwd(); | ||
|
|
||
| console.log('Build dir is: ' + buildDir); | ||
|
|
||
| const osName = os.type(); | ||
|
|
||
| var lldbVersion; | ||
| var lldbHeadersBranch; | ||
| var lldbIncludeDir; | ||
|
|
||
| // Need to determine: | ||
| // - What level of lldb we are running. | ||
| // - If we need the headers. (Linux may have them installed) | ||
| var lldbExe = 'lldb'; | ||
|
|
||
| if (osName === 'Darwin') { | ||
|
|
||
| lldbVersion = getDarwinRelease(); | ||
|
|
||
| if (lldbVersion === undefined) { | ||
| console.log('Unable to locate lldb binary. llnode installation failed.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| lldbHeadersBranch = lldbReleases[lldbVersion]; | ||
| lldbIncludeDir = 'lldb-' + lldbVersion; | ||
|
|
||
| } else if (osName === 'Linux') { | ||
|
|
||
| lldbExe = getLldbExecutable(); | ||
| lldbVersion = getLinuxVersion(lldbExe); | ||
|
|
||
| if (lldbVersion === undefined) { | ||
| console.log('Unable to locate lldb binary. llnode installation failed.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // console.log('lldb_version is ' + lldb_version) | ||
| var installedHeadersDir = getLinuxHeadersDir(lldbVersion); | ||
| // console.log('installed_headers_dir is ' + installed_headers_dir); | ||
| if (installedHeadersDir === undefined) { | ||
| // Initialising lldb_headers_branch will cause us to clone them. | ||
| lldbHeadersBranch = lldbReleases[lldbVersion]; | ||
| lldbIncludeDir = 'lldb-' + lldbVersion; | ||
| } else { | ||
| lldbIncludeDir = installedHeadersDir; | ||
| } | ||
| } | ||
|
|
||
| console.log(`Installing llnode for ${lldbExe}, lldb version ${lldbVersion}`); | ||
|
|
||
| // Check out source code of the LLDB that is compatible with OS X's default lldb | ||
| // TODO: The llvm project is probably moving to github soon at that point we | ||
| // should stop using the mirror. | ||
| if (lldbHeadersBranch != undefined) { | ||
| console.log('Cloning lldb from ' + lldbHeadersBranch); | ||
| child_process.execFileSync('git', | ||
| ['clone', '--depth=1', '-b', lldbHeadersBranch, | ||
| 'https://github.com/llvm-mirror/lldb.git', lldbIncludeDir], | ||
| {cwd: buildDir}); | ||
| } | ||
|
|
||
| // Link to the headers file so we can run gyp_llnode directly and don't need to | ||
| // setup parameters to pass it. | ||
| console.log(`Linking lldb to include directory ${lldbIncludeDir}`); | ||
| fs.symlinkSync(lldbIncludeDir, 'lldb'); | ||
|
|
||
| // Initialize GYP | ||
| // We can use the node-gyp that comes with npm. | ||
| // We can locate it with npm -g explore npm npm explore node-gyp pwd | ||
| // It might have been neater to make node-gyp one of our dependencies | ||
| // *but* they don't get installed until after the install step has run. | ||
| var gypDir = child_process.execFileSync('npm', | ||
| ['-g', 'explore', 'npm', 'npm', 'explore', 'node-gyp', 'pwd'], | ||
| {cwd: buildDir}).toString().trim(); | ||
| fs.mkdirSync('tools'); | ||
| console.log(`Linking tools/gyp to ${gypDir}/gyp`); | ||
| fs.symlinkSync(`${gypDir}/gyp`, 'tools/gyp'); | ||
|
|
||
| // Exit with success. | ||
| process.exit(0); | ||
|
|
||
| // On Mac the lldb version string doesn't match the original lldb versions. | ||
| function getDarwinRelease() { | ||
| var xcodeStr; | ||
| try { | ||
| xcodeStr = child_process.execFileSync('xcodebuild', ['-version']) | ||
| .toString(); | ||
| } catch (err) { | ||
| return undefined; | ||
| } | ||
| var versionStr = ''; | ||
| var splitStr = xcodeStr.split(os.EOL); | ||
| for (var str of splitStr) { | ||
| if (str.indexOf('Xcode') != -1) { | ||
| versionStr = str.split(' ')[1]; | ||
| break; | ||
| } | ||
| } | ||
| // console.log('Xcode version is ' + version_str) | ||
|
|
||
| var version = parseFloat(versionStr); | ||
| if (version > 8.0) { | ||
| return '3.8'; | ||
| } else { | ||
| return '3.4'; | ||
| } | ||
| } | ||
|
|
||
| // Find the 'best' lldb to use. Either: | ||
| // - the one specified by the user using npm --llnode_exe=... install llnode | ||
| // - the default lldb executable | ||
| // - the higest known lldb version | ||
| function getLldbExecutable() { | ||
| var lldbExe = process.env.npm_config_lldb_exe; | ||
| if (lldbExe === undefined) { | ||
| var lldbExeNames = ['lldb', 'lldb-4.0', 'lldb-3.9', | ||
| 'lldb-3.8', 'lldb-3.7', 'lldb-3.6']; | ||
| for (var lldbExeVersion of lldbExeNames) { | ||
| try { | ||
| lldbExe = child_process.execSync('which ' + | ||
| lldbExeVersion).toString().trim(); | ||
| // If the result starts with '/' `which` found a path. | ||
| if (lldbExe.startsWith('/')) { | ||
| break; | ||
| } | ||
| } catch (err) { | ||
| // Do nothing - we expect not to find some of these. | ||
| } | ||
| } | ||
| } | ||
| return lldbExe; | ||
| } | ||
|
|
||
| // There are multiple versions of lldb available for the various linux distos. | ||
| // Use the default unless --llnode_exe= has been set on the command line. | ||
| function getLinuxVersion(lldbExe) { | ||
|
|
||
| var lldbStr; | ||
| try { | ||
| lldbStr = child_process.execFileSync(lldbExe, ['-v']).toString(); | ||
| } catch (err) { | ||
| return undefined; | ||
| } | ||
| // Ignore minor revisions like 3.8.1 | ||
| if (lldbStr.indexOf('version 4.0') > 0) { | ||
| return '4.0'; | ||
| } else if (lldbStr.indexOf('version 3.9') > 0) { | ||
| return '3.9'; | ||
| } else if (lldbStr.indexOf('version 3.8') > 0) { | ||
| return '3.8'; | ||
| } else if (lldbStr.indexOf('version 3.7') > 0) { | ||
| return '3.7'; | ||
| } if (lldbStr.indexOf('version 3.6') > 0) { | ||
| return '3.6'; | ||
| } if (lldbStr.indexOf('version 3.5') > 0) { | ||
| return '3.5'; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| function getLinuxHeadersDir(version) { | ||
| // Get the directory which should contain the headers and | ||
| // check if they are present. | ||
| // (Using the installed headers will ensure we have the correct ones.) | ||
| console.log('Checking for headers, version is ' + version); | ||
| try { | ||
| var includeDir = child_process.execFileSync('llvm-config-' + version, | ||
| ['--prefix']).toString().trim(); | ||
| // console.log('Checking for directory ' + include_dir); | ||
| // Include directory doesn't need include/lldb on the end but the llvm | ||
| // headers can be installed without the lldb headers so check for them. | ||
| if (fs.existsSync(includeDir + '/include/lldb')) { | ||
| // console.log('Found ' + include_dir); | ||
| return includeDir; | ||
| } | ||
| } catch (err) { | ||
| // Return undefined, we will download the headers. | ||
| } | ||
| // On Redhat the headers are just installed in /usr/include | ||
| if (fs.existsSync('/usr/include/lldb')) { | ||
| return '/usr'; | ||
| } | ||
| return undefined; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.