Create template project (#443)
* Create template project Support retrieving version from code
This commit is contained in:
parent
2027d5102f
commit
1a32179fec
@ -49,3 +49,4 @@ if(BUILD_CURL_TRANSPORT)
|
||||
add_subdirectory(sdk/core/azure-core/test/e2e) # will work only if BUILD_CURL_TRANSPORT=ON
|
||||
endif()
|
||||
add_subdirectory(sdk/storage)
|
||||
add_subdirectory(sdk/template/azure-template)
|
||||
|
||||
@ -32,7 +32,7 @@ add_library (
|
||||
src/http/winhttp/win_http_transport.cpp
|
||||
src/logging/logging.cpp
|
||||
src/strings.cpp
|
||||
)
|
||||
src/version.cpp)
|
||||
|
||||
target_include_directories (${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc> $<INSTALL_INTERFACE:include/az_core>)
|
||||
|
||||
|
||||
34
sdk/core/azure-core/inc/azure/core/version.hpp
Normal file
34
sdk/core/azure-core/inc/azure/core/version.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#define AZURE_CORE_VERSION_MAJOR 1
|
||||
#define AZURE_CORE_VERSION_MINOR 0
|
||||
#define AZURE_CORE_VERSION_PATCH 0
|
||||
#define AZURE_CORE_VERSION_PRERELEASE "beta.1"
|
||||
|
||||
namespace Azure { namespace Core {
|
||||
|
||||
class Version {
|
||||
public:
|
||||
static constexpr int Major = AZURE_CORE_VERSION_MAJOR;
|
||||
static constexpr int Minor = AZURE_CORE_VERSION_MINOR;
|
||||
static constexpr int Patch = AZURE_CORE_VERSION_PATCH;
|
||||
static std::string const PreRelease;
|
||||
static std::string const VersionString();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}} // namespace Azure::Core
|
||||
|
||||
#undef AZURE_CORE_VERSION_MAJOR
|
||||
#undef AZURE_CORE_VERSION_MINOR
|
||||
#undef AZURE_CORE_VERSION_PATCH
|
||||
#undef AZURE_CORE_VERSION_PRERELEASE
|
||||
30
sdk/core/azure-core/src/version.cpp
Normal file
30
sdk/core/azure-core/src/version.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "azure/core/version.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
using namespace Azure::Core;
|
||||
|
||||
const std::string Version::PreRelease = secret;
|
||||
|
||||
std::string const Version::VersionString()
|
||||
{
|
||||
static const std::string versionString = [] {
|
||||
std::string version;
|
||||
std::stringstream ss;
|
||||
std::string dot = ".";
|
||||
|
||||
ss << Version::Major << dot << Version::Minor << dot << Version::Patch;
|
||||
|
||||
if (!Version::PreRelease.empty())
|
||||
ss << "-" << Version::PreRelease;
|
||||
|
||||
return ss.str();
|
||||
}();
|
||||
|
||||
return versionString;
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@ add_executable (
|
||||
telemetry_policy.cpp
|
||||
transport_adapter.cpp
|
||||
transport_adapter.hpp
|
||||
uuid.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE azure-core)
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
|
||||
using namespace Azure::Core;
|
||||
|
||||
TEST(UUID, Basic)
|
||||
TEST(Uuid, Basic)
|
||||
{
|
||||
auto uuid = UUID::CreateUUID();
|
||||
EXPECT_TRUE(uuid.GetUUIDString().length() == 36);
|
||||
auto uuid = Uuid::CreateUuid();
|
||||
EXPECT_TRUE(uuid.GetUuidString().length() == 36);
|
||||
}
|
||||
5
sdk/template/azure-template/CHANGELOG.md
Normal file
5
sdk/template/azure-template/CHANGELOG.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Release History
|
||||
|
||||
## 1.0.0-beta.1 (Unreleased)
|
||||
|
||||
* Template package
|
||||
25
sdk/template/azure-template/CMakeLists.txt
Normal file
25
sdk/template/azure-template/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
set(TARGET_NAME "azure-template")
|
||||
project(azure-template LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
add_library (
|
||||
azure-template
|
||||
src/version.cpp
|
||||
src/template_client.cpp
|
||||
)
|
||||
|
||||
target_include_directories (azure-template PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>)
|
||||
|
||||
# make sure that users can consume the project as a library.
|
||||
add_library (Azure::Template ALIAS azure-template)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
# tests
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
21
sdk/template/azure-template/LICENSE
Normal file
21
sdk/template/azure-template/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
70
sdk/template/azure-template/README.md
Normal file
70
sdk/template/azure-template/README.md
Normal file
@ -0,0 +1,70 @@
|
||||
# Azure Template Package client library for C++
|
||||
|
||||
Azure Template Package client library for C++ (`azure-template`) matches necessary patterns that the development team has established to create a unified sdk written in the C++ programming language. These libraries follow the Azure SDK Design Guidelines for C++.
|
||||
|
||||
The library allows client libraries to expose common functionality in a consistent fashion. Once you learn how to use these APIs in one client library, you will know how to use them in other client libraries.
|
||||
|
||||
## Getting started
|
||||
|
||||
For a rich example of a well formatted readme, please check [here.](https://github.com/Azure/azure-sdk/blob/master/docs/policies/README-TEMPLATE.md) In addition, this is an [example readme](https://github.com/Azure/azure-sdk/blob/master/docs/policies/README-EXAMPLE.md) that should be emulated. Note that the top-level sections in this template align with that of the [template.](https://github.com/Azure/azure-sdk/blob/master/docs/policies/README-TEMPLATE.md)
|
||||
|
||||
# Key concepts
|
||||
|
||||
Bullet point list of your library's main concepts.
|
||||
|
||||
# Examples
|
||||
|
||||
Examples of some of the key concepts for your library.
|
||||
|
||||
# Troubleshooting
|
||||
|
||||
Running into issues? This section should contain details as to what to do there.
|
||||
|
||||
# Next steps
|
||||
|
||||
More sample code should go here, along with links out to the appropriate example tests.
|
||||
|
||||
## Contributing
|
||||
For details on contributing to this repository, see the [contributing guide][azure_sdk_for_cpp_contributing].
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
||||
|
||||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
||||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
### Additional Helpful Links for Contributors
|
||||
Many people all over the world have helped make this project better. You'll want to check out:
|
||||
|
||||
* [What are some good first issues for new contributors to the repo?](https://github.com/azure/azure-sdk-for-cpp/issues?q=is%3Aopen+is%3Aissue+label%3A%22up+for+grabs%22)
|
||||
* [How to build and test your change][azure_sdk_for_cpp_contributing_developer_guide]
|
||||
* [How you can make a change happen!][azure_sdk_for_cpp_contributing_pull_requests]
|
||||
* Frequently Asked Questions (FAQ) and Conceptual Topics in the detailed [Azure SDK for C++ wiki](https://github.com/azure/azure-sdk-for-cpp/wiki).
|
||||
|
||||
<!-- ### Community-->
|
||||
### Reporting security issues and security bugs
|
||||
|
||||
Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) <secure@microsoft.com>. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the [Security TechCenter](https://www.microsoft.com/msrc/faqs-report-an-issue).
|
||||
|
||||
### License
|
||||
|
||||
Azure SDK for C++ is licensed under the [MIT](LICENSE) license.
|
||||
|
||||
<!-- LINKS -->
|
||||
[azure_sdk_for_cpp_contributing]: https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md
|
||||
[azure_sdk_for_cpp_contributing_developer_guide]: https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md#developer-guide
|
||||
[azure_sdk_for_cpp_contributing_pull_requests]: https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md#pull-requests
|
||||
[azure_cli]: https://docs.microsoft.com/cli/azure
|
||||
[azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker
|
||||
[azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry
|
||||
[azure_portal]: https://portal.azure.com
|
||||
[azure_sub]: https://azure.microsoft.com/free/
|
||||
[c_compiler]: https://visualstudio.microsoft.com/vs/features/cplusplus/
|
||||
[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview
|
||||
[cloud_shell_bash]: https://shell.azure.com/bash
|
||||
@ -0,0 +1,15 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Azure { namespace Template {
|
||||
|
||||
class TemplateClient {
|
||||
public:
|
||||
std::string const ClientVersion();
|
||||
};
|
||||
|
||||
}} // namespace Azure::Template
|
||||
34
sdk/template/azure-template/inc/azure/template/version.hpp
Normal file
34
sdk/template/azure-template/inc/azure/template/version.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#define AZURE_TEMPLATE_VERSION_MAJOR 1
|
||||
#define AZURE_TEMPLATE_VERSION_MINOR 0
|
||||
#define AZURE_TEMPLATE_VERSION_PATCH 0
|
||||
#define AZURE_TEMPLATE_VERSION_PRERELEASE "beta.1"
|
||||
|
||||
namespace Azure { namespace Template {
|
||||
|
||||
class Version {
|
||||
public:
|
||||
static constexpr int Major = AZURE_TEMPLATE_VERSION_MAJOR;
|
||||
static constexpr int Minor = AZURE_TEMPLATE_VERSION_MINOR;
|
||||
static constexpr int Patch = AZURE_TEMPLATE_VERSION_PATCH;
|
||||
static std::string const PreRelease;
|
||||
static std::string const VersionString();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}} // namespace Azure::Template
|
||||
|
||||
#undef AZURE_TEMPLATE_VERSION_MAJOR
|
||||
#undef AZURE_TEMPLATE_VERSION_MINOR
|
||||
#undef AZURE_TEMPLATE_VERSION_PATCH
|
||||
#undef AZURE_TEMPLATE_VERSION_PRERELEASE
|
||||
14
sdk/template/azure-template/src/template_client.cpp
Normal file
14
sdk/template/azure-template/src/template_client.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <azure/template/template_client.hpp>
|
||||
#include <azure/template/version.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace Azure::Template;
|
||||
|
||||
std::string const TemplateClient::ClientVersion()
|
||||
{
|
||||
return Version::VersionString();
|
||||
}
|
||||
29
sdk/template/azure-template/src/version.cpp
Normal file
29
sdk/template/azure-template/src/version.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <azure/template/version.hpp>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
using namespace Azure::Template;
|
||||
|
||||
const std::string Version::PreRelease = secret;
|
||||
|
||||
std::string const Azure::Template::Version::VersionString()
|
||||
{
|
||||
static const std::string versionString = [] {
|
||||
std::string version;
|
||||
std::stringstream ss;
|
||||
std::string dot = ".";
|
||||
|
||||
ss << Version::Major << dot << Version::Minor << dot << Version::Patch;
|
||||
|
||||
if (!Version::PreRelease.empty())
|
||||
ss << "-" << Version::PreRelease;
|
||||
|
||||
return ss.str();
|
||||
}();
|
||||
|
||||
return versionString;
|
||||
}
|
||||
|
||||
24
sdk/template/azure-template/test/CMakeLists.txt
Normal file
24
sdk/template/azure-template/test/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
|
||||
project (azure-template-test LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
add_compile_definitions(AZURE_TEST_DATA_PATH="${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable (
|
||||
azure-template-test
|
||||
ut/template_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(azure-template-test PUBLIC Azure::Template)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(azure-template-test PUBLIC /wd6326 /wd26495 /wd26812)
|
||||
endif()
|
||||
|
||||
add_gtest(azure-template-test)
|
||||
|
||||
15
sdk/template/azure-template/test/ut/template_test.cpp
Normal file
15
sdk/template/azure-template/test/ut/template_test.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <azure/template/template_client.hpp>
|
||||
|
||||
using namespace Azure::Template;
|
||||
|
||||
TEST(Template, Basic)
|
||||
{
|
||||
TemplateClient templateClient;
|
||||
|
||||
EXPECT_FALSE(templateClient.ClientVersion().empty());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user