Use official `llvm-project` monorepo, expand LLDB versions check by trxcllnt · Pull Request #389 · nodejs/llnode · GitHub
Skip to content
Merged
58 changes: 47 additions & 11 deletions .github/workflows/push.yml
13 changes: 9 additions & 4 deletions scripts/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ function getLldbExecutable() {
return process.env.npm_config_lldb_exe;
}

const lldbExeNames = [
'lldb', 'lldb-5.0', 'lldb-4.0',
'lldb-3.9', 'lldb-3.8', 'lldb-3.7', 'lldb-3.6'
];
// Use `Array.prototype.concat.apply` to support
// runtimes without `Array.prototype.flatMap`.
// Look for LLDB up to version 20.
const versions = Array.prototype.concat.apply([],
Array.from({length: 20}, (_, i) => i + 1).map((major) =>
Array.from({ length: major < 4 ? 10 : 1 }, (_, minor) => major + '.' + minor)
));

const lldbExeNames = ['lldb'].concat(versions.reverse().map((v) => 'lldb-' + v));

return lldb.tryExecutables(lldbExeNames);
}
Expand Down
34 changes: 31 additions & 3 deletions scripts/lldb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ const fs = require('fs');
* @returns {string} Branch of the corresponding lldb release
*/
function versionToBranch(version) {
return 'release_' + version.replace('.', '');
// `llvm-project` v1-3 branches are in the form `release/major.minor.x`:
// release/1.0.x ... release/3.9.x
// `llvm-project` v4-latest branches are in the form `release/major.x`:
// release/4.x ... release/12.x

// split into array of semver components
var chars = (version.indexOf('.') === -1
? version.split('') // split `39` into ['3', '9']
: version.split('.').filter(x => x !== '.') // split `3.9` into ['3', '9']
);

// if version < 4, keep `major.minor` components
// if version >= 4, only keep `major` component
chars = chars.slice(0, (+chars[0] >= 4) ? 1 : 2);

// join components into the form `release/3.9.x`
return 'release/' + chars.concat('x').join('.');
}

/**
Expand Down Expand Up @@ -44,18 +60,30 @@ function cloneHeaders(lldbVersion, buildDir) {

if (!fs.existsSync(lldbInstallDir)) {
console.log(`\nCloning lldb ${lldbHeadersBranch} into ${lldbInstallDir}`);
// use `git clone --filter` in git v2.19 to only download `lldb` dir of `llvm-project` monorepo
// see: https://stackoverflow.com/a/52269934/3117331
// see: https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
child_process.execFileSync(
'git', ['clone',
'--depth', '1',
'--filter=blob:none',
'--sparse',
'--branch', lldbHeadersBranch,
'https://github.com/llvm-mirror/lldb.git',
'https://github.com/llvm/llvm-project.git',
lldbInstallDir
],
{ stdio: 'inherit' }); // show progress
child_process.execFileSync(
'git', [
'-C', lldbInstallDir,
'sparse-checkout',
'set', 'lldb'
],
{ stdio: 'inherit' }); // show progress
} else {
console.log(`\nSkip cloning lldb headers because ${lldbInstallDir} exists`);
}
return path.join(lldbInstallDir, 'include');
return path.join(lldbInstallDir, 'lldb', 'include');
}

/**
Expand Down
28 changes: 18 additions & 10 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function SessionOutput(session, stream, timeout) {
this.waiting = false;
this.waitQueue = [];
let buf = '';
this.timeout = timeout || 10000;
this.timeout = timeout || 20000;
this.session = session;

this.flush = function flush() {
Expand All @@ -52,12 +52,23 @@ function SessionOutput(session, stream, timeout) {
if (!this.waiting)
break

let index = buf.indexOf('\n');
let line = '';
let index = 0;

if (index === -1)
break;
let inv = buf.indexOf('invalid_expr');
if (inv !== -1) {
line = buf;
index = buf.length;
} else {

index = buf.indexOf('\n');

if (index === -1)
break;

line = buf.slice(0, index);
}

const line = buf.slice(0, index);
buf = buf.slice(index + 1);

if (/process \d+ exited/i.test(line))
Expand Down Expand Up @@ -107,6 +118,7 @@ SessionOutput.prototype.wait = function wait(regexp, callback, allLines) {
const lines = [];

function onLine(line) {

lines.push(line);
if (self.session)
debug(`[LINE][${self.session.lldb.pid}]`, line);
Expand Down Expand Up @@ -158,7 +170,7 @@ SessionOutput.prototype.linesUntil = function linesUntil(regexp, callback) {

function Session(options) {
EventEmitter.call(this);
const timeout = parseInt(process.env.TEST_TIMEOUT) || 10000;
const timeout = parseInt(process.env.TEST_TIMEOUT) || 20000;
const lldbBin = process.env.TEST_LLDB_BINARY || 'lldb';
const env = Object.assign({}, process.env);

Expand Down Expand Up @@ -196,10 +208,6 @@ function Session(options) {
this.stdout = new SessionOutput(this, this.lldb.stdout, timeout);
this.stderr = new SessionOutput(this, this.lldb.stderr, timeout);

this.stderr.on('line', (line) => {
debug('[stderr]', line);
});

// Map these methods to stdout for compatibility with legacy tests.
this.wait = SessionOutput.prototype.wait.bind(this.stdout);
this.waitError = SessionOutput.prototype.wait.bind(this.stderr);
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/inspect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,11 @@ function verifyInvalidExpr(t, sess) {
return teardown(t, sess, err);
}
t.ok(
/error: error: use of undeclared identifier 'invalid_expr'/.test(line),
/use of undeclared identifier 'invalid_expr'/.test(line),
'invalid expression should return an error'
);
teardown(t, sess);
});
}, false);
}

tape('v8 inspect', (t) => {
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/scan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function testFindrefsForInvalidExpr(t, sess, next) {
sess.waitError(/error:/, (err, line) => {
t.error(err);
t.ok(
/error: error: use of undeclared identifier 'invalid_expr'/.test(line),
/use of undeclared identifier 'invalid_expr'/.test(line),
'invalid expression should return an error'
);
next();
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/workqueue-test.js