build.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. module.exports = exports = build;
  3. exports.usage = 'Attempts to compile the module by dispatching to node-gyp or nw-gyp';
  4. const napi = require('./util/napi.js');
  5. const compile = require('./util/compile.js');
  6. const handle_gyp_opts = require('./util/handle_gyp_opts.js');
  7. const configure = require('./configure.js');
  8. function do_build(gyp, argv, callback) {
  9. handle_gyp_opts(gyp, argv, (err, result) => {
  10. let final_args = ['build'].concat(result.gyp).concat(result.pre);
  11. if (result.unparsed.length > 0) {
  12. final_args = final_args.
  13. concat(['--']).
  14. concat(result.unparsed);
  15. }
  16. if (!err && result.opts.napi_build_version) {
  17. napi.swap_build_dir_in(result.opts.napi_build_version);
  18. }
  19. compile.run_gyp(final_args, result.opts, (err2) => {
  20. if (result.opts.napi_build_version) {
  21. napi.swap_build_dir_out(result.opts.napi_build_version);
  22. }
  23. return callback(err2);
  24. });
  25. });
  26. }
  27. function build(gyp, argv, callback) {
  28. // Form up commands to pass to node-gyp:
  29. // We map `node-pre-gyp build` to `node-gyp configure build` so that we do not
  30. // trigger a clean and therefore do not pay the penalty of a full recompile
  31. if (argv.length && (argv.indexOf('rebuild') > -1)) {
  32. argv.shift(); // remove `rebuild`
  33. // here we map `node-pre-gyp rebuild` to `node-gyp rebuild` which internally means
  34. // "clean + configure + build" and triggers a full recompile
  35. compile.run_gyp(['clean'], {}, (err3) => {
  36. if (err3) return callback(err3);
  37. configure(gyp, argv, (err4) => {
  38. if (err4) return callback(err4);
  39. return do_build(gyp, argv, callback);
  40. });
  41. });
  42. } else {
  43. return do_build(gyp, argv, callback);
  44. }
  45. }