Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See issue nodejs#960

Added initial `gyp.js` support with --gypjs command line option.
Environment variable `npm_config_gypjs` also turns this option on.

Update configure and build usage strings depending on `npm_config_gypjs`
environment variable
  • Loading branch information
pmed committed Jun 19, 2016
1 parent 77383dd commit f9e3a54
Show file tree
Hide file tree
Showing 27 changed files with 157 additions and 94 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Command Options
| `--python=$path` | Set path to the python (2) binary
| `--msvs_version=$version` | Set Visual Studio version (win)
| `--solution=$solution` | Set Visual Studio Solution version (win)
| `--gypjs` | Use gyp.js instead of gyp


License
Expand Down
Empty file modified gyp/buildbot/buildbot_run.py
100755 → 100644
Empty file.
Empty file modified gyp/gyp
100755 → 100644
Empty file.
10 changes: 5 additions & 5 deletions gyp/gyp.bat
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@rem Copyright (c) 2009 Google Inc. All rights reserved.
@rem Use of this source code is governed by a BSD-style license that can be
@rem found in the LICENSE file.

@python "%~dp0gyp_main.py" %*
@rem Copyright (c) 2009 Google Inc. All rights reserved.
@rem Use of this source code is governed by a BSD-style license that can be
@rem found in the LICENSE file.

@python "%~dp0gyp_main.py" %*
Empty file modified gyp/gyp_main.py
100755 → 100644
Empty file.
Empty file modified gyp/gyptest.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/MSVSSettings_test.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/__init__.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/common_test.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/easy_xml_test.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/flock_tool.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/generator/msvs_test.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/input_test.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/mac_tool.py
100755 → 100644
Empty file.
Empty file modified gyp/pylib/gyp/win_tool.py
100755 → 100644
Empty file.
Empty file modified gyp/samples/samples
100755 → 100644
Empty file.
10 changes: 5 additions & 5 deletions gyp/samples/samples.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@rem Copyright (c) 2009 Google Inc. All rights reserved.
@rem Use of this source code is governed by a BSD-style license that can be
@rem found in the LICENSE file.

@python %~dp0/samples %*
@rem Copyright (c) 2009 Google Inc. All rights reserved.
@rem Use of this source code is governed by a BSD-style license that can be
@rem found in the LICENSE file.

@python %~dp0/samples %*
Empty file modified gyp/setup.py
100755 → 100644
Empty file.
Empty file modified gyp/tools/emacs/run-unit-tests.sh
100755 → 100644
Empty file.
Empty file modified gyp/tools/graphviz.py
100755 → 100644
Empty file.
Empty file modified gyp/tools/pretty_gyp.py
100755 → 100644
Empty file.
Empty file modified gyp/tools/pretty_sln.py
100755 → 100644
Empty file.
Empty file modified gyp/tools/pretty_vcproj.py
100755 → 100644
Empty file.
135 changes: 93 additions & 42 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var fs = require('graceful-fs')
, 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' : (win ? 'msbuild' : 'make')) + '` and builds the module'

function build (gyp, argv, callback) {
var platformMake = 'make'
Expand All @@ -36,8 +36,12 @@ function build (gyp, argv, callback) {
, config
, arch
, nodeDir
, vcDir
, copyDevLib

if (gyp.opts.gypjs) {
command = gyp.opts.ninja || process.env.NINJA || 'ninja'
}
loadConfigGypi()

/**
Expand Down Expand Up @@ -74,13 +78,40 @@ function build (gyp, argv, callback) {
log.verbose('node dev dir', nodeDir)

if (win) {
findSolutionFile()
gyp.opts.gypjs? findMSVS() : findSolutionFile()
} else {
doWhich()
}
})
}

/**
* On Windows, find Visual C++ toolset
*/

function findMSVS () {
var msvs_version = gyp.opts.msvs_version || 'auto'
var vs_versions = (msvs_version === 'auto'? [14, 12, 10] : [msvs_version])
vs_versions.find(function(version) {
var vscomntools = process.env['VS' + version + '0COMNTOOLS']
if (vscomntools) {
// remove quotes to work with path.join()
if (vscomntools.substr(0, 1) === '"' && vscomntools.substr(-1, 1) === '"') {
vscomntools = vscomntools.substr(1, vscomntools.length - 2)
}
vcDir = path.join(vscomntools, '..', '..', 'VC')
if (vcDir) {
log.verbose('found Visual C++ in ', vcDir)
return true
}
}
})
if (!vcDir) {
callback(new Error('Visual C++ not found, please setup a C++ compiler toolset'))
}
doWhich()
}

/**
* On Windows, find the first build/*.sln file.
*/
Expand All @@ -105,7 +136,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 {
Expand Down Expand Up @@ -212,54 +243,74 @@ 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)
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)
// invoke vcvarsall.bat before build
if (win && vcDir) {
argv.unshift(arch === 'ia32'? 'x86' : arch, '&', command)
command = path.join(vcDir, 'vcvarsall.bat')
}
}

Expand Down
93 changes: 51 additions & 42 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ var fs = require('graceful-fs')
, execFile = cp.execFile
, win = process.platform == 'win32'
, findNodeDirectory = require('./find-node-directory')
, msgFormat = require('util').format
, gypjs = require('gyp.js')

exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module'
exports.usage = 'Generates ' + (process.env.npm_config_gypjs? 'ninja build files' : (win ? 'MSVC project files' : 'a Makefile')) + ' for the current module'

function configure (gyp, argv, callback) {

Expand All @@ -34,14 +34,18 @@ function configure (gyp, argv, callback) {
, nodeDir
, release = processRelease(argv, gyp, process.version, process.release)

findPython(python, function (err, found) {
if (err) {
callback(err)
} else {
python = found
getNodeDir()
}
})
if (!gyp.opts.gypjs) {
findPython(python, function (err, found) {
if (err) {
callback(err)
} else {
python = found
getNodeDir()
}
})
} else {
getNodeDir()
}

function getNodeDir () {

Expand Down Expand Up @@ -188,35 +192,37 @@ function configure (gyp, argv, callback) {
function runGyp (err) {
if (err) return callback(err)

if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) {
if (win) {
log.verbose('gyp', 'gyp format was not specified; forcing "msvs"')
// force the 'make' target for non-Windows
argv.push('-f', 'msvs')
} else {
log.verbose('gyp', 'gyp format was not specified; forcing "make"')
// force the 'make' target for non-Windows
argv.push('-f', 'make')
if (!gyp.opts.gypjs) {
if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) {
if (win) {
log.verbose('gyp', 'gyp format was not specified; forcing "msvs"')
// force the 'make' target for non-Windows
argv.push('-f', 'msvs')
} else {
log.verbose('gyp', 'gyp format was not specified; forcing "make"')
// force the 'make' target for non-Windows
argv.push('-f', 'make')
}
}
}

function hasMsvsVersion () {
return argv.some(function (arg) {
return arg.indexOf('msvs_version') === 0
})
}
function hasMsvsVersion () {
return argv.some(function (arg) {
return arg.indexOf('msvs_version') === 0
})
}

if (win && !hasMsvsVersion()) {
if ('msvs_version' in gyp.opts) {
argv.push('-G', 'msvs_version=' + gyp.opts.msvs_version)
} else {
argv.push('-G', 'msvs_version=auto')
if (win && !hasMsvsVersion()) {
if ('msvs_version' in gyp.opts) {
argv.push('-G', 'msvs_version=' + gyp.opts.msvs_version)
} else {
argv.push('-G', 'msvs_version=auto')
}
}
}

// include all the ".gypi" files that were found
configs.forEach(function (config) {
argv.push('-I', config)
argv.push('-I' + config)
})

// for AIX we need to set up the path to the exp file
Expand All @@ -240,9 +246,8 @@ function configure (gyp, argv, callback) {
if (node_exp_file !== undefined) {
log.verbose(logprefix, 'Found exports file: %s', node_exp_file)
} else {
var msg = msgFormat('Could not find node.exp file in %s', node_root_dir)
log.error(logprefix, 'Could not find exports file')
return callback(new Error(msg))
return callback(new Error('Could not find node.exp file in ' + node_root_dir))
}
}

Expand All @@ -261,8 +266,8 @@ function configure (gyp, argv, callback) {
}
var nodeGypDir = path.resolve(__dirname, '..')

argv.push('-I', addon_gypi)
argv.push('-I', common_gypi)
argv.push('-I' + addon_gypi)
argv.push('-I' + common_gypi)
argv.push('-Dlibrary=shared_library')
argv.push('-Dvisibility=default')
argv.push('-Dnode_root_dir=' + nodeDir)
Expand All @@ -284,15 +289,19 @@ function configure (gyp, argv, callback) {
// enforce use of the "binding.gyp" file
argv.unshift('binding.gyp')

// execute `gyp` from the current target nodedir
argv.unshift(gyp_script)
if (!gyp.opts.gypjs) {
// execute `gyp` from the current target nodedir
argv.unshift(gyp_script)

// make sure python uses files that came with this particular node package
var pypath = new PathArray(process.env, 'PYTHONPATH')
pypath.unshift(path.join(__dirname, '..', 'gyp', 'pylib'))
// make sure python uses files that came with this particular node package
var pypath = new PathArray(process.env, 'PYTHONPATH')
pypath.unshift(path.join(__dirname, '..', 'gyp', 'pylib'))

var cp = gyp.spawn(python, argv)
cp.on('exit', onCpExit)
var cp = gyp.spawn(python, argv)
cp.on('exit', onCpExit)
} else {
onCpExit(gypjs.main(argv))
}
})
}

Expand Down
1 change: 1 addition & 0 deletions lib/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ proto.configDefs = {
, 'tarball': String // 'install'
, jobs: String // 'build'
, thin: String // 'configure'
, gypjs: Boolean // 'configure', 'build'
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"fstream": "^1.0.0",
"glob": "^7.0.3",
"graceful-fs": "^4.1.2",
"gyp.js": "^1.1.1",
"minimatch": "1",
"mkdirp": "^0.5.0",
"nopt": "2 || 3",
Expand Down

0 comments on commit f9e3a54

Please sign in to comment.