Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function configure(gyp, argv, callback) {
known_gyp_args.forEach(function(key) {
var val = gyp.opts[key] || gyp.opts[key.replace('-','_')];
if (val) {
final_args.push('--'+key+'='+val);
if (key === 'python') {
// node-gyp 5+ will use this if set
process.env.NODE_GYP_FORCE_PYTHON = val;
}
final_args.push('--'+key+'='+val);
}
});
// --ensure=false tell node-gyp to re-install node development headers
Expand Down
15 changes: 13 additions & 2 deletions test/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ test.Test.prototype.stringContains = function(actual, contents, message) {
});
};

test.Test.prototype.stringMatches = function(actual, regex, message) {
this._assert(regex.test(actual) > -1, {
message: message || 'should match '+regex,
operator: 'stringMatches',
actual: actual,
expected: regex
});
};

// Because the below tests only ensure that flags can be correctly passed to node-gyp is it not
// likely they will behave differently for different apps. So we save time by avoiding running these for each app.
var app = apps[0];
Expand Down Expand Up @@ -206,17 +215,19 @@ test(app.name + ' passes --nodedir down to node-gyp via npm' + app.args, functio
// https://github.com/nodejs/node-gyp/blob/c84a54194781410743efe353d18ca7d20fc9d3a3/lib/configure.js#L396-L397
if (process.platform !== 'win32') {
test(app.name + ' passes --python down to node-gyp via node-pre-gyp ' + app.args, function(t) {
// node-gyp@5 improved the python detection the the below wont be used if it's invalid,
// we can instead set an invalid NODE_GYP_FORCE_PYTHON environment variable to force a failure
run('node-pre-gyp', 'configure', '--python=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err, 'Expected command to fail');
t.stringContains(stderr,"Can't find Python executable");
t.stringMatches(stderr,/(Can't find Python executable|Could not find any Python installation to use)/);
t.end();
});
});

test(app.name + ' passes --python down to node-gyp via npm ' + app.args, function(t) {
run('node-pre-gyp', 'configure', '--build-from-source --python=invalid-value', app, {}, function(err,stdout,stderr) {
t.ok(err, 'Expected command to fail');
t.stringContains(stderr,"Can't find Python executable");
t.stringMatches(stderr,/(Can't find Python executable|Could not find any Python installation to use)/);
t.end();
});
});
Expand Down