[edk2-devel] [PATCH] BaseTools/WindowsVsToolChain.py: Update toolchain plugin

Zhang, Shenglei posted 1 patch 4 years ago
Failed in applying to current master (apply log)
.../WindowsVsToolChain/WindowsVsToolChain.py  | 73 ++++++++++++++++---
1 file changed, 62 insertions(+), 11 deletions(-)
[edk2-devel] [PATCH] BaseTools/WindowsVsToolChain.py: Update toolchain plugin
Posted by Zhang, Shenglei 4 years ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2659
Allow WindowsVsToolChain Plugin to add libraries and headers
of user defined ARCH for VS2017 and VS2019.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
 .../WindowsVsToolChain/WindowsVsToolChain.py  | 73 ++++++++++++++++---
 1 file changed, 62 insertions(+), 11 deletions(-)

diff --git a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py
index c9279e1c75b5..0fba2c1b5325 100644
--- a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py
+++ b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py
@@ -13,6 +13,7 @@ import edk2toollib.windows.locate_tools as locate_tools
 from edk2toollib.windows.locate_tools import FindWithVsWhere
 from edk2toolext.environment import shell_environment
 from edk2toolext.environment import version_aggregator
+from edk2toollib.utility_functions import GetHostInfo
 
 
 class WindowsVsToolChain(IUefiBuildPlugin):
@@ -26,14 +27,41 @@ class WindowsVsToolChain(IUefiBuildPlugin):
                             "UCRTVersion", "WindowsLibPath", "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
                             "WindowsSDKVersion", "VCToolsInstallDir", "Path"]
 
-#
+        #
         # VS2017 - Follow VS2017 where there is potential for many versions of the tools.
         # If a specific version is required then the user must set both env variables:
         # VS150INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
         # VS150TOOLVER:      version number for the VC compiler tools
         # VS2017_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
+        # VS2017_HOST:       set the host architecture to use for host tools, and host libs, etc
         if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2017":
 
+            # check to see if host is configured
+            # HostType for VS2017 should be (defined in tools_def):
+            # x86   == 32bit Intel
+            # x64   == 64bit Intel
+            # arm   == 32bit Arm
+            # arm64 == 64bit Arm
+            #
+            HostType = shell_environment.GetEnvironment().get_shell_var("VS2017_HOST")
+            if HostType is not None:
+                HostType = HostType.lower()
+                self.Logger.info(
+                    f"HOST TYPE defined by environment.  Host Type is {HostType}")
+            else:
+                HostInfo = GetHostInfo()
+                if HostInfo.arch == "x86":
+                    if HostInfo.bit == "32":
+                        HostType = "x86"
+                    elif HostInfo.bit == "64":
+                        HostType = "x64"
+                else:
+                    raise NotImplementedError()
+
+            # VS2017_HOST options are not exactly the same as QueryVcVariables. This translates.
+            VC_HOST_ARCH_TRANSLATOR = {
+                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}
+
             # check to see if full path already configured
             if shell_environment.GetEnvironment().get_shell_var("VS2017_PREFIX") != None:
                 self.Logger.info("VS2017_PREFIX is already set.")
@@ -58,16 +86,14 @@ class WindowsVsToolChain(IUefiBuildPlugin):
                                       "Tools", "MSVC", vc_ver)
                 prefix = prefix + os.path.sep
                 shell_environment.GetEnvironment().set_shell_var("VS2017_PREFIX", prefix)
+                shell_environment.GetEnvironment().set_shell_var("VS2017_HOST", HostType)
 
                 shell_env = shell_environment.GetEnvironment()
                 # Use the tools lib to determine the correct values for the vars that interest us.
                 vs_vars = locate_tools.QueryVcVariables(
-                    interesting_keys, "amd64", vs_version="vs2017")
+                    interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="vs2017")
                 for (k, v) in vs_vars.items():
-                    if k.upper() == "PATH":
-                        shell_env.insert_path(v)
-                    else:
-                        shell_env.set_shell_var(k, v)
+                    shell_env.set_shell_var(k, v)
 
             # now confirm it exists
             if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("VS2017_PREFIX")):
@@ -80,8 +106,35 @@ class WindowsVsToolChain(IUefiBuildPlugin):
         # VS160INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
         # VS160TOOLVER:      version number for the VC compiler tools
         # VS2019_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
+        # VS2017_HOST:       set the host architecture to use for host tools, and host libs, etc
         elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019":
 
+            # check to see if host is configured
+            # HostType for VS2019 should be (defined in tools_def):
+            # x86   == 32bit Intel
+            # x64   == 64bit Intel
+            # arm   == 32bit Arm
+            # arm64 == 64bit Arm
+            #
+            HostType = shell_environment.GetEnvironment().get_shell_var("VS2019_HOST")
+            if HostType is not None:
+                HostType = HostType.lower()
+                self.Logger.info(
+                    f"HOST TYPE defined by environment.  Host Type is {HostType}")
+            else:
+                HostInfo = GetHostInfo()
+                if HostInfo.arch == "x86":
+                    if HostInfo.bit == "32":
+                        HostType = "x86"
+                    elif HostInfo.bit == "64":
+                        HostType = "x64"
+                else:
+                    raise NotImplementedError()
+
+            # VS2019_HOST options are not exactly the same as QueryVcVariables. This translates.
+            VC_HOST_ARCH_TRANSLATOR = {
+                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}
+
             # check to see if full path already configured
             if shell_environment.GetEnvironment().get_shell_var("VS2019_PREFIX") != None:
                 self.Logger.info("VS2019_PREFIX is already set.")
@@ -106,16 +159,14 @@ class WindowsVsToolChain(IUefiBuildPlugin):
                                       "Tools", "MSVC", vc_ver)
                 prefix = prefix + os.path.sep
                 shell_environment.GetEnvironment().set_shell_var("VS2019_PREFIX", prefix)
+                shell_environment.GetEnvironment().set_shell_var("VS2019_HOST", HostType)
 
                 shell_env = shell_environment.GetEnvironment()
                 # Use the tools lib to determine the correct values for the vars that interest us.
                 vs_vars = locate_tools.QueryVcVariables(
-                    interesting_keys, "amd64", vs_version="vs2019")
+                    interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="vs2019")
                 for (k, v) in vs_vars.items():
-                    if k.upper() == "PATH":
-                        shell_env.insert_path(v)
-                    else:
-                        shell_env.set_shell_var(k, v)
+                    shell_env.set_shell_var(k, v)
 
             # now confirm it exists
             if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("VS2019_PREFIX")):
-- 
2.18.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57012): https://edk2.groups.io/g/devel/message/57012
Mute This Topic: https://groups.io/mt/72845392/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [EXTERNAL] [edk2-devel] [PATCH] BaseTools/WindowsVsToolChain.py: Update toolchain plugin
Posted by Bret Barkelew via groups.io 4 years ago
Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>

- Bret

________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Zhang, Shenglei via groups.io <shenglei.zhang=intel.com@groups.io>
Sent: Monday, April 6, 2020 11:47:37 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Bob Feng <bob.c.feng@intel.com>; Liming Gao <liming.gao@intel.com>
Subject: [EXTERNAL] [edk2-devel] [PATCH] BaseTools/WindowsVsToolChain.py: Update toolchain plugin

REF: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2659&amp;data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cb69f6a990b644ab252d708d7dabf94d6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637218388681928753&amp;sdata=nCRoJjRWBWaeRBkCUsWV7TFwdKGR7770Cq4qFiBkA5U%3D&amp;reserved=0
Allow WindowsVsToolChain Plugin to add libraries and headers
of user defined ARCH for VS2017 and VS2019.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
 .../WindowsVsToolChain/WindowsVsToolChain.py  | 73 ++++++++++++++++---
 1 file changed, 62 insertions(+), 11 deletions(-)

diff --git a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py
index c9279e1c75b5..0fba2c1b5325 100644
--- a/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py
+++ b/BaseTools/Plugin/WindowsVsToolChain/WindowsVsToolChain.py
@@ -13,6 +13,7 @@ import edk2toollib.windows.locate_tools as locate_tools
 from edk2toollib.windows.locate_tools import FindWithVsWhere
 from edk2toolext.environment import shell_environment
 from edk2toolext.environment import version_aggregator
+from edk2toollib.utility_functions import GetHostInfo


 class WindowsVsToolChain(IUefiBuildPlugin):
@@ -26,14 +27,41 @@ class WindowsVsToolChain(IUefiBuildPlugin):
                             "UCRTVersion", "WindowsLibPath", "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
                             "WindowsSDKVersion", "VCToolsInstallDir", "Path"]

-#
+        #
         # VS2017 - Follow VS2017 where there is potential for many versions of the tools.
         # If a specific version is required then the user must set both env variables:
         # VS150INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
         # VS150TOOLVER:      version number for the VC compiler tools
         # VS2017_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
+        # VS2017_HOST:       set the host architecture to use for host tools, and host libs, etc
         if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2017":

+            # check to see if host is configured
+            # HostType for VS2017 should be (defined in tools_def):
+            # x86   == 32bit Intel
+            # x64   == 64bit Intel
+            # arm   == 32bit Arm
+            # arm64 == 64bit Arm
+            #
+            HostType = shell_environment.GetEnvironment().get_shell_var("VS2017_HOST")
+            if HostType is not None:
+                HostType = HostType.lower()
+                self.Logger.info(
+                    f"HOST TYPE defined by environment.  Host Type is {HostType}")
+            else:
+                HostInfo = GetHostInfo()
+                if HostInfo.arch == "x86":
+                    if HostInfo.bit == "32":
+                        HostType = "x86"
+                    elif HostInfo.bit == "64":
+                        HostType = "x64"
+                else:
+                    raise NotImplementedError()
+
+            # VS2017_HOST options are not exactly the same as QueryVcVariables. This translates.
+            VC_HOST_ARCH_TRANSLATOR = {
+                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}
+
             # check to see if full path already configured
             if shell_environment.GetEnvironment().get_shell_var("VS2017_PREFIX") != None:
                 self.Logger.info("VS2017_PREFIX is already set.")
@@ -58,16 +86,14 @@ class WindowsVsToolChain(IUefiBuildPlugin):
                                       "Tools", "MSVC", vc_ver)
                 prefix = prefix + os.path.sep
                 shell_environment.GetEnvironment().set_shell_var("VS2017_PREFIX", prefix)
+                shell_environment.GetEnvironment().set_shell_var("VS2017_HOST", HostType)

                 shell_env = shell_environment.GetEnvironment()
                 # Use the tools lib to determine the correct values for the vars that interest us.
                 vs_vars = locate_tools.QueryVcVariables(
-                    interesting_keys, "amd64", vs_version="vs2017")
+                    interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="vs2017")
                 for (k, v) in vs_vars.items():
-                    if k.upper() == "PATH":
-                        shell_env.insert_path(v)
-                    else:
-                        shell_env.set_shell_var(k, v)
+                    shell_env.set_shell_var(k, v)

             # now confirm it exists
             if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("VS2017_PREFIX")):
@@ -80,8 +106,35 @@ class WindowsVsToolChain(IUefiBuildPlugin):
         # VS160INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
         # VS160TOOLVER:      version number for the VC compiler tools
         # VS2019_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
+        # VS2017_HOST:       set the host architecture to use for host tools, and host libs, etc
         elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019":

+            # check to see if host is configured
+            # HostType for VS2019 should be (defined in tools_def):
+            # x86   == 32bit Intel
+            # x64   == 64bit Intel
+            # arm   == 32bit Arm
+            # arm64 == 64bit Arm
+            #
+            HostType = shell_environment.GetEnvironment().get_shell_var("VS2019_HOST")
+            if HostType is not None:
+                HostType = HostType.lower()
+                self.Logger.info(
+                    f"HOST TYPE defined by environment.  Host Type is {HostType}")
+            else:
+                HostInfo = GetHostInfo()
+                if HostInfo.arch == "x86":
+                    if HostInfo.bit == "32":
+                        HostType = "x86"
+                    elif HostInfo.bit == "64":
+                        HostType = "x64"
+                else:
+                    raise NotImplementedError()
+
+            # VS2019_HOST options are not exactly the same as QueryVcVariables. This translates.
+            VC_HOST_ARCH_TRANSLATOR = {
+                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}
+
             # check to see if full path already configured
             if shell_environment.GetEnvironment().get_shell_var("VS2019_PREFIX") != None:
                 self.Logger.info("VS2019_PREFIX is already set.")
@@ -106,16 +159,14 @@ class WindowsVsToolChain(IUefiBuildPlugin):
                                       "Tools", "MSVC", vc_ver)
                 prefix = prefix + os.path.sep
                 shell_environment.GetEnvironment().set_shell_var("VS2019_PREFIX", prefix)
+                shell_environment.GetEnvironment().set_shell_var("VS2019_HOST", HostType)

                 shell_env = shell_environment.GetEnvironment()
                 # Use the tools lib to determine the correct values for the vars that interest us.
                 vs_vars = locate_tools.QueryVcVariables(
-                    interesting_keys, "amd64", vs_version="vs2019")
+                    interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="vs2019")
                 for (k, v) in vs_vars.items():
-                    if k.upper() == "PATH":
-                        shell_env.insert_path(v)
-                    else:
-                        shell_env.set_shell_var(k, v)
+                    shell_env.set_shell_var(k, v)

             # now confirm it exists
             if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("VS2019_PREFIX")):
--
2.18.0.windows.1





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57030): https://edk2.groups.io/g/devel/message/57030
Mute This Topic: https://groups.io/mt/72860922/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-