-
Notifications
You must be signed in to change notification settings - Fork 993
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
Add support for vcvars when using Powershell #15461
Changes from all commits
8b1a1e9
5472ec7
e2c9211
bbd9ba3
435f30e
1d34797
54c1921
979f262
ab184fc
68e9fd0
4f50919
008eda7
af6408b
be0e62c
dcd4fb4
0475d83
62238be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
from conan.tools.scm import Version | ||
from conan.tools.intel.intel_cc import IntelCC | ||
|
||
CONAN_VCVARS_FILE = "conanvcvars.bat" | ||
CONAN_VCVARS_BAT = "conanvcvars.bat" | ||
CONAN_VCVARS_PS1 = "conanvcvars.ps1" | ||
|
||
|
||
def check_min_vs(conanfile, version, raise_invalid=True): | ||
|
@@ -142,15 +143,32 @@ def generate(self, scope="build"): | |
winsdk_version=winsdk_version, vcvars_ver=vcvars_ver, | ||
vs_install_path=vs_install_path) | ||
|
||
content = textwrap.dedent("""\ | ||
content = textwrap.dedent(f"""\ | ||
@echo off | ||
set __VSCMD_ARG_NO_LOGO=1 | ||
set VSCMD_SKIP_SENDTELEMETRY=1 | ||
echo conanvcvars.bat: Activating environment Visual Studio {} - {} - winsdk_version={} - vcvars_ver={} | ||
{} | ||
""".format(vs_version, vcvarsarch, winsdk_version, vcvars_ver, vcvars)) | ||
echo conanvcvars.bat: Activating environment Visual Studio {vs_version} - {vcvarsarch} - winsdk_version={winsdk_version} - vcvars_ver={vcvars_ver} | ||
{vcvars} | ||
""") | ||
from conan.tools.env.environment import create_env_script | ||
create_env_script(conanfile, content, CONAN_VCVARS_FILE, scope) | ||
create_env_script(conanfile, content, CONAN_VCVARS_BAT, scope) | ||
|
||
is_ps1 = conanfile.conf.get("tools.env.virtualenv:powershell", check_type=bool, default=False) | ||
if is_ps1: | ||
content_ps1 = textwrap.dedent(f"""\ | ||
if (-not $env:VSCMD_ARG_VCVARS_VER){{ | ||
Push-Location "$PSScriptRoot" | ||
cmd /c "conanvcvars.bat&set" | | ||
memsharded marked this conversation as resolved.
Show resolved
Hide resolved
|
||
foreach {{ | ||
if ($_ -match "=") {{ | ||
$v = $_.split("=", 2); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])" | ||
}} | ||
}} | ||
Pop-Location | ||
write-host conanvcvars.ps1: Activated environment}} | ||
""") | ||
Comment on lines
+161
to
+169
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. I know no-one asked for my opinion ( :) ) but this makes me uneasy. here's how you could do it similarly than the Launch-VsDevShell.ps1 ( $vspath=$(vswhere -products '*' -requires Microsoft.Component.MSBuild -property installationPath -latest)
$devShellModule = "$vspath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Import-Module $devShellModule
Enter-VsDevShell -VsInstallPath $vspath -SkipAutomaticLocation -Arch amd64 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. Get-Help Enter-VsDevShell
NAME
Enter-VsDevShell
SYNTAX
Enter-VsDevShell -VsInstallPath <string> [-SkipExistingEnvironmentVariables] [-StartInPath <string>] [-Arch {Default | x86 | amd64 | arm | arm64}] [-HostArch {Default | x86 | amd64}]
[-DevCmdArguments <string>] [-DevCmdDebugLevel {None | Basic | Detailed | Trace}] [-SkipAutomaticLocation] [-SetDefaultWindowTitle] [-ReportNewInstanceType {PowerShell | Cmd |
LaunchScript}] [<CommonParameters>]
Enter-VsDevShell [-VsInstanceId] <string> [-SkipExistingEnvironmentVariables] [-StartInPath <string>] [-Arch {Default | x86 | amd64 | arm | arm64}] [-HostArch {Default | x86 |
amd64}] [-DevCmdArguments <string>] [-DevCmdDebugLevel {None | Basic | Detailed | Trace}] [-SkipAutomaticLocation] [-SetDefaultWindowTitle] [-ReportNewInstanceType {PowerShell | Cmd
| LaunchScript}] [<CommonParameters>]
Enter-VsDevShell [-Arch {Default | x86 | amd64 | arm | arm64}] [-HostArch {Default | x86 | amd64}] [-Test] [-DevCmdDebugLevel {None | Basic | Detailed | Trace}] [<CommonParameters>]
ALIASES
None
REMARKS
None 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. Hi @jmarrec - thanks for your feedback. This is the approach we considered initially, but discarded it for a couple of reasons:
we wouldn't want to use undocumented/subject to breakages features, and the 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. Gotcha, thanks a lot for the detailed explanation! |
||
create_env_script(conanfile, content_ps1, CONAN_VCVARS_PS1, scope) | ||
|
||
|
||
|
||
def vs_ide_version(conanfile): | ||
|
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.
I reverted this back to using "push/pop" as calling the path directly in the cmd command was causing trouble when path had spaces.