Skip to content
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

Support rebuild and build when configure with -- -f make on Windows #2974

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 18 additions & 12 deletions lib/build.js
Expand Up @@ -85,59 +85,65 @@ async function build (gyp, argv) {
async function findSolutionFile () {
const files = await glob('build/*.sln')
if (files.length === 0) {
throw new Error('Could not find *.sln file. Did you run "configure"?')
if (require('fs').existsSync('build/Makefile') || (await glob('build/*.mk')).length !== 0) {
command = makeCommand
await doWhich(false)
return
} else {
throw new Error('Could not find *.sln file or Makefile. Did you run "configure"?')
}
}
guessedSolution = files[0]
log.verbose('found first Solution file', guessedSolution)
await doWhich()
await doWhich(true)
}

/**
* Uses node-which to locate the msbuild / make executable.
*/

async function doWhich () {
async function doWhich (msvs) {
// On Windows use msbuild provided by node-gyp configure
if (win) {
if (msvs) {
if (!config.variables.msbuild_path) {
throw new Error('MSBuild is not set, please run `node-gyp configure`.')
}
command = config.variables.msbuild_path
log.verbose('using MSBuild:', command)
await doBuild()
await doBuild(msvs)
return
}

// First make sure we have the build command in the PATH
const execPath = await which(command)
log.verbose('`which` succeeded for `' + command + '`', execPath)
await doBuild()
await doBuild(msvs)
}

/**
* Actually spawn the process and compile the module.
*/

async function doBuild () {
async function doBuild (msvs) {
// Enable Verbose build
const verbose = log.logger.isVisible('verbose')
let j

if (!win && verbose) {
if (!msvs && verbose) {
argv.push('V=1')
}

if (win && !verbose) {
if (msvs && !verbose) {
argv.push('/clp:Verbosity=minimal')
}

if (win) {
if (msvs) {
// Turn off the Microsoft logo on Windows
argv.push('/nologo')
}

// Specify the build type, Release by default
if (win) {
if (msvs) {
// Convert .gypi config target_arch to MSBuild /Platform
// Since there are many ways to state '32-bit Intel', default to it.
// N.B. msbuild's Condition string equality tests are case-insensitive.
Expand Down Expand Up @@ -173,7 +179,7 @@ async function build (gyp, argv) {
}
}

if (win) {
if (msvs) {
// did the user specify their own .sln file?
const hasSln = argv.some(function (arg) {
return path.extname(arg) === '.sln'
Expand Down
18 changes: 16 additions & 2 deletions lib/configure.js
Expand Up @@ -92,8 +92,22 @@ async function configure (gyp, argv) {
log.verbose(
'build dir', '"build" dir needed to be created?', isNew ? 'Yes' : 'No'
)
const vsInfo = win ? await findVisualStudio(release.semver, gyp.opts['msvs-version']) : null
return createConfigFile(vsInfo)
if (win) {
let gypFormatIndex = argv.indexOf('-f')
if (gypFormatIndex === -1) {
gypFormatIndex = argv.indexOf('--format')
}
if (gypFormatIndex === -1 || !argv[gypFormatIndex + 1] || argv[gypFormatIndex + 1].startsWith('msvs')) {
const vsInfo = await findVisualStudio(release.semver, gyp.opts['msvs-version'])
return createConfigFile(vsInfo)
}
let vsInfo = {}
try {
vsInfo = await findVisualStudio(release.semver, gyp.opts['msvs-version'])
} catch (_) {}
return createConfigFile(vsInfo)
}
return createConfigFile(null)
}

async function createConfigFile (vsInfo) {
Expand Down