{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node-gyp/issues/855","repository_url":"https://api.github.com/repos/nodejs/node-gyp","labels_url":"https://api.github.com/repos/nodejs/node-gyp/issues/855/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node-gyp/issues/855/comments","events_url":"https://api.github.com/repos/nodejs/node-gyp/issues/855/events","html_url":"https://github.com/nodejs/node-gyp/pull/855","id":125392413,"number":855,"title":"Add `target_modules_version` variable into generated config.gypi file","user":{"login":"pmed","id":1122386,"avatar_url":"https://avatars.githubusercontent.com/u/1122386?v=3","gravatar_id":"","url":"https://api.github.com/users/pmed","html_url":"https://github.com/pmed","followers_url":"https://api.github.com/users/pmed/followers","following_url":"https://api.github.com/users/pmed/following{/other_user}","gists_url":"https://api.github.com/users/pmed/gists{/gist_id}","starred_url":"https://api.github.com/users/pmed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmed/subscriptions","organizations_url":"https://api.github.com/users/pmed/orgs","repos_url":"https://api.github.com/users/pmed/repos","events_url":"https://api.github.com/users/pmed/events{/privacy}","received_events_url":"https://api.github.com/users/pmed/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-01-07T13:18:16Z","updated_at":"2016-07-16T09:26:58Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/node-gyp/pulls/855","html_url":"https://github.com/nodejs/node-gyp/pull/855","diff_url":"https://github.com/nodejs/node-gyp/pull/855.diff","patch_url":"https://github.com/nodejs/node-gyp/pull/855.patch"},"body":"It may be handy to have multiple native addon binaries for several Node.js versions (i.e. 0.12, 4.X, 5.X). Node.js has a value for the native modules version as `process.versions.modules`.\r\n\r\nA particular C++ addon can be loaded in JavaScript depending on Node.js version like this:\r\n\r\n```js\r\n  // loads 'addon_win32_x64_m47.node' for Node.js 5.0 on Windows x64\r\n  // loads 'addon_linux_x64_m46.node' for Node.js 4.X on Linux x64\r\n  var native = require('addon' + process.platform + '_'\r\n              + process.arch + '_m' + process.versions.modules + '.node');\r\n```\r\n\r\nThe target binary file name should be set with `product_name` directive in binding.gyp file in a such way:\r\n\r\n```gyp\r\n  {\r\n    'targets': [\r\n      {\r\n        'product_name': 'addon_<(target_platform)_<(target_arch)_m<(target_modules_version)'\r\n        ... # rest of GYP directives\r\n      }\r\n    ]\r\n  }\r\n```\r\n\r\nwhere `target_platform` is a configuration variable with value from Node.js `process.platform` property.\r\n\r\nBut the `process.versions.modules` value can't be used for `target_modules_version` since node-gyp can build targets for different Node.js versions specified with a `--target` command-line option.\r\n\r\nTo resolve this issue, a function getModulesVersion() was added on `configure` step to get a value of `NODE_MODULE_VERSION` defined in `node_version.h` file in a supplied directory with Node.js development files."},"comment":{"url":"https://api.github.com/repos/nodejs/node-gyp/issues/comments/233122007","html_url":"https://github.com/nodejs/node-gyp/pull/855#issuecomment-233122007","issue_url":"https://api.github.com/repos/nodejs/node-gyp/issues/855","id":233122007,"user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"created_at":"2016-07-16T09:26:58Z","updated_at":"2016-07-16T09:26:58Z","body":"This needs more tests, there are quite a few cases that aren't covered yet.  For example, the use case of `node-gyp --nodedir /path/to/master configure` (i.e., no version number in the path) should be tested because I'm quite sure that's broken now.\r\n\r\nIf you make the `fs.readFileSync` call pluggable, e.g. by making it an optional argument to `nodeModulesVersion()`, you can unit test it more easily."}}
{"actor":{"display_login":"bnoordhuis"}}