Selaa lähdekoodia

Move setenv/unsetenv to azcore and remove aztest dependency from vulkan back end (#7798)

Signed-off-by: moudgils <[email protected]>
moudgils 3 vuotta sitten
vanhempi
commit
04e2c90d97

+ 13 - 0
Code/Framework/AzCore/AzCore/Utils/Utils.h

@@ -114,5 +114,18 @@ namespace AZ
         template<typename Container = AZStd::string>
         template<typename Container = AZStd::string>
         AZ::Outcome<Container, AZStd::string> ReadFile(
         AZ::Outcome<Container, AZStd::string> ReadFile(
             AZStd::string_view filePath, size_t maxFileSize = AZStd::numeric_limits<size_t>::max());
             AZStd::string_view filePath, size_t maxFileSize = AZStd::numeric_limits<size_t>::max());
+
+        //! Create or modify environment variable.
+        //! @param envname The environment variable name
+        //! @param envvalue The environment variable name
+        //! @param overwrite If name does exist in the environment, then its value is changed to value if overwrite is nonzero;
+        //! if overwrite is zero, then the value of name is not changed
+        //! @returns Return true if successful, otherwise false
+        bool SetEnv(const char* envname, const char* envvalue, bool overwrite);
+
+        //! Remove environment variable.
+        //! @param envname The environment variable name
+        //! @returns Return true if successful, otherwise false
+        bool UnsetEnv(const char* envname);
     }
     }
 }
 }

+ 10 - 0
Code/Framework/AzCore/Platform/Common/Unimplemented/AzCore/Utils/Utils_Unimplemented.cpp

@@ -14,4 +14,14 @@ namespace AZ::Utils
     {
     {
         return {};
         return {};
     }
     }
+
+    bool SetEnv([[maybe_unused]] const char* envname, [[maybe_unused]] const char* envvalue, [[maybe_unused]] bool overwrite)
+    {
+        return false;
+    }
+
+    bool UnsetEnv([[maybe_unused]] const char* envname)
+    {
+        return false;
+    }
 } // namespace AZ::Utils
 } // namespace AZ::Utils

+ 10 - 0
Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/Utils/Utils_UnixLike.cpp

@@ -72,4 +72,14 @@ namespace AZ::Utils
         azstrcpy(absolutePath, maxLength, path);
         azstrcpy(absolutePath, maxLength, path);
         return AZ::IO::PathView(absolutePath).IsAbsolute();
         return AZ::IO::PathView(absolutePath).IsAbsolute();
     }
     }
+
+    bool SetEnv(const char* envname, const char* envvalue, bool overwrite)
+    {
+        return setenv(envname, envvalue, overwrite) != -1;
+    }
+
+    bool UnsetEnv(const char* envname)
+    {
+        return unsetenv(envname) != -1;
+    }
 } // namespace AZ::Utils
 } // namespace AZ::Utils

+ 8 - 0
Code/Framework/AzCore/Platform/Common/WinAPI/AzCore/Utils/Utils_WinAPI.cpp

@@ -73,6 +73,14 @@ namespace AZ
             return result != nullptr;
             return result != nullptr;
         }
         }
 
 
+        bool SetEnv(const char* envname, const char* envvalue, [[maybe_unused]] bool overwrite)
+        {
+            return _putenv_s(envname, envvalue);
+        }
 
 
+        bool UnsetEnv(const char* envname)
+        {
+            return SetEnv(envname, "", 1);
+        }
     }
     }
 }
 }

+ 1 - 9
Code/Framework/AzTest/AzTest/Platform/Common/Unimplemented/AzTest/Utils_Unimplemented.cpp

@@ -12,14 +12,6 @@ namespace AZ
 {
 {
     namespace Test
     namespace Test
     {
     {
-        bool SetEnv([[maybe_unused]] const char* envname, [[maybe_unused]] const char* envvalue, [[maybe_unused]] bool overwrite)
-        {
-            return false;
-        }
-
-        bool UnsetEnv([[maybe_unused]] const char* envname)
-        {
-            return false;
-        }
+        //Unimplemented methods will go here
     } // namespace Test
     } // namespace Test
 } // namespace AZ
 } // namespace AZ

+ 0 - 9
Code/Framework/AzTest/AzTest/Platform/Common/UnixLike/AzTest/Utils_UnixLike.cpp

@@ -12,14 +12,5 @@ namespace AZ
 {
 {
     namespace Test
     namespace Test
     {
     {
-        bool SetEnv(const char* envname, const char* envvalue, bool overwrite)
-        {
-            return setenv(envname, envvalue, overwrite) != -1;
-        }
-
-        bool UnsetEnv(const char* envname)
-        {
-            return unsetenv(envname) != -1;
-        }
     }
     }
 }
 }

+ 0 - 9
Code/Framework/AzTest/AzTest/Platform/Common/WinAPI/AzTest/Utils_WinAPI.cpp

@@ -12,14 +12,5 @@ namespace AZ
 {
 {
     namespace Test
     namespace Test
     {
     {
-        bool SetEnv(const char* envname, const char* envvalue, [[maybe_unused]] bool overwrite)
-        {
-            return _putenv_s(envname, envvalue);
-        }
-
-        bool UnsetEnv(const char* envname)
-        {
-            return SetEnv(envname, "", 1);
-        }
     }
     }
 }
 }

+ 0 - 13
Code/Framework/AzTest/AzTest/Utils.h

@@ -55,19 +55,6 @@ namespace AZ
         // Returns the path to the engine's root by cdup from the current execution path until engine.txt is found
         // Returns the path to the engine's root by cdup from the current execution path until engine.txt is found
         AZStd::string GetEngineRootPath();
         AZStd::string GetEngineRootPath();
 
 
-        //! Create or modify environment variable.
-        //! @param envname The environment variable name
-        //! @param envvalue The environment variable name
-        //! @param overwrite If name does exist in the environment, then its value is changed to value if overwrite is nonzero;
-        //! if overwrite is zero, then the value of name is not changed
-        //! @returns Return true if successful, otherwise false
-        bool SetEnv(const char* envname, const char* envvalue, bool overwrite);
-
-        //! Remove environment variable.
-        //! @param envname The environment variable name
-        //! @returns Return true if successful, otherwise false
-        bool UnsetEnv(const char* envname);
-
         //! Provides a scoped object that will create a temporary operating-system specific folder on creation, and delete it and 
         //! Provides a scoped object that will create a temporary operating-system specific folder on creation, and delete it and 
         //! its contents on destruction. This class is only available on host platforms (Windows, Mac, and Linux)
         //! its contents on destruction. This class is only available on host platforms (Windows, Mac, and Linux)
         class ScopedAutoTempDirectory
         class ScopedAutoTempDirectory

+ 3 - 3
Code/Tools/AWSNativeSDKInit/tests/libs/AWSNativeSDKTestManager.cpp

@@ -10,7 +10,7 @@
 #include <AWSNativeSDKTestManager.h>
 #include <AWSNativeSDKTestManager.h>
 
 
 #include <AzCore/Module/Environment.h>
 #include <AzCore/Module/Environment.h>
-#include <AzTest/Utils.h>
+#include <AzCore/Utils/Utils.h>
 
 
 #include <AWSNativeSDKInit/AWSLogSystemInterface.h>
 #include <AWSNativeSDKInit/AWSLogSystemInterface.h>
 #include <aws/core/Aws.h>
 #include <aws/core/Aws.h>
@@ -22,7 +22,7 @@ namespace AWSNativeSDKTestLibs
 
 
     AWSNativeSDKTestManager::AWSNativeSDKTestManager()
     AWSNativeSDKTestManager::AWSNativeSDKTestManager()
     {
     {
-        AZ::Test::SetEnv("AWS_DEFAULT_REGION", "us-east-1", 1);
+        AZ::Utils::SetEnv("AWS_DEFAULT_REGION", "us-east-1", 1);
         m_awsSDKOptions.memoryManagementOptions.memoryManager = &m_memoryManager;
         m_awsSDKOptions.memoryManagementOptions.memoryManager = &m_memoryManager;
         Aws::InitAPI(m_awsSDKOptions);
         Aws::InitAPI(m_awsSDKOptions);
     }
     }
@@ -30,7 +30,7 @@ namespace AWSNativeSDKTestLibs
     AWSNativeSDKTestManager::~AWSNativeSDKTestManager()
     AWSNativeSDKTestManager::~AWSNativeSDKTestManager()
     {
     {
         Aws::ShutdownAPI(m_awsSDKOptions);
         Aws::ShutdownAPI(m_awsSDKOptions);
-        AZ::Test::UnsetEnv("AWS_DEFAULT_REGION");
+        AZ::Utils::UnsetEnv("AWS_DEFAULT_REGION");
     }
     }
 
 
     void AWSNativeSDKTestManager::Init()
     void AWSNativeSDKTestManager::Init()

+ 0 - 1
Gems/Atom/RHI/Vulkan/Code/CMakeLists.txt

@@ -108,7 +108,6 @@ ly_add_target(
     BUILD_DEPENDENCIES
     BUILD_DEPENDENCIES
         PUBLIC
         PUBLIC
             AZ::AzCore
             AZ::AzCore
-            AZ::AzTest
             AZ::AzFramework
             AZ::AzFramework
             Gem::Atom_RHI.Reflect
             Gem::Atom_RHI.Reflect
             Gem::Atom_RHI_Vulkan.Reflect
             Gem::Atom_RHI_Vulkan.Reflect

+ 5 - 2
Gems/Atom/RHI/Vulkan/Code/Source/RHI/Instance.cpp

@@ -9,7 +9,7 @@
 #include <RHI/Instance.h>
 #include <RHI/Instance.h>
 #include <Atom/RHI.Loader/FunctionLoader.h>
 #include <Atom/RHI.Loader/FunctionLoader.h>
 #include <AzCore/Debug/Trace.h>
 #include <AzCore/Debug/Trace.h>
-#include <AzTest/Utils.h>
+#include <AzCore/Utils/Utils.h>
 
 
 namespace AZ
 namespace AZ
 {
 {
@@ -49,8 +49,11 @@ namespace AZ
             m_descriptor = descriptor;
             m_descriptor = descriptor;
             if (GetValidationMode() != RHI::ValidationMode::Disabled)
             if (GetValidationMode() != RHI::ValidationMode::Disabled)
             {
             {
+                char exeDirectory[AZ_MAX_PATH_LEN];
+                AZ::Utils::GetExecutableDirectory(exeDirectory, AZ_ARRAY_SIZE(exeDirectory));
+
                 //This env var (VK_LAYER_PATH) is used by the drivers to look for VkLayer_khronos_validation.dll
                 //This env var (VK_LAYER_PATH) is used by the drivers to look for VkLayer_khronos_validation.dll
-                AZ::Test::SetEnv("VK_LAYER_PATH", AZ::Test::GetCurrentExecutablePath().c_str(), 1);
+                AZ::Utils::SetEnv("VK_LAYER_PATH", exeDirectory, 1);
 
 
                 RawStringList validationLayers = Debug::GetValidationLayers();
                 RawStringList validationLayers = Debug::GetValidationLayers();
                 m_descriptor.m_optionalLayers.insert(m_descriptor.m_requiredLayers.end(), validationLayers.begin(), validationLayers.end());
                 m_descriptor.m_optionalLayers.insert(m_descriptor.m_requiredLayers.end(), validationLayers.begin(), validationLayers.end());