Skip to content
This repository
Browse code

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.
  • Loading branch information...
commit 11d8823791644a307a7c521b08d1e213e7836885 1 parent 95fd517
Nathan Rajlich TooTallNate authored
27 doc/api/process.markdown
Source Rendered
@@ -256,6 +256,33 @@ Will output:
256 256 ev: '4.4',
257 257 openssl: '1.0.0e-fips' }
258 258
  259 +## process.config
  260 +
  261 +An Object containing the JavaScript representation of the configure options
  262 +that were used to compile the current node executable. This is the same as
  263 +the "config.gypi" file that was produced when running the `./configure` script.
  264 +
  265 +An example of the possible output looks like:
  266 +
  267 + { target_defaults:
  268 + { cflags: [],
  269 + default_configuration: 'Release',
  270 + defines: [],
  271 + include_dirs: [],
  272 + libraries: [] },
  273 + variables:
  274 + { host_arch: 'x64',
  275 + node_install_npm: 'true',
  276 + node_install_waf: 'true',
  277 + node_prefix: '',
  278 + node_shared_v8: 'false',
  279 + node_shared_zlib: 'false',
  280 + node_use_dtrace: 'false',
  281 + node_use_openssl: 'true',
  282 + node_use_system_openssl: 'false',
  283 + strict_aliasing: 'true',
  284 + target_arch: 'x64',
  285 + v8_use_snapshot: 'true' } }
259 286
260 287 ## process.installPrefix
261 288
16 src/node.js
@@ -37,6 +37,7 @@
37 37 startup.globalConsole();
38 38
39 39 startup.processAssert();
  40 + startup.processConfig();
40 41 startup.processNextTick();
41 42 startup.processStdio();
42 43 startup.processKillAndExit();
@@ -177,6 +178,21 @@
177 178 };
178 179 };
179 180
  181 + startup.processConfig = function() {
  182 + // used for `process.config`, but not a real module
  183 + var config = NativeModule._source.config;
  184 + delete NativeModule._source.config;
  185 +
  186 + // strip the gyp comment line at the beginning
  187 + config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
  188 +
  189 + process.config = JSON.parse(config, function(key, value) {
  190 + if (value === 'true') return true;
  191 + if (value === 'false') return false;
  192 + return value;
  193 + });
  194 + }
  195 +
180 196 startup.processNextTick = function() {
181 197 var nextTickQueue = [];
182 198
44 test/simple/test-process-config.js
... ... @@ -0,0 +1,44 @@
  1 +// Copyright Joyent, Inc. and other Node contributors.
  2 +//
  3 +// Permission is hereby granted, free of charge, to any person obtaining a
  4 +// copy of this software and associated documentation files (the
  5 +// "Software"), to deal in the Software without restriction, including
  6 +// without limitation the rights to use, copy, modify, merge, publish,
  7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
  8 +// persons to whom the Software is furnished to do so, subject to the
  9 +// following conditions:
  10 +//
  11 +// The above copyright notice and this permission notice shall be included
  12 +// in all copies or substantial portions of the Software.
  13 +//
  14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
  21 +
  22 +var common = require('../common');
  23 +var assert = require('assert');
  24 +var fs = require('fs');
  25 +var path = require('path');
  26 +
  27 +// check for existence
  28 +assert(process.hasOwnProperty('config'));
  29 +
  30 +// ensure that `process.config` is an Object
  31 +assert(Object(process.config) === process.config);
  32 +
  33 +var configPath = path.resolve(__dirname, '..', '..', 'config.gypi');
  34 +var config = fs.readFileSync(configPath, 'utf8');
  35 +
  36 +// clean up comment at the first line
  37 +config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
  38 +config = JSON.parse(config, function(key, value) {
  39 + if (value === 'true') return true;
  40 + if (value === 'false') return false;
  41 + return value;
  42 +});
  43 +
  44 +assert.deepEqual(config, process.config);

0 comments on commit 11d8823

Please sign in to comment.
Something went wrong with that request. Please try again.