Compilation fixes for UWP (#4335)
* Compilation fixes for UWP * More accurate condition * Fix warnings * Format files as vcpkg formats them; pull one change back from vcpkg --------- Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
parent
72f8721e26
commit
243fb4c58d
@ -16,6 +16,7 @@
|
||||
"default-features": false,
|
||||
"version>=": "1.7.0"
|
||||
},
|
||||
"openssl",
|
||||
{
|
||||
"name": "vcpkg-cmake",
|
||||
"host": true
|
||||
@ -23,9 +24,6 @@
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "openssl"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -10,9 +10,11 @@ if(@BUILD_TRANSPORT_CURL@)
|
||||
find_dependency(CURL @CURL_MIN_REQUIRED_VERSION@)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
if(@BUILD_TRANSPORT_WINHTTP@)
|
||||
find_dependency(wil)
|
||||
else()
|
||||
endif()
|
||||
|
||||
if (NOT WIN32)
|
||||
find_dependency(OpenSSL)
|
||||
endif()
|
||||
|
||||
|
||||
@ -22,10 +22,6 @@
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "wil",
|
||||
"platform": "windows"
|
||||
}
|
||||
],
|
||||
"default-features": [
|
||||
@ -71,11 +67,13 @@
|
||||
},
|
||||
"winhttp": {
|
||||
"description": "WinHTTP HTTP transport implementation",
|
||||
"supports": "windows",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "azure-core-cpp",
|
||||
"default-features": false
|
||||
}
|
||||
},
|
||||
"wil"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,6 +154,7 @@ AccessToken AzureCliCredential::GetToken(
|
||||
|
||||
namespace {
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
template <typename> struct UniqueHandleHelper;
|
||||
template <> struct UniqueHandleHelper<HANDLE>
|
||||
{
|
||||
@ -163,6 +164,7 @@ template <> struct UniqueHandleHelper<HANDLE>
|
||||
|
||||
template <typename T>
|
||||
using UniqueHandle = Azure::Core::_internal::UniqueHandle<T, UniqueHandleHelper>;
|
||||
#endif // not UWP
|
||||
#endif
|
||||
|
||||
class ShellProcess;
|
||||
@ -171,10 +173,12 @@ class OutputPipe final {
|
||||
|
||||
private:
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
UniqueHandle<HANDLE> m_writeHandle;
|
||||
UniqueHandle<HANDLE> m_readHandle;
|
||||
OVERLAPPED m_overlapped = {};
|
||||
#else
|
||||
#endif // not UWP
|
||||
#else // not Windows
|
||||
std::vector<int> m_fd;
|
||||
#endif
|
||||
|
||||
@ -195,8 +199,10 @@ public:
|
||||
class ShellProcess final {
|
||||
private:
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
UniqueHandle<HANDLE> m_processHandle;
|
||||
#else
|
||||
#endif // not UWP
|
||||
#else // not Windows
|
||||
std::vector<char*> m_argv;
|
||||
std::vector<char> m_argvValues;
|
||||
|
||||
@ -271,6 +277,7 @@ std::string RunShellCommand(
|
||||
}
|
||||
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
void ThrowIfApiCallFails(BOOL apiResult, std::string const& errMsg)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
@ -283,7 +290,8 @@ void ThrowIfApiCallFails(BOOL apiResult, std::string const& errMsg)
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
#else
|
||||
#endif // not UWP
|
||||
#else // not Windows
|
||||
void ThrowIfApiCallFails(int apiResult, std::string const& errMsg)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
@ -299,6 +307,7 @@ void ThrowIfApiCallFails(int apiResult, std::string const& errMsg)
|
||||
OutputPipe::OutputPipe()
|
||||
{
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
SECURITY_ATTRIBUTES pipeSecurity = {};
|
||||
pipeSecurity.nLength = sizeof(decltype(pipeSecurity));
|
||||
pipeSecurity.bInheritHandle = TRUE;
|
||||
@ -318,7 +327,10 @@ OutputPipe::OutputPipe()
|
||||
ThrowIfApiCallFails(
|
||||
SetHandleInformation(m_readHandle.get(), HANDLE_FLAG_INHERIT, 0),
|
||||
"Cannot ensure the read handle for the output pipe is not inherited");
|
||||
#else
|
||||
#else // UWP
|
||||
throw std::runtime_error("The credential is not supported on UWP.");
|
||||
#endif
|
||||
#else // not Windows
|
||||
m_fd.push_back(-1);
|
||||
m_fd.push_back(-1);
|
||||
|
||||
@ -342,6 +354,7 @@ OutputPipe::~OutputPipe()
|
||||
}
|
||||
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
void AppendToEnvironmentValuesIfNotEmpty(
|
||||
std::vector<CHAR>& environmentValues,
|
||||
std::string const& envVarName,
|
||||
@ -365,7 +378,8 @@ void AppendToEnvironmentValuesIfDefined(
|
||||
AppendToEnvironmentValuesIfNotEmpty(
|
||||
environmentValues, envVarName, Environment::GetVariable(envVarName.c_str()));
|
||||
}
|
||||
#else
|
||||
#endif // not UWP
|
||||
#else // not Windows
|
||||
void AppendToArgvValues(
|
||||
std::vector<char>& argvValues,
|
||||
std::vector<std::remove_reference<decltype(argvValues)>::type::size_type>& argvValuePositions,
|
||||
@ -394,6 +408,7 @@ void EnsureShellExists(std::string const& pathToShell)
|
||||
ShellProcess::ShellProcess(std::string const& command, OutputPipe& outputPipe)
|
||||
{
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
// Start the process.
|
||||
PROCESS_INFORMATION procInfo = {};
|
||||
|
||||
@ -484,7 +499,11 @@ ShellProcess::ShellProcess(std::string const& command, OutputPipe& outputPipe)
|
||||
// We will only be reading the pipe.
|
||||
// So, now that the process is started, we can close write handle on our end.
|
||||
outputPipe.m_writeHandle.reset();
|
||||
#else
|
||||
#else // UWP
|
||||
static_cast<void>(command);
|
||||
static_cast<void>(outputPipe);
|
||||
#endif // UWP
|
||||
#else // not Windows
|
||||
// Form the 'argv' array:
|
||||
// * An array of pointers to non-const C strings (0-terminated).
|
||||
// * Last element is nullptr.
|
||||
@ -587,8 +606,10 @@ void ShellProcess::Finalize()
|
||||
void ShellProcess::Terminate()
|
||||
{
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
static_cast<void>(TerminateProcess(m_processHandle.get(), 0));
|
||||
#else
|
||||
#endif // not UWP
|
||||
#else // not Windows
|
||||
if (m_pid > 0)
|
||||
{
|
||||
static_cast<void>(kill(m_pid, SIGKILL));
|
||||
@ -602,6 +623,7 @@ bool OutputPipe::NonBlockingRead(
|
||||
bool& willHaveMoreData)
|
||||
{
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
|
||||
static_assert(
|
||||
sizeof(std::remove_reference<decltype(buffer)>::type::value_type) == sizeof(CHAR),
|
||||
"buffer elements and CHARs should be of the same size");
|
||||
@ -627,7 +649,13 @@ bool OutputPipe::NonBlockingRead(
|
||||
willHaveMoreData = (GetLastError() != ERROR_BROKEN_PIPE);
|
||||
|
||||
return hadData && bytesRead > 0;
|
||||
#else
|
||||
#else // UWP
|
||||
static_cast<void>(buffer);
|
||||
static_cast<void>(bytesRead);
|
||||
static_cast<void>(willHaveMoreData);
|
||||
throw std::runtime_error("The credential is not supported on UWP.");
|
||||
#endif // UWP
|
||||
#else // not Windows
|
||||
static_assert(
|
||||
sizeof(std::remove_reference<decltype(buffer)>::type::value_type) == sizeof(char),
|
||||
"buffer elements and chars should be of the same size");
|
||||
|
||||
@ -82,7 +82,12 @@ public:
|
||||
};
|
||||
} // namespace
|
||||
|
||||
#if !defined(AZ_PLATFORM_WINDOWS) \
|
||||
|| (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP) // not UWP
|
||||
TEST(AzureCliCredential, Success)
|
||||
#else
|
||||
TEST(AzureCliCredential, NotAvailable)
|
||||
#endif
|
||||
{
|
||||
constexpr auto Token = "{\"accessToken\":\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\","
|
||||
"\"expiresOn\":\"2022-08-24 00:43:08.000000\","
|
||||
@ -93,6 +98,8 @@ TEST(AzureCliCredential, Success)
|
||||
|
||||
TokenRequestContext trc;
|
||||
trc.Scopes.push_back("https://storage.azure.com/.default");
|
||||
#if !defined(AZ_PLATFORM_WINDOWS) \
|
||||
|| (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP) // not UWP
|
||||
auto const token = azCliCred.GetToken(trc, {});
|
||||
|
||||
EXPECT_EQ(token.Token, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
@ -100,8 +107,19 @@ TEST(AzureCliCredential, Success)
|
||||
EXPECT_EQ(
|
||||
token.ExpiresOn,
|
||||
DateTime::Parse("2022-08-24T00:43:08.000000Z", DateTime::DateFormat::Rfc3339));
|
||||
#else // UWP
|
||||
// The credential should throw during GetToken() and not during construction, because it allows
|
||||
// customers to put it into ChainedTokenCredential and successfully use it there without writing
|
||||
// ifdefs for UWP. It is not too late to throw - for example, if Azure CLI is not installed, then
|
||||
// the credential will also find out during GetToken() and not during construction (if we had to
|
||||
// find out during the construction, we'd have to fire up some 'az' command in constructor; again,
|
||||
// that would also make it hard to put the credential into ChainedTokenCredential).
|
||||
EXPECT_THROW(static_cast<void>(azCliCred.GetToken(trc, {})), AuthenticationException);
|
||||
#endif // UWP
|
||||
}
|
||||
|
||||
#if !defined(AZ_PLATFORM_WINDOWS) \
|
||||
|| (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP) // not UWP
|
||||
TEST(AzureCliCredential, Error)
|
||||
{
|
||||
AzureCliTestCredential const azCliCred(
|
||||
@ -308,3 +326,4 @@ TEST(AzureCliCredential, StrictIso8601TimeFormat)
|
||||
token.ExpiresOn,
|
||||
DateTime::Parse("2022-08-24T00:43:08.000000Z", DateTime::DateFormat::Rfc3339));
|
||||
}
|
||||
#endif // not UWP
|
||||
|
||||
@ -16,9 +16,7 @@
|
||||
"default-features": false,
|
||||
"version>=": "1.4.0"
|
||||
},
|
||||
{
|
||||
"name": "openssl"
|
||||
},
|
||||
"openssl",
|
||||
{
|
||||
"name": "vcpkg-cmake",
|
||||
"host": true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user