process: add `process.config`

This is the JS representation of the `config.gypi` file that was used when
compiling node. With this information, you can tell whether the current node
binary has shared or static dependencies, or any other configuration options
that may have been used.
pull/24503/head
Nathan Rajlich 2012-03-15 17:15:18 -07:00
parent 95fd517431
commit 11d8823791
3 changed files with 87 additions and 0 deletions

View File

@ -256,6 +256,33 @@ Will output:
ev: '4.4',
openssl: '1.0.0e-fips' }
## process.config
An Object containing the JavaScript representation of the configure options
that were used to compile the current node executable. This is the same as
the "config.gypi" file that was produced when running the `./configure` script.
An example of the possible output looks like:
{ target_defaults:
{ cflags: [],
default_configuration: 'Release',
defines: [],
include_dirs: [],
libraries: [] },
variables:
{ host_arch: 'x64',
node_install_npm: 'true',
node_install_waf: 'true',
node_prefix: '',
node_shared_v8: 'false',
node_shared_zlib: 'false',
node_use_dtrace: 'false',
node_use_openssl: 'true',
node_use_system_openssl: 'false',
strict_aliasing: 'true',
target_arch: 'x64',
v8_use_snapshot: 'true' } }
## process.installPrefix

View File

@ -37,6 +37,7 @@
startup.globalConsole();
startup.processAssert();
startup.processConfig();
startup.processNextTick();
startup.processStdio();
startup.processKillAndExit();
@ -177,6 +178,21 @@
};
};
startup.processConfig = function() {
// used for `process.config`, but not a real module
var config = NativeModule._source.config;
delete NativeModule._source.config;
// strip the gyp comment line at the beginning
config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
process.config = JSON.parse(config, function(key, value) {
if (value === 'true') return true;
if (value === 'false') return false;
return value;
});
}
startup.processNextTick = function() {
var nextTickQueue = [];

View File

@ -0,0 +1,44 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
// check for existence
assert(process.hasOwnProperty('config'));
// ensure that `process.config` is an Object
assert(Object(process.config) === process.config);
var configPath = path.resolve(__dirname, '..', '..', 'config.gypi');
var config = fs.readFileSync(configPath, 'utf8');
// clean up comment at the first line
config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
config = JSON.parse(config, function(key, value) {
if (value === 'true') return true;
if (value === 'false') return false;
return value;
});
assert.deepEqual(config, process.config);