Skip to content
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

Allow for single-level module_path when packing #371

Merged
merged 4 commits into from
Apr 27, 2018
Merged
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
7 changes: 5 additions & 2 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ function _package(gyp, argv, callback) {
return true;
};
mkdirp(path.dirname(tarball),function(err) {
from = path.dirname(from);
if (err) return callback(err);
packlist({ path: from }).then(function(files) {
var base = path.basename(from);
files = files.map(function(file) {
return path.join(base, file);
});
tar.create({
portable: true,
gzip: true,
onentry: filter_func,
file: tarball,
cwd: from
cwd: path.dirname(from)
}, files, function(err) {
if (err) console.error('['+package_json.name+'] ' + err.message);
else log.info('package','Binary staged at "' + tarball + '"');
Expand Down
5 changes: 5 additions & 0 deletions test/app8/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
build/
lib/
node_modules
npm-debug.log
3 changes: 3 additions & 0 deletions test/app8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test app

Demonstrates a simpler configuration that uses node-pre-gyp.
38 changes: 38 additions & 0 deletions test/app8/app8.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// v8
#include <v8.h>

// node.js
#include <node.h>
#include <node_version.h>

#if (NODE_MODULE_VERSION > 0x000B)

static void get_hello(const v8::FunctionCallbackInfo<v8::Value>& args)
{
v8::HandleScope scope(v8::Isolate::GetCurrent());
args.GetReturnValue().Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(),"hello"));
}

#else

static v8::Handle<v8::Value> get_hello(const v8::Arguments& args)
{
v8::HandleScope scope;
return scope.Close(v8::String::New("hello"));
}

#endif

extern "C" {
static void start(v8::Handle<v8::Object> target) {
#if (NODE_MODULE_VERSION > 0x000B)
v8::HandleScope scope(v8::Isolate::GetCurrent());
#else
v8::HandleScope scope;
#endif
NODE_SET_METHOD(target, "hello", get_hello);
}
}

NODE_MODULE(app8, start)

13 changes: 13 additions & 0 deletions test/app8/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"targets": [
{
"target_name": "<(module_name)",
"sources": [ "<(module_name).cc" ],
"product_dir": "<(module_path)",
"xcode_settings": {
"MACOSX_DEPLOYMENT_TARGET":"10.9",
"CLANG_CXX_LIBRARY": "libc++"
}
}
]
}
6 changes: 6 additions & 0 deletions test/app8/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var binary = require('node-pre-gyp');
var path = require('path')
var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json')));
var binding = require(binding_path);

require('assert').equal(binding.hello(),"hello");
21 changes: 21 additions & 0 deletions test/app8/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "node-pre-gyp-test-app8",
"author": "Dane Springmeyer <springmeyer>",
"description": "node-pre-gyp test",
"repository": {
"type": "git",
"url": "git://github.com/mapbox/node-pre-gyp.git"
},
"license": "BSD-3-Clause",
"version": "0.1.0",
"main": "./index.js",
"binary": {
"module_name": "app8",
"module_path": "./lib",
"host": "https://node-pre-gyp-tests.s3-us-west-1.amazonaws.com"
},
"scripts": {
"install": "node-pre-gyp install --fallback-to-build",
"test": "node index.js"
}
}
148 changes: 141 additions & 7 deletions test/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,131 @@ var rm = require('rimraf');
var path = require('path');
var getPrevious = require('./target_version.util.js');
var napi = require ('../lib/util/napi.js');
var versioning = require('../lib/util/versioning.js');
var tar = require('tar');

var localVer = [versioning.get_runtime_abi('node'), process.platform, process.arch].join('-');
var SOEXT = {'darwin': 'dylib', 'linux': 'so', 'win32': 'dll'}[process.platform];

// The list of different sample apps that we use to test
var apps = [
{
'name': 'app1',
'args': ''
'args': '',
'files': {
'base': ['binding/app1.node'],
'win32': {
'base': [
'binding/app1.exp',
'binding/app1.lib',
'binding/app1.map',
'binding/app1.node'
],
'node-v59': [
'binding/app1.exp',
'binding/app1.iobj',
'binding/app1.ipdb',
'binding/app1.lib',
'binding/app1.map',
'binding/app1.node'
]
}
}
},
{
'name': 'app2',
'args': '--custom_include_path=../include --debug'
'name': 'app2',
'args': '--custom_include_path=../include --debug',
'files': {
'base': ['node-pre-gyp-test-app2/app2.node'],
'win32': [
'node-pre-gyp-test-app2/app2.exp',
'node-pre-gyp-test-app2/app2.ilk',
'node-pre-gyp-test-app2/app2.lib',
'node-pre-gyp-test-app2/app2.map',
'node-pre-gyp-test-app2/app2.node'
]
}
},
{
'name': 'app2',
'args': '--custom_include_path=../include --toolset=cpp11'
'args': '--custom_include_path=../include --toolset=cpp11',
'files': {
'base': ['node-pre-gyp-test-app2/app2.node'],
'win32': {
'base': [
'node-pre-gyp-test-app2/app2.exp',
'node-pre-gyp-test-app2/app2.lib',
'node-pre-gyp-test-app2/app2.map',
'node-pre-gyp-test-app2/app2.node'
],
'node-v59': [
'node-pre-gyp-test-app2/app2.exp',
'node-pre-gyp-test-app2/app2.iobj',
'node-pre-gyp-test-app2/app2.ipdb',
'node-pre-gyp-test-app2/app2.lib',
'node-pre-gyp-test-app2/app2.map',
'node-pre-gyp-test-app2/app2.node'
]
}
}
},
{
'name': 'app3',
'args': ''
'args': '',
'files': {
'base': [[localVer, 'app3.node'].join('/')],
'win32': {
'base': [
[localVer, 'app3.exp'].join('/'),
[localVer, 'app3.lib'].join('/'),
[localVer, 'app3.map'].join('/'),
[localVer, 'app3.node'].join('/')
],
'node-v59': [
[localVer, 'app3.exp'].join('/'),
[localVer, 'app3.iobj'].join('/'),
[localVer, 'app3.ipdb'].join('/'),
[localVer, 'app3.lib'].join('/'),
[localVer, 'app3.map'].join('/'),
[localVer, 'app3.node'].join('/'),
]
}
}
},
{
'name': 'app4',
'args': ''
'args': '',
'files': {
'base': [[localVer, 'app4.node'].join('/'), [localVer, 'lib.target', 'mylib.' + SOEXT].join('/')],
'win32': [[localVer, 'app4.node'].join('/'), [localVer, 'mylib.' + SOEXT].join('/')]
}
},
{
'name': 'app7',
'args': ''
},
{
'name': 'app8',
'args': '',
'files': {
'base': ['lib/app8.node'],
'win32': {
'base': [
'lib/app8.exp',
'lib/app8.lib',
'lib/app8.map',
'lib/app8.node'
],
'node-v59': [
'lib/app8.exp',
'lib/app8.iobj',
'lib/app8.ipdb',
'lib/app8.lib',
'lib/app8.map',
'lib/app8.node'
]
}
}
}
];

Expand Down Expand Up @@ -211,7 +310,42 @@ apps.forEach(function(app) {
test(app.name + ' packages ' + app.args, function(t) {
run('node-pre-gyp', 'package', '', app, {}, function(err,stdout,stderr) {
t.ifError(err);
t.end();
// Make sure a tarball was created
run('node-pre-gyp', 'reveal', 'staged_tarball --silent', app, {}, function(err,stdout,stderr) {
t.ifError(err);
var staged_tarball = stdout.trim();
if (staged_tarball.indexOf('\n') !== -1) { // take just the first line
staged_tarball = staged_tarball.substr(0,staged_tarball.indexOf('\n'));
}
var tarball_path = path.join(__dirname, app.name, staged_tarball);
t.ok(existsSync(tarball_path),'staged tarball is a valid file');
if (!app.files) {
return t.end();
}
// Make sure the package contains what we expect
var entries = [];
tar.t({
file: tarball_path,
sync: true,
onentry: function (entry) {
entries.push(entry.path);
}
});
var files = app.files.base;
var nodever = versioning.get_runtime_abi('node');
// Look for a more specific choice
if (app.files.hasOwnProperty(process.platform)) {
if (app.files[process.platform].hasOwnProperty(nodever)) {
files = app.files[process.platform][nodever];
} else if (app.files[process.platform].hasOwnProperty('base')) {
files = app.files[process.platform].base;
} else {
files = app.files[process.platform];
}
}
t.same(entries.sort(), files.sort(), 'staged tarball contains the right files');
t.end();
});
});
});

Expand Down