]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py
1 # @file WindowsVsToolChain.py
2 # Plugin to configures paths for the VS2017 and VS2019 tool chain
4 # This plugin works in conjuncture with the tools_def
6 # Copyright (c) Microsoft Corporation
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 from edk2toolext
.environment
.plugintypes
.uefi_build_plugin
import IUefiBuildPlugin
12 import edk2toollib
.windows
.locate_tools
as locate_tools
13 from edk2toollib
.windows
.locate_tools
import FindWithVsWhere
14 from edk2toolext
.environment
import shell_environment
15 from edk2toolext
.environment
import version_aggregator
18 class WindowsVsToolChain(IUefiBuildPlugin
):
20 def do_post_build(self
, thebuilder
):
23 def do_pre_build(self
, thebuilder
):
24 self
.Logger
= logging
.getLogger("WindowsVsToolChain")
25 interesting_keys
= ["ExtensionSdkDir", "INCLUDE", "LIB", "LIBPATH", "UniversalCRTSdkDir",
26 "UCRTVersion", "WindowsLibPath", "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
27 "WindowsSDKVersion", "VCToolsInstallDir", "Path"]
30 # VS2017 - Follow VS2017 where there is potential for many versions of the tools.
31 # If a specific version is required then the user must set both env variables:
32 # VS150INSTALLPATH: base install path on system to VC install dir. Here you will find the VC folder, etc
33 # VS150TOOLVER: version number for the VC compiler tools
34 # VS2017_PREFIX: path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
35 if thebuilder
.env
.GetValue("TOOL_CHAIN_TAG") == "VS2017":
37 # check to see if full path already configured
38 if shell_environment
.GetEnvironment().get_shell_var("VS2017_PREFIX") != None:
39 self
.Logger
.info("VS2017_PREFIX is already set.")
42 install_path
= self
._get
_vs
_install
_path
(
43 "VS2017".lower(), "VS150INSTALLPATH")
44 vc_ver
= self
._get
_vc
_version
(install_path
, "VS150TOOLVER")
46 if install_path
is None or vc_ver
is None:
48 "Failed to configure environment for VS2017")
51 version_aggregator
.GetVersionAggregator().ReportVersion(
52 "Visual Studio Install Path", install_path
, version_aggregator
.VersionTypes
.INFO
)
53 version_aggregator
.GetVersionAggregator().ReportVersion(
54 "VC Version", vc_ver
, version_aggregator
.VersionTypes
.TOOL
)
56 # make VS2017_PREFIX to align with tools_def.txt
57 prefix
= os
.path
.join(install_path
, "VC",
58 "Tools", "MSVC", vc_ver
)
59 prefix
= prefix
+ os
.path
.sep
60 shell_environment
.GetEnvironment().set_shell_var("VS2017_PREFIX", prefix
)
62 shell_env
= shell_environment
.GetEnvironment()
63 # Use the tools lib to determine the correct values for the vars that interest us.
64 vs_vars
= locate_tools
.QueryVcVariables(
65 interesting_keys
, "amd64", vs_version
="vs2017")
66 for (k
, v
) in vs_vars
.items():
67 if k
.upper() == "PATH":
68 shell_env
.insert_path(v
)
70 shell_env
.set_shell_var(k
, v
)
72 # now confirm it exists
73 if not os
.path
.exists(shell_environment
.GetEnvironment().get_shell_var("VS2017_PREFIX")):
74 self
.Logger
.error("Path for VS2017 toolchain is invalid")
78 # VS2019 - Follow VS2019 where there is potential for many versions of the tools.
79 # If a specific version is required then the user must set both env variables:
80 # VS160INSTALLPATH: base install path on system to VC install dir. Here you will find the VC folder, etc
81 # VS160TOOLVER: version number for the VC compiler tools
82 # VS2019_PREFIX: path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
83 elif thebuilder
.env
.GetValue("TOOL_CHAIN_TAG") == "VS2019":
85 # check to see if full path already configured
86 if shell_environment
.GetEnvironment().get_shell_var("VS2019_PREFIX") != None:
87 self
.Logger
.info("VS2019_PREFIX is already set.")
90 install_path
= self
._get
_vs
_install
_path
(
91 "VS2019".lower(), "VS160INSTALLPATH")
92 vc_ver
= self
._get
_vc
_version
(install_path
, "VS160TOOLVER")
94 if install_path
is None or vc_ver
is None:
96 "Failed to configure environment for VS2019")
99 version_aggregator
.GetVersionAggregator().ReportVersion(
100 "Visual Studio Install Path", install_path
, version_aggregator
.VersionTypes
.INFO
)
101 version_aggregator
.GetVersionAggregator().ReportVersion(
102 "VC Version", vc_ver
, version_aggregator
.VersionTypes
.TOOL
)
104 # make VS2019_PREFIX to align with tools_def.txt
105 prefix
= os
.path
.join(install_path
, "VC",
106 "Tools", "MSVC", vc_ver
)
107 prefix
= prefix
+ os
.path
.sep
108 shell_environment
.GetEnvironment().set_shell_var("VS2019_PREFIX", prefix
)
110 shell_env
= shell_environment
.GetEnvironment()
111 # Use the tools lib to determine the correct values for the vars that interest us.
112 vs_vars
= locate_tools
.QueryVcVariables(
113 interesting_keys
, "amd64", vs_version
="vs2019")
114 for (k
, v
) in vs_vars
.items():
115 if k
.upper() == "PATH":
116 shell_env
.insert_path(v
)
118 shell_env
.set_shell_var(k
, v
)
120 # now confirm it exists
121 if not os
.path
.exists(shell_environment
.GetEnvironment().get_shell_var("VS2019_PREFIX")):
122 self
.Logger
.error("Path for VS2019 toolchain is invalid")
127 def _get_vs_install_path(self
, vs_version
, varname
):
128 # check if already specified
129 path
= shell_environment
.GetEnvironment().get_shell_var(varname
)
131 # Not specified...find latest
132 (rc
, path
) = FindWithVsWhere(vs_version
=vs_version
)
133 if rc
== 0 and path
is not None and os
.path
.exists(path
):
134 self
.Logger
.debug("Found VS instance for %s", vs_version
)
137 "Failed to find VS instance with VsWhere (%d)" % rc
)
140 def _get_vc_version(self
, path
, varname
):
141 # check if already specified
142 vc_ver
= shell_environment
.GetEnvironment().get_shell_var(varname
)
144 self
.Logger
.critical(
145 "Failed to find Visual Studio tools. Might need to check for VS install")
148 # Not specified...find latest
149 p2
= os
.path
.join(path
, "VC", "Tools", "MSVC")
150 if not os
.path
.isdir(p2
):
151 self
.Logger
.critical(
152 "Failed to find VC tools. Might need to check for VS install")
154 vc_ver
= os
.listdir(p2
)[-1].strip() # get last in list
155 self
.Logger
.debug("Found VC Tool version is %s" % vc_ver
)