Skip to content

build: fix detection of Visual Studio 2017 - #30119

Merged
richardlau merged 1 commit into
nodejs:masterfrom
richardlau:vs2017
Nov 5, 2019
Merged

build: fix detection of Visual Studio 2017#30119
richardlau merged 1 commit into
nodejs:masterfrom
richardlau:vs2017

Conversation

@richardlau

@richardlaurichardlau commented Oct 25, 2019

Copy link
Copy Markdown
Member

When run in a Visual Studio 2017 command prompt the VCINSTALLDIR
environment variable will be already set and is not cleared by the
tools/msvs/vswhere_usability_wrapper.cmd utility when it fails to
find Visual Studio 2019. This causes vcbuild.bat to incorrectly
assume Visual Studio 2019 and generate an incompatible configuration.

Clearing the value of VCINSTALLDIR before calling the utility fixes
the detection logic.

Fixes: #30118
Refs: #30022

cc @nodejs/platform-windows @nodejs/build-files @targos

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-botnodejs-github-bot added build Issues and PRs related to build files or the CI. windows Issues and PRs related to the Windows platform. labels Oct 25, 2019
@nodejs-github-bot

This comment has been minimized.

@richardlaurichardlau changed the title build: fix detection of VS 2019 on Windowsbuild: fix detection of VS 2017 on WindowsOct 25, 2019
@richardlaurichardlau changed the title build: fix detection of VS 2017 on Windowsbuild: fix detection of Visual Studio 2017Oct 25, 2019
@targos

Copy link
Copy Markdown
Member

do you know why it's not found in the Look for Visual Studio 2017 block?

@targos

Copy link
Copy Markdown
Member

Maybe we need to change the argument to call tools\msvs\vswhere_usability_wrapper.cmd "[16.0,17.0)"

@richardlau

Copy link
Copy Markdown
MemberAuthor

do you know why it's not found in the Look for Visual Studio 2017 block?

Because it doesn't get there. See the debug in #30118 (comment).

@richardlau

richardlau commented Oct 25, 2019

Copy link
Copy Markdown
MemberAuthor

Or to be more specific in this block:

node/vcbuild.bat

Lines 239 to 272 in 11275dc

@rem Look for Visual Studio 2019
:vs-set-2019
ifdefined target_env if"%target_env%"NEQ"vs2019"goto vs-set-2017
echo Looking for Visual Studio 2019
call tools\msvs\vswhere_usability_wrapper.cmd "[16.0,17.0)"
if"_%VCINSTALLDIR%_"=="__"goto vs-set-2017
ifdefined msi (
echo Looking for WiX installation for Visual Studio 2019...
ifnotexist"%WIX%\SDK\VS2017" (
echo Failed to find WiX install for Visual Studio 2019
echo VS2019 support for WiX is only present starting at version 3.11
goto vs-set-2017
)
ifnotexist"%VCINSTALLDIR%\..\MSBuild\Microsoft\WiX" (
echo Failed to find the WiX Toolset Visual Studio 2019 Extension
goto vs-set-2017
)
)
@rem check if VS2019 is already setup, and for the requested arch
if"_%VisualStudioVersion%_"=="_16.0_"if"_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_"goto found_vs2019
@rem need to clear VSINSTALLDIR for vcvarsall to work as expected
set"VSINSTALLDIR="
@rem prevent VsDevCmd.bat from changing the current working directory
set"VSCMD_START_DIR=%CD%"
setvcvars_call="%VCINSTALLDIR%\Auxiliary\Build\vcvarsall.bat"%vcvarsall_arg%
echo calling: %vcvars_call%
call%vcvars_call%
iferrorlevel1goto vs-set-2017
ifdefined DEBUG_HELPER @ECHOON
:found_vs2019
echo Found MSVS version %VisualStudioVersion%
setGYP_MSVS_VERSION=2019
setPLATFORM_TOOLSET=v142
goto msbuild-found

On my system:

  • %VCINSTALLDIR% comes back as C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\ so the if test on L244 doesn't pass and it continues into the Looking for Visual Studio 2019 block.
  • The WiX test passes because apparently WiX uses the 2017 directory for 2019 too.
  • The test on L258 doesn't pass because %VisualStudioVersion% is 15.0.
  • The call %vcvars_call% on L265 succeeds so the if errorlevel test on the next line doesn't match and we drop into found_vs2019.

It looks like on the CI (which uses VS2017) %VCINSTALLDIR% is coming back empty. Perhaps this is a difference between the Professional (which I have) and Community (on the CI) editions of Visual Studio? Or is it something with tools\msvs\vswhere_usability_wrapper.cmd?

@richardlau

Copy link
Copy Markdown
MemberAuthor

It looks like on the CI (which uses VS2017) %VCINSTALLDIR% is coming back empty. Perhaps this is a difference between the Professional (which I have) and Community (on the CI) editions of Visual Studio? Or is it something with tools\msvs\vswhere_usability_wrapper.cmd?

Ah, it's probably because I build Node.js inside a "Developer Command Prompt for VS 2017" command prompt which has set up that environment variable.

@richardlau

Copy link
Copy Markdown
MemberAuthor

I've got a build going at the moment but when it completes I'll try clearing VCINSTALLDIR before we call tools\msvs\vswhere_usability_wrapper.cmd.

@richardlaurichardlau added the wip Issues and PRs that are still a work in progress. label Oct 25, 2019
@richardlaurichardlau removed the wip Issues and PRs that are still a work in progress. label Oct 25, 2019
@richardlau

Copy link
Copy Markdown
MemberAuthor

@targos I've updated this PR. Turns out all we need to do is clear the value of the VCINSTALLDIR environment variable before calling tools/msvs/vswhere_usability_wrapper.cmd so that the subsequent logic works properly.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@richardlaurichardlau added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 26, 2019
@targos

Copy link
Copy Markdown
Member

@joaocgreis

@joaocgreisjoaocgreis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @richardlau!

Comment threadvcbuild.bat Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set"VCINSTALLDIR="
@rem VS2017 is detected here when VCINSTALLDIR is set (as in VS Command Prompt)
set"VCINSTALLDIR="

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, this is just a suggestion. Feel free to take it, change it as you see fit or leave it.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a (different) comment. PTAL.

@richardlau
richardlauforce-pushed the vs2017 branch 2 times, most recently from dcdd328 to 07c4965CompareOctober 31, 2019 05:39
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

nodejs-github-bot commented Oct 31, 2019

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

When run in a Visual Studio 2017 command prompt the `VCINSTALLDIR`
environment variable will be already set and is not cleared by the
`tools/msvs/vswhere_usability_wrapper.cmd` utility when it fails to
find Visual Studio 2019. This causes `vcbuild.bat` to incorrectly
assume Visual Studio 2019 and generate an incompatible configuration.
Clearing the value of `VCINSTALLDIR` before calling the utility fixes
the detection logic.
PR-URL: nodejs#30119Fixes: nodejs#30118
Refs: nodejs#30022
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: João Reis <reis@janeasystems.com>
@richardlau
richardlau merged commit 1f2fdc9 into nodejs:masterNov 5, 2019
@richardlau

Copy link
Copy Markdown
MemberAuthor

Landed in 1f2fdc9

@richardlau
richardlau deleted the vs2017 branch November 5, 2019 04:03
targos pushed a commit that referenced this pull request Nov 5, 2019
When run in a Visual Studio 2017 command prompt the `VCINSTALLDIR`
environment variable will be already set and is not cleared by the
`tools/msvs/vswhere_usability_wrapper.cmd` utility when it fails to
find Visual Studio 2019. This causes `vcbuild.bat` to incorrectly
assume Visual Studio 2019 and generate an incompatible configuration.
Clearing the value of `VCINSTALLDIR` before calling the utility fixes
the detection logic.
PR-URL: #30119Fixes: #30118
Refs: #30022
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: João Reis <reis@janeasystems.com>
@targostargos mentioned this pull request Nov 5, 2019
@richardlaurichardlau mentioned this pull request Jan 17, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.buildIssues and PRs related to build files or the CI.windowsIssues and PRs related to the Windows platform.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vcbuild.bat fails with Visual Studio 2017

5 participants

@richardlau@nodejs-github-bot@targos@joaocgreis@jasnell