From cd36753d76636baebd341973fca8ccdf2149b16a Mon Sep 17 00:00:00 2001 From: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Date: Thu, 29 Apr 2021 00:34:24 +0000 Subject: [PATCH] PackageVersion made constexpr and moved to src/package_version.hpp (#2166) --- cmake-modules/AzureVcpkg.cmake | 2 +- cmake-modules/AzureVersion.cmake | 4 +- eng/scripts/SdkVersion-Common.ps1 | 6 +- eng/scripts/Update-PkgVersion.ps1 | 6 +- sdk/core/azure-core/CMakeLists.txt | 10 +- .../src/environment_log_level_listener.cpp | 2 +- sdk/core/azure-core/src/logger.cpp | 2 +- .../src/private/curl_connection.hpp | 200 +++++++++ .../src/private/curl_connection_pool.hpp | 127 ++++++ .../azure-core/src/private/curl_session.hpp | 418 ++++++++++++++++++ .../environment_log_level_listener.hpp} | 0 .../private/package_version.hpp} | 30 +- sdk/core/azure-core/src/version.cpp | 29 -- .../test/ut/azure_libcurl_core_main.cpp | 6 +- .../test/ut/curl_connection_pool.cpp | 8 +- sdk/core/azure-core/test/ut/curl_options.cpp | 4 +- sdk/core/azure-core/test/ut/curl_session.hpp | 2 +- .../azure-core/test/ut/curl_session_test.cpp | 4 +- sdk/identity/azure-identity/CMakeLists.txt | 5 +- .../private/package_version.hpp} | 30 +- sdk/identity/azure-identity/src/version.cpp | 29 -- .../CMakeLists.txt | 4 +- .../inc/azure/keyvault/common/version.hpp | 40 -- .../src/private/package_version.hpp | 60 +++ .../CMakeLists.txt | 4 +- .../inc/azure/keyvault/key_vault.hpp | 1 - .../inc/azure/keyvault/keys/version.hpp | 40 -- .../src/private/package_version.hpp | 60 +++ .../azure-storage-blobs/CMakeLists.txt | 4 +- .../inc/azure/storage/blobs/version.hpp | 61 --- .../azure-storage-blobs/src/blob_client.cpp | 5 +- .../src/blob_container_client.cpp | 3 +- .../src/blob_service_client.cpp | 2 +- .../src/private/package_version.hpp | 59 +++ .../azure-storage-common/CMakeLists.txt | 4 +- .../inc/azure/storage/common/version.hpp | 61 --- .../src/private/package_version.hpp | 61 +++ .../CMakeLists.txt | 4 +- .../azure/storage/files/datalake/version.hpp | 61 --- .../src/datalake_directory_client.cpp | 1 - .../src/datalake_file_client.cpp | 1 - .../src/datalake_file_system_client.cpp | 3 +- .../src/datalake_path_client.cpp | 3 +- .../src/datalake_service_client.cpp | 3 +- .../src/private/package_version.hpp | 60 +++ .../azure-storage-files-shares/CMakeLists.txt | 4 +- .../azure/storage/files/shares/version.hpp | 61 --- .../src/private/package_version.hpp | 59 +++ .../src/share_client.cpp | 3 +- .../src/share_directory_client.cpp | 3 +- .../src/share_file_client.cpp | 3 +- .../src/share_service_client.cpp | 3 +- sdk/template/azure-template/CMakeLists.txt | 5 +- .../azure-template/inc/azure/template.hpp | 1 - .../inc/azure/template/template_client.hpp | 2 +- .../private/package_version.hpp} | 35 +- .../azure-template/src/template_client.cpp | 5 +- sdk/template/azure-template/src/version.cpp | 28 -- 58 files changed, 1227 insertions(+), 514 deletions(-) create mode 100644 sdk/core/azure-core/src/private/curl_connection.hpp create mode 100644 sdk/core/azure-core/src/private/curl_connection_pool.hpp create mode 100644 sdk/core/azure-core/src/private/curl_session.hpp rename sdk/core/azure-core/src/{environment_log_level_listener_private.hpp => private/environment_log_level_listener.hpp} (100%) rename sdk/core/azure-core/{inc/azure/core/version.hpp => src/private/package_version.hpp} (56%) delete mode 100644 sdk/core/azure-core/src/version.cpp rename sdk/identity/azure-identity/{inc/azure/identity/version.hpp => src/private/package_version.hpp} (55%) delete mode 100644 sdk/identity/azure-identity/src/version.cpp delete mode 100644 sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/version.hpp create mode 100644 sdk/keyvault/azure-security-keyvault-common/src/private/package_version.hpp delete mode 100644 sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/version.hpp create mode 100644 sdk/keyvault/azure-security-keyvault-keys/src/private/package_version.hpp delete mode 100644 sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/version.hpp create mode 100644 sdk/storage/azure-storage-blobs/src/private/package_version.hpp delete mode 100644 sdk/storage/azure-storage-common/inc/azure/storage/common/version.hpp create mode 100644 sdk/storage/azure-storage-common/src/private/package_version.hpp delete mode 100644 sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/version.hpp create mode 100644 sdk/storage/azure-storage-files-datalake/src/private/package_version.hpp delete mode 100644 sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/version.hpp create mode 100644 sdk/storage/azure-storage-files-shares/src/private/package_version.hpp rename sdk/template/azure-template/{inc/azure/template/version.hpp => src/private/package_version.hpp} (52%) delete mode 100644 sdk/template/azure-template/src/version.cpp diff --git a/cmake-modules/AzureVcpkg.cmake b/cmake-modules/AzureVcpkg.cmake index dd9a166cb..14d4b7fc4 100644 --- a/cmake-modules/AzureVcpkg.cmake +++ b/cmake-modules/AzureVcpkg.cmake @@ -124,7 +124,7 @@ macro(az_vcpkg_export targetName macroNamePart dllImportExportHeaderPath) # Produce version file. write_basic_package_version_file( "${targetName}-cppConfigVersion.cmake" - VERSION ${AZ_LIBRARY_VERSION} # the version that we extracted from version.hpp + VERSION ${AZ_LIBRARY_VERSION} # the version that we extracted from package_version.hpp COMPATIBILITY SameMajorVersion ) diff --git a/cmake-modules/AzureVersion.cmake b/cmake-modules/AzureVersion.cmake index f9b11b02e..603b7c1f5 100644 --- a/cmake-modules/AzureVersion.cmake +++ b/cmake-modules/AzureVersion.cmake @@ -2,8 +2,8 @@ # SPDX-License-Identifier: MIT # # Sets ${AZ_LIBRARY_VERSION} in the parent context with the version value -# constructed from version.hpp. The version.hpp must follow the example in -# templates for version information to parse correctly. +# constructed from package_version.hpp. The package_version.hpp must follow +# the example in templates for version information to parse correctly. function(get_az_version VERSION_HPP_FILE) if(NOT EXISTS ${VERSION_HPP_FILE}) diff --git a/eng/scripts/SdkVersion-Common.ps1 b/eng/scripts/SdkVersion-Common.ps1 index 6e9efbf81..db5690321 100644 --- a/eng/scripts/SdkVersion-Common.ps1 +++ b/eng/scripts/SdkVersion-Common.ps1 @@ -4,11 +4,11 @@ $RepoRoot = "${PSScriptRoot}/../.." $VersionRegex = '(#define AZURE_\w+_VERSION_MAJOR )(?[0-9]+)(\s+#define AZURE_\w+_VERSION_MINOR )(?[0-9]+)(\s+#define AZURE_\w+_VERSION_PATCH )(?[0-9]+)(\s+#define AZURE_\w+_VERSION_PRERELEASE )"(?[a-zA-Z0-9.]*)"'; function Get-VersionHppLocaiton ($ServiceDirectory, $PackageName) { - $versionHppLocation = Get-ChildItem version.hpp -Path "$RepoRoot/sdk/$ServiceDirectory/$PackageName" -Recurse - Write-Verbose "version.hpp location: $versionHppLocation" + $versionHppLocation = Get-ChildItem package_version.hpp -Path "$RepoRoot/sdk/$ServiceDirectory/$PackageName" -Recurse + Write-Verbose "package_version.hpp location: $versionHppLocation" if (!$versionHppLocation) { - Write-Warning "Could not locate version.hpp file in sdk/$ServiceDirectory/$PackageName" + Write-Warning "Could not locate package_version.hpp file in sdk/$ServiceDirectory/$PackageName" } return $versionHppLocation diff --git a/eng/scripts/Update-PkgVersion.ps1 b/eng/scripts/Update-PkgVersion.ps1 index 11421cb7e..af2669b71 100644 --- a/eng/scripts/Update-PkgVersion.ps1 +++ b/eng/scripts/Update-PkgVersion.ps1 @@ -6,11 +6,11 @@ Bumps up package versions after release The root of the repo (defaults to ${PSScriptRoot}/..) .PARAMETER ServiceDirectory -The service directory under /sdk/ used to find version.hpp +The service directory under /sdk/ used to find package_version.hpp .PARAMETER PackageName The package name under /sdk/ used to find -version.hpp +package_version.hpp .PARAMETER NewVersionString New version string to use. Must follow SemVer conventions. @@ -48,7 +48,7 @@ function Update-Version( exit 1 } - Write-Verbose "Saving version.hpp file..." + Write-Verbose "Saving package_version.hpp file..." $versionHppContent = Get-Content $VersionHppLocation -Raw if ($SemVer.IsPrerelease) { diff --git a/sdk/core/azure-core/CMakeLists.txt b/sdk/core/azure-core/CMakeLists.txt index 397a4746b..3a6c37f2c 100644 --- a/sdk/core/azure-core/CMakeLists.txt +++ b/sdk/core/azure-core/CMakeLists.txt @@ -81,7 +81,6 @@ set( inc/azure/core/response.hpp inc/azure/core/url.hpp inc/azure/core/uuid.hpp - inc/azure/core/version.hpp inc/azure/core.hpp ) @@ -102,16 +101,19 @@ set( src/http/url.cpp src/io/body_stream.cpp src/io/random_access_file_body_stream.cpp + src/private/curl_connection.hpp + src/private/curl_connection_pool.hpp + src/private/curl_session.hpp + src/private/environment_log_level_listener.hpp + src/private/package_version.hpp src/base64.cpp src/context.cpp src/datetime.cpp src/environment_log_level_listener.cpp - src/environment_log_level_listener_private.hpp src/exception.cpp src/logger.cpp src/operation_status.cpp src/strings.cpp - src/version.cpp ) add_library(azure-core ${AZURE_CORE_HEADER} ${AZURE_CORE_SOURCE}) @@ -145,7 +147,7 @@ if(BUILD_TRANSPORT_WINHTTP) target_link_libraries(azure-core PRIVATE winhttp) endif() -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/core/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-core ${AZ_LIBRARY_VERSION}) az_vcpkg_export( diff --git a/sdk/core/azure-core/src/environment_log_level_listener.cpp b/sdk/core/azure-core/src/environment_log_level_listener.cpp index 9da18239a..1ccef1abb 100644 --- a/sdk/core/azure-core/src/environment_log_level_listener.cpp +++ b/sdk/core/azure-core/src/environment_log_level_listener.cpp @@ -17,7 +17,7 @@ #if (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP) // See azure/core/platform.hpp // for explanation. -#include "environment_log_level_listener_private.hpp" +#include "private/environment_log_level_listener.hpp" #include "azure/core/datetime.hpp" #include "azure/core/internal/strings.hpp" diff --git a/sdk/core/azure-core/src/logger.cpp b/sdk/core/azure-core/src/logger.cpp index 9f9267993..fc6db11dd 100644 --- a/sdk/core/azure-core/src/logger.cpp +++ b/sdk/core/azure-core/src/logger.cpp @@ -7,7 +7,7 @@ #include #include -#include "environment_log_level_listener_private.hpp" +#include "private/environment_log_level_listener.hpp" using namespace Azure::Core::Diagnostics; using namespace Azure::Core::Diagnostics::_internal; diff --git a/sdk/core/azure-core/src/private/curl_connection.hpp b/sdk/core/azure-core/src/private/curl_connection.hpp new file mode 100644 index 000000000..27463cf8e --- /dev/null +++ b/sdk/core/azure-core/src/private/curl_connection.hpp @@ -0,0 +1,200 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief The libcurl connection keeps the curl handle and performs the data transfer to the + * network. + */ + +#pragma once + +#include "azure/core/http/http.hpp" + +#include +#include +#include + +namespace Azure { namespace Core { namespace Http { + + namespace _detail { + // libcurl CURL_MAX_WRITE_SIZE is 64k. Using same value for default uploading chunk size. + // This can be customizable in the HttpRequest + constexpr static int64_t DefaultUploadChunkSize = 1024 * 64; + constexpr static auto DefaultLibcurlReaderSize = 1024; + // Run time error template + constexpr static const char* DefaultFailedToGetNewConnectionTemplate + = "Fail to get a new connection for: "; + constexpr static int DefaultMaxOpenNewConnectionIntentsAllowed = 10; + // After 3 connections are received from the pool and failed to send a request, the next + // connections would ask the pool to be clean and spawn new connection. + constexpr static int RequestPoolResetAfterConnectionFailed = 3; + // 90 sec -> cleaner wait time before next clean routine + constexpr static int DefaultCleanerIntervalMilliseconds = 1000 * 90; + // 60 sec -> expired connection is when it waits for 60 sec or more and it's not re-used + constexpr static int DefaultConnectionExpiredMilliseconds = 1000 * 60; + // Define the maximun allowed connections per host-index in the pool. If this number is reached + // for the host-index, next connections trying to be added to the pool will be ignored. + constexpr static size_t MaxConnectionsPerIndex = 1024; + } // namespace _detail + + /** + * @brief Interface for the connection to the network with Curl. + * + * @remark This interface enables to mock the communication to the network with any behavior for + * testing. + * + */ + class CurlNetworkConnection { + protected: + bool m_isShutDown = false; + + public: + /** + * @brief Allow derived classes calling a destructor. + * + */ + virtual ~CurlNetworkConnection() = default; + + /** + * @brief Get the Connection Properties Key object + * + */ + virtual std::string const& GetConnectionKey() const = 0; + + /** + * @brief Update last usage time for the connection. + */ + virtual void UpdateLastUsageTime() = 0; + + /** + * @brief Checks whether this CURL connection is expired. + */ + virtual bool IsExpired() = 0; + + /** + * @brief This function is used when working with streams to pull more data from the wire. + * Function will try to keep pulling data from socket until the buffer is all written or until + * there is no more data to get from the socket. + * + */ + virtual int64_t ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Context const& context) = 0; + + /** + * @brief This method will use libcurl socket to write all the bytes from buffer. + * + */ + virtual CURLcode SendBuffer(uint8_t const* buffer, size_t bufferSize, Context const& context) + = 0; + + /** + * @brief Set the connection into an invalid and unusable state. + * + * @remark A connection won't be returned to the connection pool if it was shut it down. + * + */ + virtual void Shutdown() { m_isShutDown = true; }; + + /** + * @brief Check if the the connection was shut it down. + * + * @return `true` is the connection was shut it down. + */ + bool IsShutdown() const { return m_isShutDown; }; + }; + + /** + * @brief CURL HTTP connection. + */ + class CurlConnection : public CurlNetworkConnection { + private: + CURL* m_handle; + curl_socket_t m_curlSocket; + std::chrono::steady_clock::time_point m_lastUseTime; + std::string m_connectionKey; + + public: + /** + * @Brief Construct CURL HTTP connection. + * + * @param host HTTP connection host name. + */ + CurlConnection(CURL* handle, std::string connectionPropertiesKey) + : m_handle(handle), m_connectionKey(std::move(connectionPropertiesKey)) + { + // Get the socket that libcurl is using from handle. Will use this to wait while + // reading/writing + // into wire +#if defined(_MSC_VER) +#pragma warning(push) +// C26812: The enum type 'CURLcode' is un-scoped. Prefer 'enum class' over 'enum' (Enum.3) +#pragma warning(disable : 26812) +#endif + auto result = curl_easy_getinfo(m_handle, CURLINFO_ACTIVESOCKET, &m_curlSocket); +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + if (result != CURLE_OK) + { + throw Http::TransportException( + "Broken connection. Couldn't get the active sockect for it." + + std::string(curl_easy_strerror(result))); + } + } + + /** + * @brief Destructor. + * @details Cleans up CURL (invokes `curl_easy_cleanup()`). + */ + ~CurlConnection() override { curl_easy_cleanup(this->m_handle); } + + std::string const& GetConnectionKey() const override { return this->m_connectionKey; } + + /** + * @brief Update last usage time for the connection. + */ + void UpdateLastUsageTime() override + { + this->m_lastUseTime = std::chrono::steady_clock::now(); + } + + /** + * @brief Checks whether this CURL connection is expired. + * @return `true` if this connection is considered expired, `false` otherwise. + */ + bool IsExpired() override + { + auto connectionOnWaitingTimeMs = std::chrono::duration_cast( + std::chrono::steady_clock::now() - this->m_lastUseTime); + return connectionOnWaitingTimeMs.count() >= _detail::DefaultConnectionExpiredMilliseconds; + } + + /** + * @brief This function is used when working with streams to pull more data from the wire. + * Function will try to keep pulling data from socket until the buffer is all written or until + * there is no more data to get from the socket. + * + * @param context #Azure::Core::Context so that operation can be cancelled. + * @param buffer ptr to buffer where to copy bytes from socket. + * @param bufferSize size of the buffer and the requested bytes to be pulled from wire. + * @return return the numbers of bytes pulled from socket. It can be less than what it was + * requested. + */ + int64_t ReadFromSocket(uint8_t* buffer, int64_t bufferSize, Context const& context) override; + + /** + * @brief This method will use libcurl socket to write all the bytes from buffer. + * + * @remarks Hardcoded timeout is used in case a socket stop responding. + * + * @param context #Azure::Core::Context so that operation can be cancelled. + * @param buffer ptr to the data to be sent to wire. + * @param bufferSize size of the buffer to send. + * @return CURL_OK when response is sent successfully. + */ + CURLcode SendBuffer(uint8_t const* buffer, size_t bufferSize, Context const& context) + override; + + void Shutdown() override; + }; +}}} // namespace Azure::Core::Http diff --git a/sdk/core/azure-core/src/private/curl_connection_pool.hpp b/sdk/core/azure-core/src/private/curl_connection_pool.hpp new file mode 100644 index 000000000..5de00e460 --- /dev/null +++ b/sdk/core/azure-core/src/private/curl_connection_pool.hpp @@ -0,0 +1,127 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief The curl connection pool provides the utilities for creating a new curl connection and to + * keep a pool of connections to be re-used. + */ + +#pragma once + +#include "azure/core/dll_import_export.hpp" +#include "azure/core/http/http.hpp" + +#include "private/curl_connection.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(TESTING_BUILD) +// Define the class name that reads from ConnectionPool private members +namespace Azure { namespace Core { namespace Test { + class CurlConnectionPool_connectionPoolTest_Test; + class CurlConnectionPool_uniquePort_Test; +}}} // namespace Azure::Core::Test +#endif + +namespace Azure { namespace Core { namespace Http { namespace _detail { + + /** + * @brief CURL HTTP connection pool makes it possible to re-use one curl connection to perform + * more than one request. Use this component when connections are not re-used by default. + * + * This pool offers static methods and it is allocated statically. There can be only one + * connection pool per application. + */ + class CurlConnectionPool { +#if defined(TESTING_BUILD) + // Give access to private to this tests class + friend class Azure::Core::Test::CurlConnectionPool_connectionPoolTest_Test; + friend class Azure::Core::Test::CurlConnectionPool_uniquePort_Test; +#endif + + public: + ~CurlConnectionPool() + { + using namespace Azure::Core::Http::_detail; + if (m_cleanThread.joinable()) + { + { + std::unique_lock lock(ConnectionPoolMutex); + // Remove all connections + g_curlConnectionPool.ConnectionPoolIndex.clear(); + } + // Signal clean thread to wake up + ConditionalVariableForCleanThread.notify_one(); + // join thread + m_cleanThread.join(); + } + curl_global_cleanup(); + } + + /** + * @brief Finds a connection to be re-used from the connection pool. + * @remark If there is not any available connection, a new connection is created. + * + * @param request HTTP request to get #Azure::Core::Http::CurlNetworkConnection for. + * @param options The connection settings which includes host name and libcurl handle specific + * configuration. + * @param resetPool Request the pool to remove all current connections for the provided + * options to force the creation of a new connection. + * + * @return #Azure::Core::Http::CurlNetworkConnection to use. + */ + std::unique_ptr ExtractOrCreateCurlConnection( + Request& request, + CurlTransportOptions const& options, + bool resetPool = false); + + /** + * @brief Moves a connection back to the pool to be re-used. + * + * @param connection CURL HTTP connection to add to the pool. + * @param lastStatusCode The most recent HTTP status code received from the \p connection. + */ + void MoveConnectionBackToPool( + std::unique_ptr connection, + HttpStatusCode lastStatusCode); + + /** + * @brief Keeps a unique key for each host and creates a connection pool for each key. + * + * @details This way getting a connection for a specific host can be done in O(1) instead of + * looping a single connection list to find the first connection for the required host. + * + * @remark There might be multiple connections for each host. + */ + std::map>> ConnectionPoolIndex; + + std::mutex ConnectionPoolMutex; + + // This is used to put the cleaning pool thread to sleep and yet to be able to wake it if the + // application finishes. + std::condition_variable ConditionalVariableForCleanThread; + + AZ_CORE_DLLEXPORT static Azure::Core::Http::_detail::CurlConnectionPool g_curlConnectionPool; + + bool IsCleanThreadRunning = false; + + private: + // private constructor to keep this as singleton. + CurlConnectionPool() { curl_global_init(CURL_GLOBAL_ALL); } + + // Makes possible to know the number of current connections in the connection pool for an + // index + int64_t ConnectionsOnPool(std::string const& host) { return ConnectionPoolIndex[host].size(); }; + + std::thread m_cleanThread; + }; + +}}}} // namespace Azure::Core::Http::_detail diff --git a/sdk/core/azure-core/src/private/curl_session.hpp b/sdk/core/azure-core/src/private/curl_session.hpp new file mode 100644 index 000000000..81e145fc6 --- /dev/null +++ b/sdk/core/azure-core/src/private/curl_session.hpp @@ -0,0 +1,418 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief The curl session consumes a curl connection to perform a request with it and start + * streaming the response. + * + * @remark The curl session is a body stream derived class. + */ + +#pragma once + +#include "azure/core/http/http.hpp" + +#include "private/curl_connection.hpp" +#include "private/curl_connection_pool.hpp" + +#include +#include + +#ifdef TESTING_BUILD +// Define the class name that reads from ConnectionPool private members +namespace Azure { namespace Core { namespace Test { + class CurlConnectionPool_connectionPoolTest_Test; +}}} // namespace Azure::Core::Test +#endif + +namespace Azure { namespace Core { namespace Http { + + /** + * @brief Stateful component that controls sending an HTTP Request with libcurl over the wire. + * + * @remark This component does not use the classic libcurl easy interface to send and receive + * bytes from the network using callbacks. Instead, `CurlSession` supports working with the custom + * HTTP protocol option from libcurl to manually upload and download bytes from the network socket + * using curl_easy_send() and curl_easy_recv(). + * + * @remarks This component is expected to be used by an HTTP Transporter to ensure that + * transporter to be reusable in multiple pipelines while every call to network is unique. + */ + class CurlSession : public Azure::Core::IO::BodyStream { +#ifdef TESTING_BUILD + // Give access to private to this tests class + friend class Azure::Core::Test::CurlConnectionPool_connectionPoolTest_Test; +#endif + private: + /** + * @brief Read one expected byte and throw if it is different than the \p expected + * + */ + void ReadExpected(uint8_t expected, Context const& context); + + /** + * @brief Read `\\r\\n` from internal buffer or from the wire. + * + * @remark throw if `\\r\\n` are not the next data read. + */ + void ReadCRLF(Context const& context); + + /** + * @brief This is used to set the current state of a session. + * + * @remark The session needs to know what's the state on it when an exception occurs so the + * connection is not moved back to the connection pool. When a new request is going to be sent, + * the session will be in `PERFORM` until the request has been uploaded and a response code is + * received from the server. At that point the state will change to `STREAMING`. + * If there is any error before changing the state, the connection need to be cleaned up. + * + */ + enum class SessionState + { + PERFORM, + STREAMING + }; + + /* + * Enum used by ResponseBufferParser to control the parsing internal state while building + * the HTTP RawResponse + * + */ + enum class ResponseParserState + { + StatusLine, + Headers, + EndOfHeaders, + }; + + /** + * @brief stateful component used to read and parse a buffer to construct a valid HTTP + * RawResponse. + * + * @remark It uses an internal string as a buffer to accumulate a response token (version, code, + * header, etc.) until the next delimiter is found. Then it uses this string to keep building + * the HTTP RawResponse. + * + * @remark Only status line and headers are parsed and built. Body is ignored by this + * component. A libcurl session will use this component to build and return the HTTP + * RawResponse with a body stream to the pipeline. + */ + class ResponseBufferParser { + private: + /** + * @brief Controls what the parser is expecting during the reading process + * + */ + ResponseParserState state = ResponseParserState::StatusLine; + /** + * @brief Unique ptr to a response. Parser will create an Initial-valid HTTP RawResponse and + * then it will append headers to it. This response is moved to a different owner once + * parsing is completed. + * + */ + std::unique_ptr m_response; + /** + * @brief Indicates if parser has found the end of the headers and there is nothing left for + * the HTTP RawResponse. + * + */ + bool m_parseCompleted = false; + + bool m_delimiterStartInPrevPosition = false; + + /** + * @brief This buffer is used when the parsed buffer doesn't contain a completed token. The + * content from the buffer will be appended to this buffer. Once that a delimiter is found, + * the token for the HTTP RawResponse is taken from this internal sting if it contains data. + * + * @remark This buffer allows a libcurl session to use any size of buffer to read from a + * socket while constructing an initial valid HTTP RawResponse. No matter if the response + * from wire contains hundreds of headers, we can use only one fixed size buffer to parse it + * all. + * + */ + std::string m_internalBuffer; + + /** + * @brief This method is invoked by the Parsing process if the internal state is set to + * status code. Function will get the status-line expected tokens until finding the end of + * status line delimiter. + * + * @remark When the end of status line delimiter is found, this method will create the HTTP + * RawResponse. The HTTP RawResponse is constructed by default with body type as Stream. + * + * @param buffer Points to a memory address with all or some part of a HTTP status line. + * @param bufferSize Indicates the size of the buffer. + * @return Returns the index of the last parsed position from buffer. + */ + int64_t BuildStatusCode(uint8_t const* const buffer, int64_t const bufferSize); + + /** + * @brief This method is invoked by the Parsing process if the internal state is set to + * headers. Function will keep adding headers to the HTTP RawResponse created before while + * parsing an status line. + * + * @param buffer Points to a memory address with all or some part of a HTTP header. + * @param bufferSize Indicates the size of the buffer. + * @return Returns the index of the last parsed position from buffer. When the returned + * value is smaller than the body size, means there is part of the body response in the + * buffer. + */ + int64_t BuildHeader(uint8_t const* const buffer, int64_t const bufferSize); + + public: + /** + * @brief Construct a new RawResponse Buffer Parser object. + * + */ + ResponseBufferParser() {} + + /** + * @brief Parses the content of a buffer to construct a valid HTTP RawResponse. This method + * is expected to be called over and over until it returns 0, indicating there is nothing + * more to parse to build the HTTP RawResponse. + * + * @param buffer points to a memory area that contains, all or some part of an HTTP + * response. + * @param bufferSize Indicates the size of the buffer. + * @return Returns the index of the last parsed position. Returning a 0 means nothing was + * parsed and it is likely that the HTTP RawResponse is completed. Returning the same value + * as the buffer size means all buffer was parsed and the HTTP might be completed or not. + * Returning a value smaller than the buffer size will likely indicate that the HTTP + * RawResponse is completed and that the rest of the buffer contains part of the response + * body. + */ + int64_t Parse(uint8_t const* const buffer, int64_t const bufferSize); + + /** + * @brief Indicates when the parser has completed parsing and building the HTTP RawResponse. + * + * @return `true` if parsing is completed. Otherwise `false`. + */ + bool IsParseCompleted() const { return m_parseCompleted; } + + /** + * @brief Moves the internal response to a different owner. + * + * @return Will move the response only if parsing is completed and if the HTTP RawResponse + * was not moved before. + */ + std::unique_ptr ExtractResponse() + { + if (m_parseCompleted && m_response != nullptr) + { + return std::move(m_response); + } + return nullptr; // parse is not completed or response has been moved already. + } + }; + + /** + * @brief The current state of the session. + * + * @remark The state of the session is used to determine if a connection can be moved back to + * the connection pool or not. A connection can be re-used only when the session state is + * `STREAMING` and the response has been read completely. + * + */ + SessionState m_sessionState = SessionState::PERFORM; + + std::unique_ptr m_connection; + + /** + * @brief unique ptr for the HTTP RawResponse. The session is responsable for creating the + * response once that an HTTP status line is received. + * + */ + std::unique_ptr m_response; + + /** + * @brief The HTTP Request for to be used by the session. + * + */ + Request& m_request; + + /** + * @brief Control field to handle the case when part of HTTP response body was copied to the + * inner buffer. When a libcurl stream tries to read part of the body, this field will help to + * decide how much data to take from the inner buffer before pulling more data from network. + * + */ + int64_t m_bodyStartInBuffer = -1; + + /** + * @brief Control field to handle the number of bytes containing relevant data within the + * internal buffer. This is because internal buffer can be set to be size N but after writing + * from wire into it, it can be holding less then N bytes. + * + */ + int64_t m_innerBufferSize = _detail::DefaultLibcurlReaderSize; + + bool m_isChunkedResponseType = false; + + /** + * @brief This is a copy of the value of an HTTP response header `content-length`. The value + * is received as string and parsed to size_t. This field avoid parsing the string header + * every time from HTTP RawResponse. + * + * @remark This value is also used to avoid trying to read more data from network than what we + * are expecting to. + * + */ + int64_t m_contentLength = 0; + + /** + * @brief For chunked responses, this field knows the size of the current chuck size server + * will de sending + * + */ + int64_t m_chunkSize = 0; + + int64_t m_sessionTotalRead = 0; + + /** + * @brief Internal buffer from a session used to read bytes from a socket. This buffer is only + * used while constructing an HTTP RawResponse without adding a body to it. Customers would + * provide their own buffer to copy from socket when reading the HTTP body using streams. + * + */ + uint8_t m_readBuffer[_detail::DefaultLibcurlReaderSize] + = {0}; // to work with libcurl custom read. + + /** + * @brief Function used when working with Streams to manually write from the HTTP Request to + * the wire. + * + * @param context #Azure::Core::Context so that operation can be cancelled. + * + * @return CURL_OK when response is sent successfully. + */ + CURLcode SendRawHttp(Context const& context); + + /** + * @brief Upload body. + * + * @param context #Azure::Core::Context so that operation can be cancelled. + * + * @return Curl code. + */ + CURLcode UploadBody(Context const& context); + + /** + * @brief This function is used after sending an HTTP request to the server to read the HTTP + * RawResponse from wire until the end of headers only. + * + * @param context #Azure::Core::Context so that operation can be cancelled. + * @param reuseInternalBuffer Indicates whether the internal buffer should be reused. + */ + void ReadStatusLineAndHeadersFromRawResponse( + Context const& context, + bool reuseInternalBuffer = false); + + /** + * @brief Reads from inner buffer or from Wire until chunkSize is parsed and converted to + * unsigned long long + * + * @param context #Azure::Core::Context so that operation can be cancelled. + */ + void ParseChunkSize(Context const& context); + + /** + * @brief Last HTTP status code read. + * + * @remark The last status is initialized as a bad request just as a way to know that there's + * not a good request performed by the session. The status will be updated as soon as the + * session sent a request and it is used to decide if a connection can be re-used or not. + */ + Http::HttpStatusCode m_lastStatusCode = Http::HttpStatusCode::BadRequest; + + /** + * @brief check whether an end of file has been reached. + * @return `true` if end of file has been reached, `false` otherwise. + */ + bool IsEOF() + { + auto eof = m_isChunkedResponseType ? m_chunkSize == 0 : m_contentLength == m_sessionTotalRead; + + // `IsEOF` is called before trying to move a connection back to the connection pool. + // If the session state is `PERFORM` it means the request could not complete an upload + // operation (might have throw while uploading). + // Connection should not be moved back to the connection pool on this scenario. + return eof && m_sessionState != SessionState::PERFORM; + } + + /** + * @brief All connections will request to keep the channel open to re-use the + * connection. + * + * @remark This option can be disabled from the transport adapter options. When disabled, the + * session won't return connections to the connection pool. Connection will be closed as soon as + * the request is completed. + * + */ + bool m_keepAlive = true; + + /** + * @brief Implement #Azure::Core::IO::BodyStream::OnRead(). Calling this function pulls data + * from the wire. + * + * @param context #Azure::Core::Context so that operation can be cancelled. + * @param buffer Buffer where data from wire is written to. + * @param count The number of bytes to read from the network. + * @return The actual number of bytes read from the network. + */ + int64_t OnRead(uint8_t* buffer, int64_t count, Azure::Core::Context const& context) override; + + public: + /** + * @brief Construct a new Curl Session object. Init internal libcurl handler. + * + * @param request reference to an HTTP Request. + */ + CurlSession(Request& request, std::unique_ptr connection, bool keepAlive) + : m_connection(std::move(connection)), m_request(request), m_keepAlive(keepAlive) + { + } + + ~CurlSession() override + { + // mark connection as reusable only if entire response was read + // If not, connection can't be reused because next Read will start from what it is currently + // in the wire. + // By not moving the connection back to the pool, it gets destroyed calling the connection + // destructor to clean libcurl handle and close the connection. + // IsEOF will also handle a connection that fail to complete an upload request. + if (IsEOF() && m_keepAlive) + { + _detail::CurlConnectionPool::g_curlConnectionPool.MoveConnectionBackToPool( + std::move(m_connection), m_lastStatusCode); + } + } + + /** + * @brief Function will use the HTTP request received in constructor to perform a network call + * based on the HTTP request configuration. + * + * @param context #Azure::Core::Context so that operation can be cancelled. + * @return CURLE_OK when the network call is completed successfully. + */ + CURLcode Perform(Context const& context); + + /** + * @brief Moved the ownership of the HTTP RawResponse out of the session. + * + * @return the unique ptr to the HTTP RawResponse or null if the HTTP RawResponse is not yet + * created or was moved before. + */ + std::unique_ptr ExtractResponse(); + + /** + * @brief Implement #Azure::Core::IO::BodyStream length. + * + * @return The size of the payload. + */ + int64_t Length() const override { return m_contentLength; } + }; + +}}} // namespace Azure::Core::Http diff --git a/sdk/core/azure-core/src/environment_log_level_listener_private.hpp b/sdk/core/azure-core/src/private/environment_log_level_listener.hpp similarity index 100% rename from sdk/core/azure-core/src/environment_log_level_listener_private.hpp rename to sdk/core/azure-core/src/private/environment_log_level_listener.hpp diff --git a/sdk/core/azure-core/inc/azure/core/version.hpp b/sdk/core/azure-core/src/private/package_version.hpp similarity index 56% rename from sdk/core/azure-core/inc/azure/core/version.hpp rename to sdk/core/azure-core/src/private/package_version.hpp index 82db824c0..583351b1a 100644 --- a/sdk/core/azure-core/inc/azure/core/version.hpp +++ b/sdk/core/azure-core/src/private/package_version.hpp @@ -8,17 +8,15 @@ #pragma once -#include "azure/core/dll_import_export.hpp" - -#include - #define AZURE_CORE_VERSION_MAJOR 1 #define AZURE_CORE_VERSION_MINOR 0 #define AZURE_CORE_VERSION_PATCH 0 #define AZURE_CORE_VERSION_PRERELEASE "beta.9" -namespace Azure { namespace Core { namespace _detail { +#define AZURE_CORE_VERSION_ITOA_HELPER(i) #i +#define AZURE_CORE_VERSION_ITOA(i) AZURE_CORE_VERSION_ITOA_HELPER(i) +namespace Azure { namespace Core { namespace _detail { /** * @brief Provides version information. */ @@ -33,23 +31,27 @@ namespace Azure { namespace Core { namespace _detail { /// Patch numeric identifier. static constexpr int Patch = AZURE_CORE_VERSION_PATCH; - /// Optional pre-release identifier. SDK is in a pre-release state when not empty. - AZ_CORE_DLLEXPORT static std::string const PreRelease; + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease = sizeof(AZURE_CORE_VERSION_PRERELEASE) != sizeof(""); /** * @brief The version in string format used for telemetry following the `semver.org` standard * (https://semver.org). */ - static std::string ToString(); - - private: - // To avoid leaking out the #define values we smuggle out the value - // which will later be used to initialize the PreRelease std::string - static constexpr const char* secret = AZURE_CORE_VERSION_PRERELEASE; + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_CORE_VERSION_ITOA(AZURE_CORE_VERSION_MAJOR) "." AZURE_CORE_VERSION_ITOA( + AZURE_CORE_VERSION_MINOR) "." AZURE_CORE_VERSION_ITOA(AZURE_CORE_VERSION_PATCH) "-" AZURE_CORE_VERSION_PRERELEASE + : AZURE_CORE_VERSION_ITOA(AZURE_CORE_VERSION_MAJOR) "." AZURE_CORE_VERSION_ITOA( + AZURE_CORE_VERSION_MINOR) "." AZURE_CORE_VERSION_ITOA(AZURE_CORE_VERSION_PATCH); + } }; - }}} // namespace Azure::Core::_detail +#undef AZURE_CORE_VERSION_ITOA_HELPER +#undef AZURE_CORE_VERSION_ITOA + #undef AZURE_CORE_VERSION_MAJOR #undef AZURE_CORE_VERSION_MINOR #undef AZURE_CORE_VERSION_PATCH diff --git a/sdk/core/azure-core/src/version.cpp b/sdk/core/azure-core/src/version.cpp deleted file mode 100644 index 7b48091da..000000000 --- a/sdk/core/azure-core/src/version.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include "azure/core/version.hpp" - -#include -#include - -using namespace Azure::Core::_detail; - -const std::string PackageVersion::PreRelease = secret; - -std::string PackageVersion::ToString() -{ - static const std::string versionString = [] { - std::string version; - std::stringstream ss; - std::string dot = "."; - - ss << PackageVersion::Major << dot << PackageVersion::Minor << dot << PackageVersion::Patch; - - if (!PackageVersion::PreRelease.empty()) - ss << "-" << PackageVersion::PreRelease; - - return ss.str(); - }(); - - return versionString; -} diff --git a/sdk/core/azure-core/test/ut/azure_libcurl_core_main.cpp b/sdk/core/azure-core/test/ut/azure_libcurl_core_main.cpp index a7baf2f2a..e2c9b7f52 100644 --- a/sdk/core/azure-core/test/ut/azure_libcurl_core_main.cpp +++ b/sdk/core/azure-core/test/ut/azure_libcurl_core_main.cpp @@ -25,9 +25,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include diff --git a/sdk/core/azure-core/test/ut/curl_connection_pool.cpp b/sdk/core/azure-core/test/ut/curl_connection_pool.cpp index 23eee1397..b28fc7e0a 100644 --- a/sdk/core/azure-core/test/ut/curl_connection_pool.cpp +++ b/sdk/core/azure-core/test/ut/curl_connection_pool.cpp @@ -15,11 +15,11 @@ #include // The next includes are from Azure Core private headers. -// That's why the path starts from `sdk/core/azure-core/src/` +// That's why the path starts from `private/` // They are included to test the connection pool from the curl transport adapter implementation. -#include -#include -#include +#include +#include +#include #include "curl_session.hpp" diff --git a/sdk/core/azure-core/test/ut/curl_options.cpp b/sdk/core/azure-core/test/ut/curl_options.cpp index fc9ad416f..83c315d07 100644 --- a/sdk/core/azure-core/test/ut/curl_options.cpp +++ b/sdk/core/azure-core/test/ut/curl_options.cpp @@ -14,8 +14,8 @@ #include "azure/core/http/curl_transport.hpp" #endif -#include -#include +#include +#include #include "transport_adapter_base.hpp" diff --git a/sdk/core/azure-core/test/ut/curl_session.hpp b/sdk/core/azure-core/test/ut/curl_session.hpp index 50d2e0e12..25db5c573 100644 --- a/sdk/core/azure-core/test/ut/curl_session.hpp +++ b/sdk/core/azure-core/test/ut/curl_session.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include namespace Azure { namespace Core { namespace Test { diff --git a/sdk/core/azure-core/test/ut/curl_session_test.cpp b/sdk/core/azure-core/test/ut/curl_session_test.cpp index 4ad6e9df9..545cbf27f 100644 --- a/sdk/core/azure-core/test/ut/curl_session_test.cpp +++ b/sdk/core/azure-core/test/ut/curl_session_test.cpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include using ::testing::_; using ::testing::DoAll; diff --git a/sdk/identity/azure-identity/CMakeLists.txt b/sdk/identity/azure-identity/CMakeLists.txt index cff17f83a..848273c6d 100644 --- a/sdk/identity/azure-identity/CMakeLists.txt +++ b/sdk/identity/azure-identity/CMakeLists.txt @@ -36,15 +36,14 @@ set( inc/azure/identity/client_secret_credential.hpp inc/azure/identity/environment_credential.hpp inc/azure/identity/dll_import_export.hpp - inc/azure/identity/version.hpp inc/azure/identity.hpp ) set( AZURE_IDENTITY_SOURCE + src/private/package_version.hpp src/client_secret_credential.cpp src/environment_credential.cpp - src/version.cpp ) add_library(azure-identity ${AZURE_IDENTITY_HEADER} ${AZURE_IDENTITY_SOURCE}) @@ -65,7 +64,7 @@ target_include_directories( target_link_libraries(azure-identity PUBLIC Azure::azure-core) -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/identity/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-identity ${AZ_LIBRARY_VERSION}) az_vcpkg_export( diff --git a/sdk/identity/azure-identity/inc/azure/identity/version.hpp b/sdk/identity/azure-identity/src/private/package_version.hpp similarity index 55% rename from sdk/identity/azure-identity/inc/azure/identity/version.hpp rename to sdk/identity/azure-identity/src/private/package_version.hpp index 00f8c72b1..8c0c1c5e2 100644 --- a/sdk/identity/azure-identity/inc/azure/identity/version.hpp +++ b/sdk/identity/azure-identity/src/private/package_version.hpp @@ -8,17 +8,15 @@ #pragma once -#include "azure/identity/dll_import_export.hpp" - -#include - #define AZURE_IDENTITY_VERSION_MAJOR 1 #define AZURE_IDENTITY_VERSION_MINOR 0 #define AZURE_IDENTITY_VERSION_PATCH 0 #define AZURE_IDENTITY_VERSION_PRERELEASE "beta.6" -namespace Azure { namespace Identity { namespace _detail { +#define AZURE_IDENTITY_VERSION_ITOA_HELPER(i) #i +#define AZURE_IDENTITY_VERSION_ITOA(i) AZURE_IDENTITY_VERSION_ITOA_HELPER(i) +namespace Azure { namespace Identity { namespace _detail { /** * @brief Provides version information. */ @@ -33,23 +31,27 @@ namespace Azure { namespace Identity { namespace _detail { /// Patch numeric identifier. static constexpr int Patch = AZURE_IDENTITY_VERSION_PATCH; - /// Optional pre-release identifier. SDK is in a pre-release state when not empty. - AZ_IDENTITY_DLLEXPORT static std::string const PreRelease; + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease = sizeof(AZURE_IDENTITY_VERSION_PRERELEASE) != sizeof(""); /** * @brief The version in string format used for telemetry following the `semver.org` standard * (https://semver.org). */ - static std::string ToString(); - - private: - // To avoid leaking out the #define values we smuggle out the value - // which will later be used to initialize the PreRelease std::string - static constexpr char const* secret = AZURE_IDENTITY_VERSION_PRERELEASE; + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_IDENTITY_VERSION_ITOA(AZURE_IDENTITY_VERSION_MAJOR) "." AZURE_IDENTITY_VERSION_ITOA( + AZURE_IDENTITY_VERSION_MINOR) "." AZURE_IDENTITY_VERSION_ITOA(AZURE_IDENTITY_VERSION_PATCH) "-" AZURE_IDENTITY_VERSION_PRERELEASE + : AZURE_IDENTITY_VERSION_ITOA(AZURE_IDENTITY_VERSION_MAJOR) "." AZURE_IDENTITY_VERSION_ITOA( + AZURE_IDENTITY_VERSION_MINOR) "." AZURE_IDENTITY_VERSION_ITOA(AZURE_IDENTITY_VERSION_PATCH); + } }; - }}} // namespace Azure::Identity::_detail +#undef AZURE_IDENTITY_VERSION_ITOA_HELPER +#undef AZURE_IDENTITY_VERSION_ITOA + #undef AZURE_IDENTITY_VERSION_MAJOR #undef AZURE_IDENTITY_VERSION_MINOR #undef AZURE_IDENTITY_VERSION_PATCH diff --git a/sdk/identity/azure-identity/src/version.cpp b/sdk/identity/azure-identity/src/version.cpp deleted file mode 100644 index 4406f010b..000000000 --- a/sdk/identity/azure-identity/src/version.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include "azure/identity/version.hpp" - -#include -#include - -using namespace Azure::Identity::_detail; - -std::string const PackageVersion::PreRelease = secret; - -std::string PackageVersion::ToString() -{ - static const std::string versionString = [] { - std::string version; - std::stringstream ss; - std::string dot = "."; - - ss << PackageVersion::Major << dot << PackageVersion::Minor << dot << PackageVersion::Patch; - - if (!PackageVersion::PreRelease.empty()) - ss << "-" << PackageVersion::PreRelease; - - return ss.str(); - }(); - - return versionString; -} diff --git a/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt index ef4c9484e..2b77f8be7 100644 --- a/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt @@ -34,11 +34,11 @@ set( inc/azure/keyvault/common/internal/unix_time_helper.hpp inc/azure/keyvault/common/keyvault_constants.hpp inc/azure/keyvault/common/keyvault_exception.hpp - inc/azure/keyvault/common/version.hpp ) set( AZURE_KEYVAULT_COMMON_SOURCE + src/private/package_version.hpp src/keyvault_exception.cpp src/keyvault_pipeline.cpp ) @@ -66,7 +66,7 @@ endif() # coverage. Has no effect if BUILD_CODE_COVERAGE is OFF create_code_coverage(keyvault azure-security-keyvault-common azure-security-keyvault-common-test) -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/keyvault/common/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-security-keyvault-common ${AZ_LIBRARY_VERSION}) if(BUILD_TESTING) diff --git a/sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/version.hpp b/sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/version.hpp deleted file mode 100644 index db9a2c337..000000000 --- a/sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/version.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -/** - * @brief This file is used for automatic release operations. - * - */ - -#pragma once - -#include - -#include "azure/keyvault/common/dll_import_export.hpp" - -#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR 4 -#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR 0 -#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH 0 -#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE "beta.2" - -namespace Azure { namespace Security { namespace KeyVault { namespace Common { namespace _detail { - - class PackageVersion { - public: - static constexpr int Major = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR; - static constexpr int Minor = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR; - static constexpr int Patch = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH; - AZ_SECURITY_KEYVAULT_COMMON_DLLEXPORT static std::string const PreRelease; - static std::string ToString(); - - private: - // To avoid leaking out the #define values we smuggle out the value - // which will later be used to initialize the PreRelease std::string - static constexpr const char* secret = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE; - }; -}}}}} // namespace Azure::Security::KeyVault::Common::_detail - -#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR -#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR -#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH -#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE diff --git a/sdk/keyvault/azure-security-keyvault-common/src/private/package_version.hpp b/sdk/keyvault/azure-security-keyvault-common/src/private/package_version.hpp new file mode 100644 index 000000000..e66b1fda8 --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-common/src/private/package_version.hpp @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief Provides version information. + */ + +#pragma once + +#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR 4 +#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR 0 +#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH 0 +#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE "beta.2" + +#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA_HELPER(i) #i +#define AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(i) \ + AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA_HELPER(i) + +namespace Azure { namespace Security { namespace KeyVault { namespace Common { namespace _detail { + /** + * @brief Provides version information. + */ + class PackageVersion { + public: + /// Major numeric identifier. + static constexpr int Major = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR; + + /// Minor numeric identifier. + static constexpr int Minor = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR; + + /// Patch numeric identifier. + static constexpr int Patch = AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH; + + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease + = sizeof(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE) != sizeof(""); + + /** + * @brief The version in string format used for telemetry following the `semver.org` standard + * (https://semver.org). + */ + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA( + AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH) "-" AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE + : AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA( + AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR) "." AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH); + } + }; +}}}}} // namespace Azure::Security::KeyVault::Common::_detail + +#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA_HELPER +#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_ITOA + +#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MAJOR +#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_MINOR +#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PATCH +#undef AZURE_SECURITY_KEYVAULT_COMMON_VERSION_PRERELEASE diff --git a/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt index 4a6d26339..f796f210c 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt @@ -45,11 +45,11 @@ set( inc/azure/keyvault/keys/key_vault_key.hpp inc/azure/keyvault/keys/list_keys_single_page_result.hpp inc/azure/keyvault/keys/recover_deleted_key_operation.hpp - inc/azure/keyvault/keys/version.hpp ) set( AZURE_KEYVAULT_KEYS_SOURCE + src/private/package_version.hpp src/delete_key_operation.cpp src/deleted_key.cpp src/import_key_options.cpp @@ -83,7 +83,7 @@ target_link_libraries(azure-security-keyvault-keys PUBLIC Azure::azure-security- # coverage. Has no effect if BUILD_CODE_COVERAGE is OFF create_code_coverage(keyvault azure-security-keyvault-keys azure-security-keyvault-keys-test) -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/keyvault/keys/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-security-keyvault-keys ${AZ_LIBRARY_VERSION}) if(BUILD_TESTING) diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/key_vault.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/key_vault.hpp index 408a4e228..8a91b1f2d 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/key_vault.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/key_vault.hpp @@ -23,4 +23,3 @@ #include "azure/keyvault/keys/key_vault_key.hpp" #include "azure/keyvault/keys/list_keys_single_page_result.hpp" #include "azure/keyvault/keys/recover_deleted_key_operation.hpp" -#include "azure/keyvault/keys/version.hpp" diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/version.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/version.hpp deleted file mode 100644 index 644fc069c..000000000 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/version.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -/** - * @brief This file is used for automatic release operations. - * - */ - -#pragma once - -#include - -#include "azure/keyvault/keys/dll_import_export.hpp" - -#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR 4 -#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR 0 -#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH 0 -#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PRERELEASE "beta.2" - -namespace Azure { namespace Security { namespace KeyVault { namespace Keys { namespace _detail { - - class PackageVersion { - public: - static constexpr int Major = AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR; - static constexpr int Minor = AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR; - static constexpr int Patch = AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH; - AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static std::string const PreRelease; - static std::string ToString(); - - private: - // To avoid leaking out the #define values we smuggle out the value - // which will later be used to initialize the PreRelease std::string - static constexpr const char* secret = AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PRERELEASE; - }; -}}}}} // namespace Azure::Security::KeyVault::Keys::_detail - -#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR -#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR -#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH -#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PRERELEASE diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/private/package_version.hpp b/sdk/keyvault/azure-security-keyvault-keys/src/private/package_version.hpp new file mode 100644 index 000000000..f12048a3c --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/src/private/package_version.hpp @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief Provides version information. + */ + +#pragma once + +#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR 4 +#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR 0 +#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH 0 +#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PRERELEASE "beta.2" + +#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA_HELPER(i) #i +#define AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA(i) \ + AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA_HELPER(i) + +namespace Azure { namespace Security { namespace KeyVault { namespace Keys { namespace _detail { + /** + * @brief Provides version information. + */ + class PackageVersion { + public: + /// Major numeric identifier. + static constexpr int Major = AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR; + + /// Minor numeric identifier. + static constexpr int Minor = AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR; + + /// Patch numeric identifier. + static constexpr int Patch = AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH; + + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease + = sizeof(AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PRERELEASE) != sizeof(""); + + /** + * @brief The version in string format used for telemetry following the `semver.org` standard + * (https://semver.org). + */ + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR) "." AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA( + AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR) "." AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH) "-" AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PRERELEASE + : AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR) "." AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA( + AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR) "." AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA(AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH); + } + }; +}}}}} // namespace Azure::Security::KeyVault::Keys::_detail + +#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA_HELPER +#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_ITOA + +#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MAJOR +#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_MINOR +#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PATCH +#undef AZURE_SECURITY_KEYVAULT_KEYS_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-blobs/CMakeLists.txt b/sdk/storage/azure-storage-blobs/CMakeLists.txt index 1ad666cd5..6c21f4ee7 100644 --- a/sdk/storage/azure-storage-blobs/CMakeLists.txt +++ b/sdk/storage/azure-storage-blobs/CMakeLists.txt @@ -40,12 +40,12 @@ set( inc/azure/storage/blobs/block_blob_client.hpp inc/azure/storage/blobs/dll_import_export.hpp inc/azure/storage/blobs/page_blob_client.hpp - inc/azure/storage/blobs/version.hpp inc/azure/storage/blobs.hpp ) set( AZURE_STORAGE_BLOB_SOURCE + src/private/package_version.hpp src/append_blob_client.cpp src/blob_client.cpp src/blob_container_client.cpp @@ -72,7 +72,7 @@ target_include_directories( target_link_libraries(azure-storage-blobs PUBLIC Azure::azure-storage-common) -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/storage/blobs/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-storage-blobs ${AZ_LIBRARY_VERSION}) az_vcpkg_export( diff --git a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/version.hpp b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/version.hpp deleted file mode 100644 index bf6820e9d..000000000 --- a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/version.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -/** - * @file - * @brief Provides version information. - */ - -#pragma once - -#include -#include - -#define AZURE_STORAGE_BLOBS_VERSION_MAJOR 12 -#define AZURE_STORAGE_BLOBS_VERSION_MINOR 0 -#define AZURE_STORAGE_BLOBS_VERSION_PATCH 0 -#define AZURE_STORAGE_BLOBS_VERSION_PRERELEASE "beta.11" - -namespace Azure { namespace Storage { namespace Blobs { namespace _detail { - - /** - * @brief Provides version information. - */ - struct PackageVersion - { - public: - /// Major numeric identifier. - constexpr static int Major = AZURE_STORAGE_BLOBS_VERSION_MAJOR; - - /// Minor numeric identifier. - constexpr static int Minor = AZURE_STORAGE_BLOBS_VERSION_MINOR; - - /// Patch numeric identifier. - constexpr static int Patch = AZURE_STORAGE_BLOBS_VERSION_PATCH; - - /// Optional pre-release identifier. SDK is in a pre-release state when not empty. - constexpr static const char* PreRelease = AZURE_STORAGE_BLOBS_VERSION_PRERELEASE; - - /** - * @brief The version in string format used for telemetry following the `semver.org` standard - * (https://semver.org). - */ - static std::string ToString() - { - std::string versionString - = std::to_string(Major) + "." + std::to_string(Minor) + "." + std::to_string(Patch); - if (std::strlen(PreRelease) != 0) - { - versionString += "-"; - versionString += PreRelease; - } - return versionString; - } - }; - -}}}} // namespace Azure::Storage::Blobs::_detail - -#undef AZURE_STORAGE_BLOBS_VERSION_MAJOR -#undef AZURE_STORAGE_BLOBS_VERSION_MINOR -#undef AZURE_STORAGE_BLOBS_VERSION_PATCH -#undef AZURE_STORAGE_BLOBS_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-blobs/src/blob_client.cpp b/sdk/storage/azure-storage-blobs/src/blob_client.cpp index 1c8ceaa67..e1b3b02ee 100644 --- a/sdk/storage/azure-storage-blobs/src/blob_client.cpp +++ b/sdk/storage/azure-storage-blobs/src/blob_client.cpp @@ -17,7 +17,10 @@ #include "azure/storage/blobs/append_blob_client.hpp" #include "azure/storage/blobs/block_blob_client.hpp" #include "azure/storage/blobs/page_blob_client.hpp" -#include "azure/storage/blobs/version.hpp" + +#include "private/package_version.hpp" + +#include namespace Azure { namespace Storage { namespace Blobs { diff --git a/sdk/storage/azure-storage-blobs/src/blob_container_client.cpp b/sdk/storage/azure-storage-blobs/src/blob_container_client.cpp index 71c2b0414..1da345c74 100644 --- a/sdk/storage/azure-storage-blobs/src/blob_container_client.cpp +++ b/sdk/storage/azure-storage-blobs/src/blob_container_client.cpp @@ -14,7 +14,8 @@ #include "azure/storage/blobs/append_blob_client.hpp" #include "azure/storage/blobs/block_blob_client.hpp" #include "azure/storage/blobs/page_blob_client.hpp" -#include "azure/storage/blobs/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Blobs { diff --git a/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp b/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp index bc976f38a..bb0bd37ef 100644 --- a/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp +++ b/sdk/storage/azure-storage-blobs/src/blob_service_client.cpp @@ -11,7 +11,7 @@ #include #include -#include "azure/storage/blobs/version.hpp" +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Blobs { diff --git a/sdk/storage/azure-storage-blobs/src/private/package_version.hpp b/sdk/storage/azure-storage-blobs/src/private/package_version.hpp new file mode 100644 index 000000000..c2e632c70 --- /dev/null +++ b/sdk/storage/azure-storage-blobs/src/private/package_version.hpp @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief Provides version information. + */ + +#pragma once + +#define AZURE_STORAGE_BLOBS_VERSION_MAJOR 12 +#define AZURE_STORAGE_BLOBS_VERSION_MINOR 0 +#define AZURE_STORAGE_BLOBS_VERSION_PATCH 0 +#define AZURE_STORAGE_BLOBS_VERSION_PRERELEASE "beta.11" + +#define AZURE_STORAGE_BLOBS_VERSION_ITOA_HELPER(i) #i +#define AZURE_STORAGE_BLOBS_VERSION_ITOA(i) AZURE_STORAGE_BLOBS_VERSION_ITOA_HELPER(i) + +namespace Azure { namespace Storage { namespace Blobs { namespace _detail { + /** + * @brief Provides version information. + */ + class PackageVersion { + public: + /// Major numeric identifier. + static constexpr int Major = AZURE_STORAGE_BLOBS_VERSION_MAJOR; + + /// Minor numeric identifier. + static constexpr int Minor = AZURE_STORAGE_BLOBS_VERSION_MINOR; + + /// Patch numeric identifier. + static constexpr int Patch = AZURE_STORAGE_BLOBS_VERSION_PATCH; + + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease + = sizeof(AZURE_STORAGE_BLOBS_VERSION_PRERELEASE) != sizeof(""); + + /** + * @brief The version in string format used for telemetry following the `semver.org` standard + * (https://semver.org). + */ + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_STORAGE_BLOBS_VERSION_ITOA(AZURE_STORAGE_BLOBS_VERSION_MAJOR) "." AZURE_STORAGE_BLOBS_VERSION_ITOA( + AZURE_STORAGE_BLOBS_VERSION_MINOR) "." AZURE_STORAGE_BLOBS_VERSION_ITOA(AZURE_STORAGE_BLOBS_VERSION_PATCH) "-" AZURE_STORAGE_BLOBS_VERSION_PRERELEASE + : AZURE_STORAGE_BLOBS_VERSION_ITOA(AZURE_STORAGE_BLOBS_VERSION_MAJOR) "." AZURE_STORAGE_BLOBS_VERSION_ITOA( + AZURE_STORAGE_BLOBS_VERSION_MINOR) "." AZURE_STORAGE_BLOBS_VERSION_ITOA(AZURE_STORAGE_BLOBS_VERSION_PATCH); + } + }; +}}}} // namespace Azure::Storage::Blobs::_detail + +#undef AZURE_STORAGE_BLOBS_VERSION_ITOA_HELPER +#undef AZURE_STORAGE_BLOBS_VERSION_ITOA + +#undef AZURE_STORAGE_BLOBS_VERSION_MAJOR +#undef AZURE_STORAGE_BLOBS_VERSION_MINOR +#undef AZURE_STORAGE_BLOBS_VERSION_PATCH +#undef AZURE_STORAGE_BLOBS_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-common/CMakeLists.txt b/sdk/storage/azure-storage-common/CMakeLists.txt index fd501a6ab..1cce210d5 100644 --- a/sdk/storage/azure-storage-common/CMakeLists.txt +++ b/sdk/storage/azure-storage-common/CMakeLists.txt @@ -46,12 +46,12 @@ set( inc/azure/storage/common/storage_per_retry_policy.hpp inc/azure/storage/common/storage_service_version_policy.hpp inc/azure/storage/common/storage_switch_to_secondary_policy.hpp - inc/azure/storage/common/version.hpp inc/azure/storage/common/xml_wrapper.hpp ) set( AZURE_STORAGE_COMMON_SOURCE + src/private/package_version.hpp src/account_sas_builder.cpp src/crypt.cpp src/file_io.cpp @@ -90,7 +90,7 @@ else() target_link_libraries(azure-storage-common PRIVATE OpenSSL::SSL OpenSSL::Crypto) endif() -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/storage/common/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-storage-common ${AZ_LIBRARY_VERSION}) az_vcpkg_export( diff --git a/sdk/storage/azure-storage-common/inc/azure/storage/common/version.hpp b/sdk/storage/azure-storage-common/inc/azure/storage/common/version.hpp deleted file mode 100644 index 9b13491c8..000000000 --- a/sdk/storage/azure-storage-common/inc/azure/storage/common/version.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -/** - * @file - * @brief Provides version information. - */ - -#pragma once - -#include -#include - -#define AZURE_STORAGE_COMMON_VERSION_MAJOR 12 -#define AZURE_STORAGE_COMMON_VERSION_MINOR 0 -#define AZURE_STORAGE_COMMON_VERSION_PATCH 0 -#define AZURE_STORAGE_COMMON_VERSION_PRERELEASE "beta.11" - -namespace Azure { namespace Storage { namespace Common { namespace _detail { - - /** - * @brief Provides version information. - */ - struct PackageVersion - { - public: - /// Major numeric identifier. - constexpr static int Major = AZURE_STORAGE_COMMON_VERSION_MAJOR; - - /// Minor numeric identifier. - constexpr static int Minor = AZURE_STORAGE_COMMON_VERSION_MINOR; - - /// Patch numeric identifier. - constexpr static int Patch = AZURE_STORAGE_COMMON_VERSION_PATCH; - - /// Optional pre-release identifier. SDK is in a pre-release state when not empty. - constexpr static const char* PreRelease = AZURE_STORAGE_COMMON_VERSION_PRERELEASE; - - /** - * @brief The version in string format used for telemetry following the `semver.org` standard - * (https://semver.org). - */ - static std::string ToString() - { - std::string versionString - = std::to_string(Major) + "." + std::to_string(Minor) + "." + std::to_string(Patch); - if (std::strlen(PreRelease) != 0) - { - versionString += "-"; - versionString += PreRelease; - } - return versionString; - } - }; - -}}}} // namespace Azure::Storage::Common::_detail - -#undef AZURE_STORAGE_COMMON_VERSION_MAJOR -#undef AZURE_STORAGE_COMMON_VERSION_MINOR -#undef AZURE_STORAGE_COMMON_VERSION_PATCH -#undef AZURE_STORAGE_COMMON_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-common/src/private/package_version.hpp b/sdk/storage/azure-storage-common/src/private/package_version.hpp new file mode 100644 index 000000000..3819ea06d --- /dev/null +++ b/sdk/storage/azure-storage-common/src/private/package_version.hpp @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief Provides version information. + */ + +#pragma once + +#include + +#define AZURE_STORAGE_COMMON_VERSION_MAJOR 12 +#define AZURE_STORAGE_COMMON_VERSION_MINOR 0 +#define AZURE_STORAGE_COMMON_VERSION_PATCH 0 +#define AZURE_STORAGE_COMMON_VERSION_PRERELEASE "beta.11" + +#define AZURE_STORAGE_COMMON_VERSION_ITOA_HELPER(i) #i +#define AZURE_STORAGE_COMMON_VERSION_ITOA(i) AZURE_STORAGE_COMMON_VERSION_ITOA_HELPER(i) + +namespace Azure { namespace Storage { namespace Common { namespace _detail { + /** + * @brief Provides version information. + */ + class PackageVersion { + public: + /// Major numeric identifier. + static constexpr int Major = AZURE_STORAGE_COMMON_VERSION_MAJOR; + + /// Minor numeric identifier. + static constexpr int Minor = AZURE_STORAGE_COMMON_VERSION_MINOR; + + /// Patch numeric identifier. + static constexpr int Patch = AZURE_STORAGE_COMMON_VERSION_PATCH; + + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease + = sizeof(AZURE_STORAGE_COMMON_VERSION_PRERELEASE) != sizeof(""); + + /** + * @brief The version in string format used for telemetry following the `semver.org` standard + * (https://semver.org). + */ + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_STORAGE_COMMON_VERSION_ITOA(AZURE_STORAGE_COMMON_VERSION_MAJOR) "." AZURE_STORAGE_COMMON_VERSION_ITOA( + AZURE_STORAGE_COMMON_VERSION_MINOR) "." AZURE_STORAGE_COMMON_VERSION_ITOA(AZURE_STORAGE_COMMON_VERSION_PATCH) "-" AZURE_STORAGE_COMMON_VERSION_PRERELEASE + : AZURE_STORAGE_COMMON_VERSION_ITOA(AZURE_STORAGE_COMMON_VERSION_MAJOR) "." AZURE_STORAGE_COMMON_VERSION_ITOA( + AZURE_STORAGE_COMMON_VERSION_MINOR) "." AZURE_STORAGE_COMMON_VERSION_ITOA(AZURE_STORAGE_COMMON_VERSION_PATCH); + } + }; +}}}} // namespace Azure::Storage::Common::_detail + +#undef AZURE_STORAGE_COMMON_VERSION_ITOA_HELPER +#undef AZURE_STORAGE_COMMON_VERSION_ITOA + +#undef AZURE_STORAGE_COMMON_VERSION_MAJOR +#undef AZURE_STORAGE_COMMON_VERSION_MINOR +#undef AZURE_STORAGE_COMMON_VERSION_PATCH +#undef AZURE_STORAGE_COMMON_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-files-datalake/CMakeLists.txt b/sdk/storage/azure-storage-files-datalake/CMakeLists.txt index f6aa027dc..650ca1d97 100644 --- a/sdk/storage/azure-storage-files-datalake/CMakeLists.txt +++ b/sdk/storage/azure-storage-files-datalake/CMakeLists.txt @@ -41,12 +41,12 @@ set( inc/azure/storage/files/datalake/datalake_service_client.hpp inc/azure/storage/files/datalake/datalake_utilities.hpp inc/azure/storage/files/datalake/dll_import_export.hpp - inc/azure/storage/files/datalake/version.hpp inc/azure/storage/files/datalake.hpp ) set( AZURE_STORAGE_FILES_DATALAKE_SOURCE + src/private/package_version.hpp src/datalake_directory_client.cpp src/datalake_file_client.cpp src/datalake_file_system_client.cpp @@ -73,7 +73,7 @@ target_include_directories( target_link_libraries(azure-storage-files-datalake PUBLIC Azure::azure-storage-blobs) -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/storage/files/datalake/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-storage-files-datalake ${AZ_LIBRARY_VERSION}) az_vcpkg_export( diff --git a/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/version.hpp b/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/version.hpp deleted file mode 100644 index 2a123aefe..000000000 --- a/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/version.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -/** - * @file - * @brief Provides version information. - */ - -#pragma once - -#include -#include - -#define AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR 12 -#define AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR 0 -#define AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH 0 -#define AZURE_STORAGE_FILES_DATALAKE_VERSION_PRERELEASE "beta.11" - -namespace Azure { namespace Storage { namespace Files { namespace DataLake { namespace _detail { - - /** - * @brief Provides version information. - */ - struct PackageVersion - { - public: - /// Major numeric identifier. - constexpr static int Major = AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR; - - /// Minor numeric identifier. - constexpr static int Minor = AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR; - - /// Patch numeric identifier. - constexpr static int Patch = AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH; - - /// Optional pre-release identifier. SDK is in a pre-release state when not empty. - constexpr static const char* PreRelease = AZURE_STORAGE_FILES_DATALAKE_VERSION_PRERELEASE; - - /** - * @brief The version in string format used for telemetry following the `semver.org` standard - * (https://semver.org). - */ - static std::string ToString() - { - std::string versionString - = std::to_string(Major) + "." + std::to_string(Minor) + "." + std::to_string(Patch); - if (std::strlen(PreRelease) != 0) - { - versionString += "-"; - versionString += PreRelease; - } - return versionString; - } - }; - -}}}}} // namespace Azure::Storage::Files::DataLake::_detail - -#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR -#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR -#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH -#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_directory_client.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_directory_client.cpp index adee25e25..1ffc50356 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_directory_client.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_directory_client.cpp @@ -12,7 +12,6 @@ #include "azure/storage/files/datalake/datalake_file_client.hpp" #include "azure/storage/files/datalake/datalake_utilities.hpp" -#include "azure/storage/files/datalake/version.hpp" namespace Azure { namespace Storage { namespace Files { namespace DataLake { diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp index 1f2258d53..31e780b00 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp @@ -11,7 +11,6 @@ #include "azure/storage/files/datalake/datalake_constants.hpp" #include "azure/storage/files/datalake/datalake_utilities.hpp" -#include "azure/storage/files/datalake/version.hpp" namespace Azure { namespace Storage { namespace Files { namespace DataLake { diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp index 4f7fbac3e..b41bdaa0e 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp @@ -18,7 +18,8 @@ #include "azure/storage/files/datalake/datalake_file_client.hpp" #include "azure/storage/files/datalake/datalake_path_client.hpp" #include "azure/storage/files/datalake/datalake_utilities.hpp" -#include "azure/storage/files/datalake/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Files { namespace DataLake { diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_path_client.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_path_client.cpp index 7b768ae66..e13915811 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_path_client.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_path_client.cpp @@ -14,7 +14,8 @@ #include "azure/storage/files/datalake/datalake_constants.hpp" #include "azure/storage/files/datalake/datalake_utilities.hpp" -#include "azure/storage/files/datalake/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Files { namespace DataLake { diff --git a/sdk/storage/azure-storage-files-datalake/src/datalake_service_client.cpp b/sdk/storage/azure-storage-files-datalake/src/datalake_service_client.cpp index d7e555bb7..81eb46e4f 100644 --- a/sdk/storage/azure-storage-files-datalake/src/datalake_service_client.cpp +++ b/sdk/storage/azure-storage-files-datalake/src/datalake_service_client.cpp @@ -15,7 +15,8 @@ #include "azure/storage/files/datalake/datalake_file_system_client.hpp" #include "azure/storage/files/datalake/datalake_utilities.hpp" -#include "azure/storage/files/datalake/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Files { namespace DataLake { diff --git a/sdk/storage/azure-storage-files-datalake/src/private/package_version.hpp b/sdk/storage/azure-storage-files-datalake/src/private/package_version.hpp new file mode 100644 index 000000000..927255eef --- /dev/null +++ b/sdk/storage/azure-storage-files-datalake/src/private/package_version.hpp @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief Provides version information. + */ + +#pragma once + +#define AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR 12 +#define AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR 0 +#define AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH 0 +#define AZURE_STORAGE_FILES_DATALAKE_VERSION_PRERELEASE "beta.11" + +#define AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA_HELPER(i) #i +#define AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA(i) \ + AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA_HELPER(i) + +namespace Azure { namespace Storage { namespace Files { namespace DataLake { namespace _detail { + /** + * @brief Provides version information. + */ + class PackageVersion { + public: + /// Major numeric identifier. + static constexpr int Major = AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR; + + /// Minor numeric identifier. + static constexpr int Minor = AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR; + + /// Patch numeric identifier. + static constexpr int Patch = AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH; + + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease + = sizeof(AZURE_STORAGE_FILES_DATALAKE_VERSION_PRERELEASE) != sizeof(""); + + /** + * @brief The version in string format used for telemetry following the `semver.org` standard + * (https://semver.org). + */ + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA(AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR) "." AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA( + AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR) "." AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA(AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH) "-" AZURE_STORAGE_FILES_DATALAKE_VERSION_PRERELEASE + : AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA(AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR) "." AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA( + AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR) "." AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA(AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH); + } + }; +}}}}} // namespace Azure::Storage::Files::DataLake::_detail + +#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA_HELPER +#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_ITOA + +#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_MAJOR +#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_MINOR +#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_PATCH +#undef AZURE_STORAGE_FILES_DATALAKE_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-files-shares/CMakeLists.txt b/sdk/storage/azure-storage-files-shares/CMakeLists.txt index 7bf5bccda..98abc249e 100644 --- a/sdk/storage/azure-storage-files-shares/CMakeLists.txt +++ b/sdk/storage/azure-storage-files-shares/CMakeLists.txt @@ -40,12 +40,12 @@ set( inc/azure/storage/files/shares/share_responses.hpp inc/azure/storage/files/shares/share_sas_builder.hpp inc/azure/storage/files/shares/share_service_client.hpp - inc/azure/storage/files/shares/version.hpp inc/azure/storage/files/shares.hpp ) set( AZURE_STORAGE_FILES_SHARES_SOURCE + src/private/package_version.hpp src/share_client.cpp src/share_directory_client.cpp src/share_file_attributes.cpp @@ -71,7 +71,7 @@ target_include_directories( target_link_libraries(azure-storage-files-shares PUBLIC Azure::azure-storage-common) -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/storage/files/shares/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp") generate_documentation(azure-storage-files-shares ${AZ_LIBRARY_VERSION}) az_vcpkg_export( diff --git a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/version.hpp b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/version.hpp deleted file mode 100644 index 4114202b8..000000000 --- a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/version.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -/** - * @file - * @brief Provides version information. - */ - -#pragma once - -#include -#include - -#define AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR 12 -#define AZURE_STORAGE_FILES_SHARES_VERSION_MINOR 0 -#define AZURE_STORAGE_FILES_SHARES_VERSION_PATCH 0 -#define AZURE_STORAGE_FILES_SHARES_VERSION_PRERELEASE "beta.11" - -namespace Azure { namespace Storage { namespace Files { namespace Shares { namespace _detail { - - /** - * @brief Provides version information. - */ - struct PackageVersion - { - public: - /// Major numeric identifier. - constexpr static int Major = AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR; - - /// Minor numeric identifier. - constexpr static int Minor = AZURE_STORAGE_FILES_SHARES_VERSION_MINOR; - - /// Patch numeric identifier. - constexpr static int Patch = AZURE_STORAGE_FILES_SHARES_VERSION_PATCH; - - /// Optional pre-release identifier. SDK is in a pre-release state when not empty. - constexpr static const char* PreRelease = AZURE_STORAGE_FILES_SHARES_VERSION_PRERELEASE; - - /** - * @brief The version in string format used for telemetry following the `semver.org` standard - * (https://semver.org). - */ - static std::string ToString() - { - std::string versionString - = std::to_string(Major) + "." + std::to_string(Minor) + "." + std::to_string(Patch); - if (std::strlen(PreRelease) != 0) - { - versionString += "-"; - versionString += PreRelease; - } - return versionString; - } - }; - -}}}}} // namespace Azure::Storage::Files::Shares::_detail - -#undef AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR -#undef AZURE_STORAGE_FILES_SHARES_VERSION_MINOR -#undef AZURE_STORAGE_FILES_SHARES_VERSION_PATCH -#undef AZURE_STORAGE_FILES_SHARES_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-files-shares/src/private/package_version.hpp b/sdk/storage/azure-storage-files-shares/src/private/package_version.hpp new file mode 100644 index 000000000..6cdc70731 --- /dev/null +++ b/sdk/storage/azure-storage-files-shares/src/private/package_version.hpp @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief Provides version information. + */ + +#pragma once + +#define AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR 12 +#define AZURE_STORAGE_FILES_SHARES_VERSION_MINOR 0 +#define AZURE_STORAGE_FILES_SHARES_VERSION_PATCH 0 +#define AZURE_STORAGE_FILES_SHARES_VERSION_PRERELEASE "beta.11" + +#define AZURE_STORAGE_FILES_SHARES_VERSION_ITOA_HELPER(i) #i +#define AZURE_STORAGE_FILES_SHARES_VERSION_ITOA(i) AZURE_STORAGE_FILES_SHARES_VERSION_ITOA_HELPER(i) + +namespace Azure { namespace Storage { namespace Files { namespace Shares { namespace _detail { + /** + * @brief Provides version information. + */ + class PackageVersion { + public: + /// Major numeric identifier. + static constexpr int Major = AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR; + + /// Minor numeric identifier. + static constexpr int Minor = AZURE_STORAGE_FILES_SHARES_VERSION_MINOR; + + /// Patch numeric identifier. + static constexpr int Patch = AZURE_STORAGE_FILES_SHARES_VERSION_PATCH; + + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease + = sizeof(AZURE_STORAGE_FILES_SHARES_VERSION_PRERELEASE) != sizeof(""); + + /** + * @brief The version in string format used for telemetry following the `semver.org` standard + * (https://semver.org). + */ + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_STORAGE_FILES_SHARES_VERSION_ITOA(AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR) "." AZURE_STORAGE_FILES_SHARES_VERSION_ITOA( + AZURE_STORAGE_FILES_SHARES_VERSION_MINOR) "." AZURE_STORAGE_FILES_SHARES_VERSION_ITOA(AZURE_STORAGE_FILES_SHARES_VERSION_PATCH) "-" AZURE_STORAGE_FILES_SHARES_VERSION_PRERELEASE + : AZURE_STORAGE_FILES_SHARES_VERSION_ITOA(AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR) "." AZURE_STORAGE_FILES_SHARES_VERSION_ITOA( + AZURE_STORAGE_FILES_SHARES_VERSION_MINOR) "." AZURE_STORAGE_FILES_SHARES_VERSION_ITOA(AZURE_STORAGE_FILES_SHARES_VERSION_PATCH); + } + }; +}}}}} // namespace Azure::Storage::Files::Shares::_detail + +#undef AZURE_STORAGE_FILES_SHARES_VERSION_ITOA_HELPER +#undef AZURE_STORAGE_FILES_SHARES_VERSION_ITOA + +#undef AZURE_STORAGE_FILES_SHARES_VERSION_MAJOR +#undef AZURE_STORAGE_FILES_SHARES_VERSION_MINOR +#undef AZURE_STORAGE_FILES_SHARES_VERSION_PATCH +#undef AZURE_STORAGE_FILES_SHARES_VERSION_PRERELEASE diff --git a/sdk/storage/azure-storage-files-shares/src/share_client.cpp b/sdk/storage/azure-storage-files-shares/src/share_client.cpp index ae745dcb2..d4b8a60f6 100644 --- a/sdk/storage/azure-storage-files-shares/src/share_client.cpp +++ b/sdk/storage/azure-storage-files-shares/src/share_client.cpp @@ -14,7 +14,8 @@ #include "azure/storage/files/shares/share_directory_client.hpp" #include "azure/storage/files/shares/share_file_client.hpp" -#include "azure/storage/files/shares/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Files { namespace Shares { diff --git a/sdk/storage/azure-storage-files-shares/src/share_directory_client.cpp b/sdk/storage/azure-storage-files-shares/src/share_directory_client.cpp index 0673f354f..19bd853da 100644 --- a/sdk/storage/azure-storage-files-shares/src/share_directory_client.cpp +++ b/sdk/storage/azure-storage-files-shares/src/share_directory_client.cpp @@ -13,7 +13,8 @@ #include #include "azure/storage/files/shares/share_file_client.hpp" -#include "azure/storage/files/shares/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Files { namespace Shares { diff --git a/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp b/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp index a96d4d42f..1b97b72ec 100644 --- a/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp +++ b/sdk/storage/azure-storage-files-shares/src/share_file_client.cpp @@ -18,7 +18,8 @@ #include #include "azure/storage/files/shares/share_constants.hpp" -#include "azure/storage/files/shares/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Files { namespace Shares { diff --git a/sdk/storage/azure-storage-files-shares/src/share_service_client.cpp b/sdk/storage/azure-storage-files-shares/src/share_service_client.cpp index 510b711e6..53e832dc6 100644 --- a/sdk/storage/azure-storage-files-shares/src/share_service_client.cpp +++ b/sdk/storage/azure-storage-files-shares/src/share_service_client.cpp @@ -13,7 +13,8 @@ #include #include "azure/storage/files/shares/share_client.hpp" -#include "azure/storage/files/shares/version.hpp" + +#include "private/package_version.hpp" namespace Azure { namespace Storage { namespace Files { namespace Shares { ShareServiceClient ShareServiceClient::CreateFromConnectionString( diff --git a/sdk/template/azure-template/CMakeLists.txt b/sdk/template/azure-template/CMakeLists.txt index 09ddf7741..abdfaf9c8 100644 --- a/sdk/template/azure-template/CMakeLists.txt +++ b/sdk/template/azure-template/CMakeLists.txt @@ -30,14 +30,13 @@ set( AZURE_TEMPLATE_HEADER inc/azure/template/dll_import_export.hpp inc/azure/template/template_client.hpp - inc/azure/template/version.hpp inc/azure/template.hpp ) set( AZURE_TEMPLATE_SOURCE + src/private/package_version.hpp src/template_client.cpp - src/version.cpp ) add_library(azure-template ${AZURE_TEMPLATE_HEADER} ${AZURE_TEMPLATE_SOURCE}) @@ -60,7 +59,7 @@ add_library(Azure::azure-template ALIAS azure-template) # coverage. Has no effect if BUILD_CODE_COVERAGE is OFF create_code_coverage(template azure-template azure-template-test) -get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/template/version.hpp") +get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private//package_version.hpp") generate_documentation(azure-template ${AZ_LIBRARY_VERSION}) az_vcpkg_export( diff --git a/sdk/template/azure-template/inc/azure/template.hpp b/sdk/template/azure-template/inc/azure/template.hpp index 7b2ec7ace..0a2a6c6a6 100644 --- a/sdk/template/azure-template/inc/azure/template.hpp +++ b/sdk/template/azure-template/inc/azure/template.hpp @@ -5,4 +5,3 @@ #include "azure/template/dll_import_export.hpp" #include "azure/template/template_client.hpp" -#include "azure/template/version.hpp" diff --git a/sdk/template/azure-template/inc/azure/template/template_client.hpp b/sdk/template/azure-template/inc/azure/template/template_client.hpp index 72dd81160..4df121e95 100644 --- a/sdk/template/azure-template/inc/azure/template/template_client.hpp +++ b/sdk/template/azure-template/inc/azure/template/template_client.hpp @@ -9,7 +9,7 @@ namespace Azure { namespace Template { class TemplateClient { public: - std::string const ClientVersion(); + std::string ClientVersion() const; }; }} // namespace Azure::Template diff --git a/sdk/template/azure-template/inc/azure/template/version.hpp b/sdk/template/azure-template/src/private/package_version.hpp similarity index 52% rename from sdk/template/azure-template/inc/azure/template/version.hpp rename to sdk/template/azure-template/src/private/package_version.hpp index 6fe78d629..555055647 100644 --- a/sdk/template/azure-template/inc/azure/template/version.hpp +++ b/sdk/template/azure-template/src/private/package_version.hpp @@ -1,19 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT +/** + * @file + * @brief Provides version information. + */ + #pragma once -#include "azure/template/dll_import_export.hpp" - -#include - #define AZURE_TEMPLATE_VERSION_MAJOR 1 #define AZURE_TEMPLATE_VERSION_MINOR 0 #define AZURE_TEMPLATE_VERSION_PATCH 0 #define AZURE_TEMPLATE_VERSION_PRERELEASE "beta.25" -namespace Azure { namespace Template { namespace _detail { +#define AZURE_TEMPLATE_VERSION_ITOA_HELPER(i) #i +#define AZURE_TEMPLATE_VERSION_ITOA(i) AZURE_TEMPLATE_VERSION_ITOA_HELPER(i) +namespace Azure { namespace Template { namespace _detail { /** * @brief Provides version information. */ @@ -28,23 +31,27 @@ namespace Azure { namespace Template { namespace _detail { /// Patch numeric identifier. static constexpr int Patch = AZURE_TEMPLATE_VERSION_PATCH; - /// Optional pre-release identifier. SDK is in a pre-release state when not empty. - AZ_TEMPLATE_DLLEXPORT static std::string const PreRelease; + /// Indicates whether the SDK is in a pre-release state. + static constexpr bool IsPreRelease = sizeof(AZURE_TEMPLATE_VERSION_PRERELEASE) != sizeof(""); /** * @brief The version in string format used for telemetry following the `semver.org` standard * (https://semver.org). */ - static std::string ToString(); - - private: - // To avoid leaking out the #define values we smuggle out the value - // which will later be used to initialize the PreRelease std::string - static constexpr const char* secret = AZURE_TEMPLATE_VERSION_PRERELEASE; + static constexpr const char* ToString() + { + return IsPreRelease + ? AZURE_TEMPLATE_VERSION_ITOA(AZURE_TEMPLATE_VERSION_MAJOR) "." AZURE_TEMPLATE_VERSION_ITOA( + AZURE_TEMPLATE_VERSION_MINOR) "." AZURE_TEMPLATE_VERSION_ITOA(AZURE_TEMPLATE_VERSION_PATCH) "-" AZURE_TEMPLATE_VERSION_PRERELEASE + : AZURE_TEMPLATE_VERSION_ITOA(AZURE_TEMPLATE_VERSION_MAJOR) "." AZURE_TEMPLATE_VERSION_ITOA( + AZURE_TEMPLATE_VERSION_MINOR) "." AZURE_TEMPLATE_VERSION_ITOA(AZURE_TEMPLATE_VERSION_PATCH); + } }; - }}} // namespace Azure::Template::_detail +#undef AZURE_TEMPLATE_VERSION_ITOA_HELPER +#undef AZURE_TEMPLATE_VERSION_ITOA + #undef AZURE_TEMPLATE_VERSION_MAJOR #undef AZURE_TEMPLATE_VERSION_MINOR #undef AZURE_TEMPLATE_VERSION_PATCH diff --git a/sdk/template/azure-template/src/template_client.cpp b/sdk/template/azure-template/src/template_client.cpp index 64ed9f862..df04dc3df 100644 --- a/sdk/template/azure-template/src/template_client.cpp +++ b/sdk/template/azure-template/src/template_client.cpp @@ -2,11 +2,12 @@ // SPDX-License-Identifier: MIT #include "azure/template/template_client.hpp" -#include "azure/template/version.hpp" + +#include "private/package_version.hpp" #include using namespace Azure::Template; using namespace Azure::Template::_detail; -std::string const TemplateClient::ClientVersion() { return PackageVersion::ToString(); } +std::string TemplateClient::ClientVersion() const { return PackageVersion::ToString(); } diff --git a/sdk/template/azure-template/src/version.cpp b/sdk/template/azure-template/src/version.cpp deleted file mode 100644 index dce689cb4..000000000 --- a/sdk/template/azure-template/src/version.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#include -#include -#include - -using namespace Azure::Template::_detail; - -const std::string PackageVersion::PreRelease = secret; - -std::string PackageVersion::ToString() -{ - static const std::string versionString = [] { - std::string version; - std::stringstream ss; - std::string dot = "."; - - ss << PackageVersion::Major << dot << PackageVersion::Minor << dot << PackageVersion::Patch; - - if (!PackageVersion::PreRelease.empty()) - ss << "-" << PackageVersion::PreRelease; - - return ss.str(); - }(); - - return versionString; -}