-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: add gyp.js support #1092
Open
indutny
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
indutny:feature/gyp.js-pmed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
lib: add gyp.js support #1092
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,12 @@ var fs = require('graceful-fs') | |
, glob = require('glob') | ||
, log = require('npmlog') | ||
, which = require('which') | ||
, mkdirp = require('mkdirp') | ||
, exec = require('child_process').exec | ||
, processRelease = require('./process-release') | ||
, win = process.platform == 'win32' | ||
|
||
exports.usage = 'Invokes `' + (win ? 'msbuild' : 'make') + '` and builds the module' | ||
exports.usage = 'Invokes `' + (process.env.npm_config_gypjs ? 'ninja' : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can move to ` templates |
||
(win ? 'msbuild' : 'make')) + '` and builds the module' | ||
|
||
function build (gyp, argv, callback) { | ||
var platformMake = 'make' | ||
|
@@ -36,8 +36,10 @@ function build (gyp, argv, callback) { | |
, config | ||
, arch | ||
, nodeDir | ||
, copyDevLib | ||
|
||
if (gyp.opts.gypjs) { | ||
command = gyp.opts.ninja || process.env.NINJA || 'ninja' | ||
} | ||
loadConfigGypi() | ||
|
||
/** | ||
|
@@ -60,7 +62,6 @@ function build (gyp, argv, callback) { | |
buildType = config.target_defaults.default_configuration | ||
arch = config.variables.target_arch | ||
nodeDir = config.variables.nodedir | ||
copyDevLib = config.variables.copy_dev_lib == 'true' | ||
|
||
if ('debug' in gyp.opts) { | ||
buildType = gyp.opts.debug ? 'Debug' : 'Release' | ||
|
@@ -73,7 +74,7 @@ function build (gyp, argv, callback) { | |
log.verbose('architecture', arch) | ||
log.verbose('node dev dir', nodeDir) | ||
|
||
if (win) { | ||
if (win && !gyp.opts.gypjs) { | ||
findSolutionFile() | ||
} else { | ||
doWhich() | ||
|
@@ -105,7 +106,7 @@ function build (gyp, argv, callback) { | |
// First make sure we have the build command in the PATH | ||
which(command, function (err, execPath) { | ||
if (err) { | ||
if (win && /not found/.test(err.message)) { | ||
if (win && !gyp.opts.gypjs && /not found/.test(err.message)) { | ||
// On windows and no 'msbuild' found. Let's guess where it is | ||
findMsbuild() | ||
} else { | ||
|
@@ -115,7 +116,7 @@ function build (gyp, argv, callback) { | |
return | ||
} | ||
log.verbose('`which` succeeded for `' + command + '`', execPath) | ||
copyNodeLib() | ||
doBuild() | ||
}) | ||
} | ||
|
||
|
@@ -173,36 +174,12 @@ function build (gyp, argv, callback) { | |
return | ||
} | ||
command = msbuildPath | ||
copyNodeLib() | ||
doBuild() | ||
}) | ||
})() | ||
}) | ||
} | ||
|
||
/** | ||
* Copies the node.lib file for the current target architecture into the | ||
* current proper dev dir location. | ||
*/ | ||
|
||
function copyNodeLib () { | ||
if (!win || !copyDevLib) return doBuild() | ||
|
||
var buildDir = path.resolve(nodeDir, buildType) | ||
, archNodeLibPath = path.resolve(nodeDir, arch, release.name + '.lib') | ||
, buildNodeLibPath = path.resolve(buildDir, release.name + '.lib') | ||
|
||
mkdirp(buildDir, function (err, isNew) { | ||
if (err) return callback(err) | ||
log.verbose('"' + buildType + '" dir needed to be created?', isNew) | ||
var rs = fs.createReadStream(archNodeLibPath) | ||
, ws = fs.createWriteStream(buildNodeLibPath) | ||
log.verbose('copying "' + release.name + '.lib" for ' + arch, buildNodeLibPath) | ||
rs.pipe(ws) | ||
rs.on('error', callback) | ||
ws.on('error', callback) | ||
rs.on('end', doBuild) | ||
}) | ||
} | ||
|
||
/** | ||
* Actually spawn the process and compile the module. | ||
|
@@ -212,57 +189,72 @@ function build (gyp, argv, callback) { | |
|
||
// Enable Verbose build | ||
var verbose = log.levels[log.level] <= log.levels.verbose | ||
if (!win && verbose) { | ||
argv.push('V=1') | ||
} | ||
if (win && !verbose) { | ||
argv.push('/clp:Verbosity=minimal') | ||
} | ||
if (!gyp.opts.gypjs) { | ||
if (!win && verbose) { | ||
argv.push('V=1') | ||
} | ||
if (win && !verbose) { | ||
argv.push('/clp:Verbosity=minimal') | ||
} | ||
|
||
if (win) { | ||
// Turn off the Microsoft logo on Windows | ||
argv.push('/nologo') | ||
} | ||
if (win) { | ||
// Turn off the Microsoft logo on Windows | ||
argv.push('/nologo') | ||
} | ||
|
||
// Specify the build type, Release by default | ||
if (win) { | ||
var p = arch === 'x64' ? 'x64' : 'Win32' | ||
argv.push('/p:Configuration=' + buildType + ';Platform=' + p) | ||
if (jobs) { | ||
var j = parseInt(jobs, 10) | ||
if (!isNaN(j) && j > 0) { | ||
argv.push('/m:' + j) | ||
} else if (jobs.toUpperCase() === 'MAX') { | ||
argv.push('/m:' + require('os').cpus().length) | ||
// Specify the build type, Release by default | ||
if (win) { | ||
var p = arch === 'x64' ? 'x64' : 'Win32' | ||
argv.push('/p:Configuration=' + buildType + ';Platform=' + p) | ||
if (jobs) { | ||
var j = parseInt(jobs, 10) | ||
if (!isNaN(j) && j > 0) { | ||
argv.push('/m:' + j) | ||
} else if (jobs.toUpperCase() === 'MAX') { | ||
argv.push('/m:' + require('os').cpus().length) | ||
} | ||
} | ||
} else { | ||
argv.push('BUILDTYPE=' + buildType) | ||
// Invoke the Makefile in the 'build' dir. | ||
argv.push('-C') | ||
argv.push('build') | ||
if (jobs) { | ||
var j = parseInt(jobs, 10) | ||
if (!isNaN(j) && j > 0) { | ||
argv.push('--jobs') | ||
argv.push(j) | ||
} else if (jobs.toUpperCase() === 'MAX') { | ||
argv.push('--jobs') | ||
argv.push(require('os').cpus().length) | ||
} | ||
} | ||
} | ||
|
||
if (win) { | ||
// did the user specify their own .sln file? | ||
var hasSln = argv.some(function (arg) { | ||
return path.extname(arg) == '.sln' | ||
}) | ||
if (!hasSln) { | ||
argv.unshift(gyp.opts.solution || guessedSolution) | ||
} | ||
} | ||
} else { | ||
argv.push('BUILDTYPE=' + buildType) | ||
// Invoke the Makefile in the 'build' dir. | ||
argv.push('-C') | ||
argv.push('build') | ||
// build with ninja | ||
if (verbose) { | ||
argv.push('-v') | ||
} | ||
// Specify the build type, Release by default | ||
argv.push('-C', path.join('build', buildType)) | ||
if (jobs) { | ||
var j = parseInt(jobs, 10) | ||
var j = jobs.toUpperCase() === 'MAX'? require('os').cpus().length : parseInt(jobs, 10) | ||
jbergstroem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!isNaN(j) && j > 0) { | ||
argv.push('--jobs') | ||
argv.push(j) | ||
} else if (jobs.toUpperCase() === 'MAX') { | ||
argv.push('--jobs') | ||
argv.push(require('os').cpus().length) | ||
argv.push('-j' + j) | ||
} | ||
} | ||
} | ||
|
||
if (win) { | ||
// did the user specify their own .sln file? | ||
var hasSln = argv.some(function (arg) { | ||
return path.extname(arg) == '.sln' | ||
}) | ||
if (!hasSln) { | ||
argv.unshift(gyp.opts.solution || guessedSolution) | ||
} | ||
} | ||
|
||
var proc = gyp.spawn(command, argv) | ||
proc.on('exit', onExit) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO no need for this after #1185