Add SetEnv and UnSetEnv for environment variable to util (#6884)
* Add SetEnv and UnSetEnv for environment variable to util * Move utils to AzTest * enable for ios and android * fix wrong file path
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
set(FILES
|
||||
../Common/UnixLike/AzTest/ColorizedOutput_UnixLike.cpp
|
||||
../Common/UnixLike/AzTest/Utils_UnixLike.cpp
|
||||
ScopedAutoTempDirectory_Android.cpp
|
||||
Platform_Android.cpp
|
||||
AzTest_Traits_Platform.h
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzTest/Utils.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
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;
|
||||
}
|
||||
} // namespace Test
|
||||
} // namespace AZ
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzTest/Utils.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
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,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzTest/Utils.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
set(FILES
|
||||
../Common/UnixLike/AzTest/ColorizedOutput_UnixLike.cpp
|
||||
../Common/UnixLike/AzTest/ScopedAutoTempDirectory_UnixLike.cpp
|
||||
../Common/UnixLike/AzTest/Utils_UnixLike.cpp
|
||||
Platform_Linux.cpp
|
||||
AzTest_Traits_Platform.h
|
||||
AzTest_Traits_Linux.h
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
set(FILES
|
||||
../Common/UnixLike/AzTest/ColorizedOutput_UnixLike.cpp
|
||||
../Common/UnixLike/AzTest/ScopedAutoTempDirectory_UnixLike.cpp
|
||||
../Common/UnixLike/AzTest/Utils_UnixLike.cpp
|
||||
Platform_Mac.cpp
|
||||
AzTest_Traits_Platform.h
|
||||
AzTest_Traits_Mac.h
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
set(FILES
|
||||
../Common/WinAPI/AzTest/ColorizedOutput_WinAPI.cpp
|
||||
../Common/WinAPI/AzTest/Utils_WinAPI.cpp
|
||||
Platform_Windows.cpp
|
||||
ScopedAutoTempDirectory_Windows.cpp
|
||||
AzTest_Traits_Platform.h
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
set(FILES
|
||||
../Common/UnixLike/AzTest/ColorizedOutput_UnixLike.cpp
|
||||
../Common/Unimplemented/AzTest/ScopedAutoTempDirectory_Unimplemented.cpp
|
||||
../Common/UnixLike/AzTest/Utils_UnixLike.cpp
|
||||
Platform_iOS.cpp
|
||||
AzTest_Traits_Platform.h
|
||||
AzTest_Traits_iOS.h
|
||||
|
||||
@@ -55,6 +55,19 @@ namespace AZ
|
||||
// Returns the path to the engine's root by cdup from the current execution path until engine.txt is found
|
||||
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
|
||||
//! its contents on destruction. This class is only available on host platforms (Windows, Mac, and Linux)
|
||||
class ScopedAutoTempDirectory
|
||||
|
||||
Reference in New Issue
Block a user