diff --git a/doc/api/process.markdown b/doc/api/process.markdown index 831c2c55062..b7ab3b7c4ad 100644 --- a/doc/api/process.markdown +++ b/doc/api/process.markdown @@ -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 diff --git a/src/node.js b/src/node.js index 9dd9fd41950..52467a69b20 100644 --- a/src/node.js +++ b/src/node.js @@ -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 = []; diff --git a/test/simple/test-process-config.js b/test/simple/test-process-config.js new file mode 100644 index 00000000000..b3236cd5ec3 --- /dev/null +++ b/test/simple/test-process-config.js @@ -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);