Build static executable.
- Fix a few errors with node.dlopen() - Report errors to stderr (this should probably be a separate commit, but whatever)
This commit is contained in:
parent
b73264d9b3
commit
a97dce7523
37
src/node.cc
37
src/node.cc
@ -33,38 +33,38 @@ ToCString(const v8::String::Utf8Value& value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ReportException(v8::TryCatch* try_catch)
|
ReportException(TryCatch* try_catch)
|
||||||
{
|
{
|
||||||
v8::HandleScope handle_scope;
|
HandleScope handle_scope;
|
||||||
v8::String::Utf8Value exception(try_catch->Exception());
|
String::Utf8Value exception(try_catch->Exception());
|
||||||
const char* exception_string = ToCString(exception);
|
const char* exception_string = ToCString(exception);
|
||||||
v8::Handle<v8::Message> message = try_catch->Message();
|
Handle<Message> message = try_catch->Message();
|
||||||
if (message.IsEmpty()) {
|
if (message.IsEmpty()) {
|
||||||
// V8 didn't provide any extra information about this error; just
|
// V8 didn't provide any extra information about this error; just
|
||||||
// print the exception.
|
// print the exception.
|
||||||
printf("%s\n", exception_string);
|
fprintf(stderr, "%s\n", exception_string);
|
||||||
} else {
|
} else {
|
||||||
message->PrintCurrentStackTrace(stdout);
|
|
||||||
|
|
||||||
// Print (filename):(line number): (message).
|
// Print (filename):(line number): (message).
|
||||||
v8::String::Utf8Value filename(message->GetScriptResourceName());
|
String::Utf8Value filename(message->GetScriptResourceName());
|
||||||
const char* filename_string = ToCString(filename);
|
const char* filename_string = ToCString(filename);
|
||||||
int linenum = message->GetLineNumber();
|
int linenum = message->GetLineNumber();
|
||||||
printf("%s:%i: %s\n", filename_string, linenum, exception_string);
|
fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string);
|
||||||
// Print line of source code.
|
// Print line of source code.
|
||||||
v8::String::Utf8Value sourceline(message->GetSourceLine());
|
String::Utf8Value sourceline(message->GetSourceLine());
|
||||||
const char* sourceline_string = ToCString(sourceline);
|
const char* sourceline_string = ToCString(sourceline);
|
||||||
printf("%s\n", sourceline_string);
|
fprintf(stderr, "%s\n", sourceline_string);
|
||||||
// Print wavy underline (GetUnderline is deprecated).
|
// Print wavy underline (GetUnderline is deprecated).
|
||||||
int start = message->GetStartColumn();
|
int start = message->GetStartColumn();
|
||||||
for (int i = 0; i < start; i++) {
|
for (int i = 0; i < start; i++) {
|
||||||
printf(" ");
|
fprintf(stderr, " ");
|
||||||
}
|
}
|
||||||
int end = message->GetEndColumn();
|
int end = message->GetEndColumn();
|
||||||
for (int i = start; i < end; i++) {
|
for (int i = start; i < end; i++) {
|
||||||
printf("^");
|
fprintf(stderr, "^");
|
||||||
}
|
}
|
||||||
printf("\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
|
message->PrintCurrentStackTrace(stderr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,17 +106,16 @@ typedef void (*extInit)(Handle<Object> exports);
|
|||||||
Handle<Value>
|
Handle<Value>
|
||||||
node_dlopen (const v8::Arguments& args)
|
node_dlopen (const v8::Arguments& args)
|
||||||
{
|
{
|
||||||
if (args.Length() < 2) return Undefined();
|
|
||||||
|
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
|
||||||
|
if (args.Length() < 2) return Undefined();
|
||||||
|
|
||||||
String::Utf8Value filename(args[0]->ToString());
|
String::Utf8Value filename(args[0]->ToString());
|
||||||
Local<Object> target = args[1]->ToObject();
|
Local<Object> target = args[1]->ToObject();
|
||||||
|
|
||||||
void *handle = dlopen(*filename, RTLD_LAZY);
|
void *handle = dlopen(*filename, RTLD_LAZY);
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
ThrowException(String::New("dlopen() failed."));
|
return ThrowException(String::New("dlopen() failed."));
|
||||||
return Undefined();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *init_handle = dlsym(handle, "init");
|
void *init_handle = dlsym(handle, "init");
|
||||||
@ -294,6 +293,8 @@ PrintHelp ( )
|
|||||||
{
|
{
|
||||||
printf("Usage: node [switches] script.js [arguments] \n"
|
printf("Usage: node [switches] script.js [arguments] \n"
|
||||||
" -v, --version print node's version\n"
|
" -v, --version print node's version\n"
|
||||||
|
" --libs print linker flags for modules\n"
|
||||||
|
" --cflags print pre-processor and compiler flags\n"
|
||||||
" --v8-options print v8 command line options\n");
|
" --v8-options print v8 command line options\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
src/node.js
28
src/node.js
@ -90,6 +90,32 @@ node.Module = function (o) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
node.Module.prototype.load = function (callback) {
|
node.Module.prototype.load = function (callback) {
|
||||||
|
if (this.filename.match(/\.node$/)) {
|
||||||
|
return this.loadObject(callback);
|
||||||
|
} else {
|
||||||
|
return this.loadScript(callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
node.Module.prototype.loadObject = function (callback) {
|
||||||
|
var self = this;
|
||||||
|
var loadPromise = new node.Promise();
|
||||||
|
self.loadPromise = loadPromise;
|
||||||
|
// XXX Not yet supporting loading from HTTP. would need to download the
|
||||||
|
// file, store it to tmp then run dlopen on it.
|
||||||
|
node.fs.exists(self.filename, function (does_exist) {
|
||||||
|
if (does_exist) {
|
||||||
|
node.dlopen(self.filename, self.target); // FIXME synchronus
|
||||||
|
loadPromise.emitSuccess([self.target]);
|
||||||
|
} else {
|
||||||
|
node.stdio.writeError("Error reading " + self.filename + "\n");
|
||||||
|
loadPromise.emitError();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return loadPromise;
|
||||||
|
};
|
||||||
|
|
||||||
|
node.Module.prototype.loadScript = function (callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (self.loaded) {
|
if (self.loaded) {
|
||||||
throw "Module '" + self.filename + "' is already loaded.";
|
throw "Module '" + self.filename + "' is already loaded.";
|
||||||
@ -165,7 +191,7 @@ node.Module.prototype.waitChildrenLoad = function (callback) {
|
|||||||
if (child.loaded) {
|
if (child.loaded) {
|
||||||
nloaded++;
|
nloaded++;
|
||||||
} else {
|
} else {
|
||||||
child.addCallback(function () {
|
child.loadPromise.addCallback(function () {
|
||||||
nloaded++;
|
nloaded++;
|
||||||
if (children.length == nloaded && callback) callback();
|
if (children.length == nloaded && callback) callback();
|
||||||
});
|
});
|
||||||
|
@ -2,8 +2,8 @@ prefix=@PREFIX@
|
|||||||
libdir=${prefix}/lib
|
libdir=${prefix}/lib
|
||||||
includedir=${prefix}/include/node
|
includedir=${prefix}/include/node
|
||||||
|
|
||||||
Name: node@DEBUG_EXT@
|
Name: node
|
||||||
Description: v8 powered non-browser javascript
|
Description: v8 powered non-browser javascript
|
||||||
Version: @VERSION@
|
Version: @VERSION@
|
||||||
Libs: @LIBFLAGS@ -L${libdir} -lnode@DEBUG_EXT@
|
Libs: @LIBFLAGS@ -R${libdir}
|
||||||
Cflags: @CCFLAGS@ @CPPFLAGS@ -I${includedir}
|
Cflags: @CCFLAGS@ @CPPFLAGS@ -I${includedir}
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
#ifndef node_version_h
|
||||||
|
#define node_version_h
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
# define NODE_VERSION "@VERSION@"
|
# define NODE_VERSION "@VERSION@"
|
||||||
#define NODE_CFLAGS "@CCFLAGS@ @CPPFLAGS@ -I@PREFIX@/include"
|
#else
|
||||||
#define NODE_LIBFLAGS "@LIBFLAGS@ -L@PREFIX@/lib -lnode@DEBUG_EXT@"
|
# define NODE_VERSION "@VERSION@ (debug)"
|
||||||
|
#endif
|
||||||
|
#define NODE_CFLAGS "@CCFLAGS@ @CPPFLAGS@ -I@PREFIX@/include/node"
|
||||||
|
#define NODE_LIBFLAGS "@LIBFLAGS@ -R@PREFIX@/lib"
|
||||||
|
|
||||||
|
#endif /* node_version_h */
|
||||||
|
34
wscript
34
wscript
@ -61,6 +61,8 @@ def configure(conf):
|
|||||||
conf.env["USE_DEBUG"] = Options.options.debug
|
conf.env["USE_DEBUG"] = Options.options.debug
|
||||||
|
|
||||||
conf.check(lib='dl', uselib_store='DL')
|
conf.check(lib='dl', uselib_store='DL')
|
||||||
|
conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
|
||||||
|
|
||||||
if Options.options.debug:
|
if Options.options.debug:
|
||||||
conf.check(lib='profiler', uselib_store='PROFILER')
|
conf.check(lib='profiler', uselib_store='PROFILER')
|
||||||
|
|
||||||
@ -260,31 +262,34 @@ def build(bld):
|
|||||||
libnode.uselib_local = "evcom ev eio http_parser coupling"
|
libnode.uselib_local = "evcom ev eio http_parser coupling"
|
||||||
libnode.uselib = "UDNS V8 EXECINFO PROFILER EFENCE DL"
|
libnode.uselib = "UDNS V8 EXECINFO PROFILER EFENCE DL"
|
||||||
libnode.install_path = '${PREFIX}/lib'
|
libnode.install_path = '${PREFIX}/lib'
|
||||||
bld.install_files('${PREFIX}/include/node/', 'config.h src/node.h src/node_version.h src/object_wrap.h');
|
|
||||||
|
|
||||||
|
libnode_static = bld.new_task_gen("cxx", "staticlib")
|
||||||
|
libnode_static.name = "node-static"
|
||||||
|
libnode_static.target = libnode.target
|
||||||
|
libnode_static.source = libnode.source
|
||||||
|
libnode_static.includes = libnode.includes
|
||||||
|
libnode_static.uselib_local = libnode.uselib_local
|
||||||
|
libnode_static.uselib = libnode.uselib
|
||||||
|
|
||||||
### node
|
### node
|
||||||
node = bld.new_task_gen("cxx", "program")
|
node = bld.new_task_gen("cxx", "program")
|
||||||
node.target = 'node'
|
node.target = 'node'
|
||||||
node.source = "src/main.cc"
|
node.source = "src/main.cc"
|
||||||
node.includes = libnode.includes
|
node.includes = libnode.includes
|
||||||
node.uselib_local = "node"
|
node.uselib_local = "node-static"
|
||||||
node.install_path = '${PREFIX}/bin'
|
node.install_path = '${PREFIX}/bin'
|
||||||
node.chmod = 0755
|
node.chmod = 0755
|
||||||
|
|
||||||
|
|
||||||
def subflags(program):
|
def subflags(program):
|
||||||
debug_ext = ""
|
|
||||||
if program.target == "node_g": debug_ext = "_g"
|
|
||||||
x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
|
x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
|
||||||
, 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
|
, 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
|
||||||
, 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
|
, 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
|
||||||
, 'VERSION' : VERSION
|
, 'VERSION' : VERSION
|
||||||
, 'PREFIX' : program.env["PREFIX"]
|
, 'PREFIX' : program.env["PREFIX"]
|
||||||
, 'DEBUG_EXT' : debug_ext
|
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
|
|
||||||
|
|
||||||
# process file.pc.in -> file.pc
|
# process file.pc.in -> file.pc
|
||||||
pkgconfig = bld.new_task_gen('subst', before="cxx")
|
pkgconfig = bld.new_task_gen('subst', before="cxx")
|
||||||
pkgconfig.source = 'src/node.pc.in'
|
pkgconfig.source = 'src/node.pc.in'
|
||||||
@ -297,6 +302,7 @@ def build(bld):
|
|||||||
node_version.source = 'src/node_version.h.in'
|
node_version.source = 'src/node_version.h.in'
|
||||||
node_version.target = 'src/node_version.h'
|
node_version.target = 'src/node_version.h'
|
||||||
node_version.dict = subflags(node)
|
node_version.dict = subflags(node)
|
||||||
|
node_version.install_path = '${PREFIX}/include/node'
|
||||||
|
|
||||||
if bld.env["USE_DEBUG"]:
|
if bld.env["USE_DEBUG"]:
|
||||||
node_g = node.clone("debug")
|
node_g = node.clone("debug")
|
||||||
@ -305,10 +311,18 @@ def build(bld):
|
|||||||
libnode_g = libnode.clone("debug")
|
libnode_g = libnode.clone("debug")
|
||||||
libnode_g.target = "node_g"
|
libnode_g.target = "node_g"
|
||||||
|
|
||||||
pkgconfig_g = pkgconfig.clone("debug")
|
libnode_static_g = libnode_static.clone("debug")
|
||||||
pkgconfig_g.dict = subflags(node_g)
|
libnode_static_g.target = "node_g"
|
||||||
pkgconfig_g.target = 'node_g.pc'
|
|
||||||
|
|
||||||
node_version_g = node_version.clone("debug")
|
node_version_g = node_version.clone("debug")
|
||||||
node_version_g.dict = subflags(node_g)
|
node_version_g.dict = subflags(node_g)
|
||||||
|
node_version_g.install_path = None
|
||||||
|
|
||||||
|
|
||||||
|
bld.install_files('${PREFIX}/include/node/', """
|
||||||
|
config.h
|
||||||
|
src/node.h
|
||||||
|
src/object_wrap.h
|
||||||
|
src/events.h
|
||||||
|
src/net.h
|
||||||
|
""");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user