Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add `process.config` #2928

Closed
wants to merge 6 commits into from

2 participants

@TooTallNate
Owner

This pull adds a process.config object. It looks like:

> process.config
{ 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: false,
     strict_aliasing: true,
     target_arch: 'x64',
     v8_use_snapshot: true } }

Relatively straightforward changes, though I am sort of abusing js2c by stuffing the config.gypi file in there. But hey, it works well! Cheers!

@TooTallNate
Owner

Added bonus: I was able to update the tools/installer.js file to use this new process.config to get the node_prefix, rather than the hacky setup that was there.

@bnoordhuis

I like it. I was going to ask you to initialize process.config lazily but it doesn't seem to make an appreciable difference on benchmark/startup.js. Can you squash it into a couple of logical commits?

TooTallNate added some commits
@TooTallNate TooTallNate js2c: fix to support files other than ones ending with 2 char extensions
Previously this was basically hard-coded for *.js files, but now we
need to include the 'config.gypi' file in there as well.
1d1f175
@TooTallNate TooTallNate node.gyp: include the config.gypi file in the js2c inputs list 585421e
@TooTallNate TooTallNate 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.
293d9a2
@TooTallNate TooTallNate docs: add documentation for `process.config` 581a964
@TooTallNate TooTallNate install: update install.js to use `process.config`
Now that the node_prefix is available from within node, we can use it :)
e1bf2ba
@TooTallNate
Owner

Ok @bnoordhuis, squashed into 5 logical commits.

@TooTallNate
Owner

So this breaks the windows build, I'll have to address that before merging.

@TooTallNate TooTallNate referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@TooTallNate
Owner

Can @igorzi or @piscisaureus check out this? It'll need to be committed before process.config: TooTallNate@joyent:master...windows-configure

@TooTallNate TooTallNate referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@TooTallNate TooTallNate referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@TooTallNate TooTallNate referenced this pull request from a commit in TooTallNate/node
@TooTallNate TooTallNate vcbuild: run the 'configure' script in vcbuild.bat
So that a 'config.gypi' file gets generated, which is
required for the `process.config` object (see #2928).
7469fb4
@TooTallNate TooTallNate referenced this pull request from a commit
@TooTallNate TooTallNate vcbuild: run the 'configure' script in vcbuild.bat
So that a 'config.gypi' file gets generated, which is
required for the `process.config` object (see #2928).
dc75232
@TooTallNate
Owner

Merged in commits leading up to 7cb0f5f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2012
  1. @TooTallNate

    js2c: fix to support files other than ones ending with 2 char extensions

    TooTallNate authored
    Previously this was basically hard-coded for *.js files, but now we
    need to include the 'config.gypi' file in there as well.
  2. @TooTallNate
  3. @TooTallNate

    process: add `process.config`

    TooTallNate authored
    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.
  4. @TooTallNate
  5. @TooTallNate

    install: update install.js to use `process.config`

    TooTallNate authored
    Now that the node_prefix is available from within node, we can use it :)
Commits on Mar 16, 2012
  1. @TooTallNate
This page is out of date. Refresh to see the latest.
View
4 Makefile
@@ -33,10 +33,10 @@ out/Makefile: common.gypi deps/uv/uv.gyp deps/http_parser/http_parser.gyp deps/z
tools/gyp_node -f make
install: all
- out/Release/node tools/installer.js ./config.gypi install
+ out/Release/node tools/installer.js install
uninstall:
- out/Release/node tools/installer.js ./config.gypi uninstall
+ out/Release/node tools/installer.js uninstall
clean:
-rm -rf out/Makefile node node_g out/$(BUILDTYPE)/node
View
27 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
View
6 node.gyp
@@ -219,8 +219,8 @@
'action_name': 'node_js2c',
'inputs': [
- './tools/js2c.py',
'<@(library_files)',
+ './config.gypi',
],
'outputs': [
@@ -237,14 +237,14 @@
'python',
'tools/js2c.py',
'<@(_outputs)',
- '<@(library_files)'
+ '<@(_inputs)',
],
}, { # No Dtrace
'action': [
'python',
'tools/js2c.py',
'<@(_outputs)',
- '<@(library_files)',
+ '<@(_inputs)',
'src/macros.py'
],
}]
View
14 src/node.js
@@ -37,6 +37,7 @@
startup.globalConsole();
startup.processAssert();
+ startup.processConfig();
startup.processNextTick();
startup.processStdio();
startup.processKillAndExit();
@@ -177,6 +178,15 @@
};
};
+ startup.processConfig = function() {
+ 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 = [];
@@ -467,6 +477,10 @@
NativeModule._source = process.binding('natives');
NativeModule._cache = {};
+ // used for `process.config`, but not a real module
+ var config = NativeModule._source.config;
+ delete NativeModule._source.config;
+
NativeModule.require = function(id) {
if (id == 'native_module') {
return NativeModule;
View
44 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);
View
12 tools/installer.js
@@ -1,21 +1,15 @@
var fs = require('fs'),
path = require('path'),
exec = require('child_process').exec,
- options = fs.readFileSync(process.argv[2]).toString(),
- cmd = process.argv[3];
+ cmd = process.argv[2];
if (cmd !== 'install' && cmd !== 'uninstall') {
console.error('Unknown command: ' + cmd);
process.exit(1);
}
-// Python pprint.pprint() uses single quotes instead of double.
-// awful.
-options = options.replace(/'/gi, '"')
-
-// Parse options file and remove first comment line
-options = JSON.parse(options.split('\n').slice(1).join(''));
-var variables = options.variables,
+// Use the built-in config reported by the current process
+var variables = process.config.variables,
node_prefix = variables.node_prefix || '/usr/local';
// Execution queue
View
2  tools/js2c.py
@@ -288,7 +288,7 @@ def JS2C(source, target):
lines = ExpandMacros(lines, macros)
lines = CompressScript(lines, do_jsmin)
data = ToCArray(s, lines)
- id = (os.path.split(str(s))[1])[:-3]
+ id = os.path.basename(str(s)).split('.')[0]
if delay: id = id[:-6]
if delay:
delay_ids.append((id, len(lines)))
Something went wrong with that request. Please try again.