diff --git a/CMakeLists.txt b/CMakeLists.txt index 164f1ad479e..162a2b07629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,7 @@ if (LEGACY_BUILD) option(ENABLE_PROTOCOL_TESTS "Enable protocol tests" OFF) option(DISABLE_DNS_REQUIRED_TESTS "Disable unit tests that require DNS lookup to succeed, useful when using a http client that does not perform DNS lookup" OFF) option(AWS_APPSTORE_SAFE "Remove reference to private Apple APIs for AES GCM in Common Crypto. If set to OFF you application will get rejected from the apple app store." OFF) - + option(ENABLE_CRT_VERSION_CHECK "Forces the check of found AWS-CRT-CPP version to match the expected one (only at the SDK build configuration)" ON) set(AWS_USER_AGENT_CUSTOMIZATION "" CACHE STRING "User agent extension") set(AWS_TEST_REGION "US_EAST_1" CACHE STRING "Region to target integration tests against") @@ -249,6 +249,12 @@ if (LEGACY_BUILD) include(AwsFindPackage) set(IN_SOURCE_BUILD OFF) endif () + + if (ENABLE_CRT_VERSION_CHECK) + include(check_crt_version) + check_crt_version() + endif() + aws_use_package(aws-crt-cpp) aws_use_package(aws-c-http) aws_use_package(aws-c-mqtt) diff --git a/cmake/check_crt_version.cmake b/cmake/check_crt_version.cmake new file mode 100644 index 00000000000..be7766fc111 --- /dev/null +++ b/cmake/check_crt_version.cmake @@ -0,0 +1,26 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0. + +function(check_crt_version) + include(expected_crt_version) + + file(READ "${aws-crt-cpp_SOURCE_DIR}/VERSION" CRT_SIMPLE_VERSION) + string(STRIP ${CRT_SIMPLE_VERSION} CRT_SIMPLE_VERSION) + string(REPLACE "." ";" CRT_SIMPLE_VERSION ${CRT_SIMPLE_VERSION}) + list(GET CRT_SIMPLE_VERSION 0 CRT_VERSION_MAJOR) + list(GET CRT_SIMPLE_VERSION 1 CRT_VERSION_MINOR) + list(GET CRT_SIMPLE_VERSION 2 CRT_VERSION_PATCH) + + if(EXPECTED_CRT_VERSION_MAJOR EQUAL CRT_VERSION_MAJOR AND + EXPECTED_CRT_VERSION_MINOR EQUAL CRT_VERSION_MINOR AND + EXPECTED_CRT_VERSION_PATCH EQUAL CRT_VERSION_PATCH) + message(TRACE "AWS-CRT-CPP version matches the expected") + else() + message(FATAL_ERROR "AWS-CRT-CPP version mismatch detected!\n" + "Expected: ${EXPECTED_CRT_VERSION_MAJOR}.${EXPECTED_CRT_VERSION_MINOR}.${EXPECTED_CRT_VERSION_PATCH}, " + "Found: ${CRT_VERSION_MAJOR}.${CRT_VERSION_MINOR}.${CRT_VERSION_PATCH}\n" + "Please use \"git pull --recurse-submodules\" to git pull and update the CRT submodule.\n" + "Or disable this check with \"-DENABLE_CRT_VERSION_CHECK=OFF\"") + endif () + +endfunction(check_crt_version) \ No newline at end of file diff --git a/cmake/expected_crt_version.cmake b/cmake/expected_crt_version.cmake new file mode 100644 index 00000000000..e35f8a341a7 --- /dev/null +++ b/cmake/expected_crt_version.cmake @@ -0,0 +1,10 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0. + +set(EXPECTED_CRT_VERSION_MAJOR 0) +set(EXPECTED_CRT_VERSION_MINOR 32) +set(EXPECTED_CRT_VERSION_PATCH 4) + +set(EXPECTED_CRT_VERSION_MAJOR ${EXPECTED_CRT_VERSION_MAJOR} PARENT_SCOPE) +set(EXPECTED_CRT_VERSION_MINOR ${EXPECTED_CRT_VERSION_MINOR} PARENT_SCOPE) +set(EXPECTED_CRT_VERSION_PATCH ${EXPECTED_CRT_VERSION_PATCH} PARENT_SCOPE) \ No newline at end of file diff --git a/src/aws-cpp-sdk-core/source/Globals.cpp b/src/aws-cpp-sdk-core/source/Globals.cpp index ce81e0f44ef..38dad2d15d2 100644 --- a/src/aws-cpp-sdk-core/source/Globals.cpp +++ b/src/aws-cpp-sdk-core/source/Globals.cpp @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -52,6 +53,19 @@ namespace Aws auto crtVersion = g_apiHandle->GetCrtVersion(); AWS_LOGSTREAM_INFO(TAG, "Initialized AWS-CRT-CPP with version " << crtVersion.major << "." << crtVersion.minor << "." << crtVersion.patch); + + if(crtVersion.major != AWS_CRT_CPP_VERSION_MAJOR || + crtVersion.minor != AWS_CRT_CPP_VERSION_MINOR || + crtVersion.patch != AWS_CRT_CPP_VERSION_PATCH) + { + AWS_LOGSTREAM_ERROR(TAG, "AWS-CRT-CPP version mismatch detected."); + AWS_LOGSTREAM_INFO(TAG, "Initialized CRT with version " + << crtVersion.major << "." << crtVersion.minor << "." << crtVersion.patch << "; " + << "However, the AWS-SDK-CPP had been built with CRT version: " + << AWS_CRT_CPP_VERSION_MAJOR << "." + << AWS_CRT_CPP_VERSION_MINOR << "." + << AWS_CRT_CPP_VERSION_PATCH << ";"); + } } void CleanupCrt() diff --git a/tools/scripts/ops/update_crt.py b/tools/scripts/ops/update_crt.py index d3786af95c9..acc028a513d 100644 --- a/tools/scripts/ops/update_crt.py +++ b/tools/scripts/ops/update_crt.py @@ -8,6 +8,7 @@ """ import os +import re import shutil import subprocess import time @@ -15,9 +16,12 @@ from jinja2 import Environment, select_autoescape PREFETCH_DEPS_SH_NAME = "prefetch_crt_dependency.sh" +EXPECTED_CRT_VER_CMAKE = "cmake/expected_crt_version.cmake" +CRT_VERSION_F = "VERSION" CRT_DIR = "./crt/aws-crt-cpp" GIT_EXE = shutil.which("git") +CRT_VERSION_PATTERN = re.compile("^(?P[0-9]+).(?P[0-9]+).(?P[0-9]+).*") PREFETCH_DEPS_TEMPLATE = \ """#!/bin/sh @@ -64,6 +68,18 @@ """ +EXPECTED_CRT_VERSION_TEMPLATE = \ +"""# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0. + +set(EXPECTED_CRT_VERSION_MAJOR {{ t_major }}) +set(EXPECTED_CRT_VERSION_MINOR {{ t_minor }}) +set(EXPECTED_CRT_VERSION_PATCH {{ t_patch }}) + +set(EXPECTED_CRT_VERSION_MAJOR ${EXPECTED_CRT_VERSION_MAJOR} PARENT_SCOPE) +set(EXPECTED_CRT_VERSION_MINOR ${EXPECTED_CRT_VERSION_MINOR} PARENT_SCOPE) +set(EXPECTED_CRT_VERSION_PATCH ${EXPECTED_CRT_VERSION_PATCH} PARENT_SCOPE) +""" def call_git(cwd: str, timeout: int, command: str): git_cmd = [GIT_EXE] @@ -114,12 +130,22 @@ def main(): with open(f"{PREFETCH_DEPS_SH_NAME}", mode="w", encoding="utf-8") as prefetch_script_f: prefetch_script_f.write(rendered_script) + with open(f"{CRT_DIR}/{CRT_VERSION_F}", mode="r", encoding="utf-8") as version_f: + ver_match = CRT_VERSION_PATTERN.match(version_f.read()) + cmake_exp_ver_template = jinja2_env.from_string(EXPECTED_CRT_VERSION_TEMPLATE) + rendered_cmake_ver = cmake_exp_ver_template.render(t_major=ver_match.group("major"), + t_minor=ver_match.group("minor"), + t_patch=ver_match.group("patch")) + + with open(f"{EXPECTED_CRT_VER_CMAKE}", mode="w", encoding="utf-8") as cmake_f: + cmake_f.write(rendered_cmake_ver) + print(f"CRT submodule is updated to {latest_crt_version}\n" - f"Script {PREFETCH_DEPS_SH_NAME} content is updated.") + f"Scripts {PREFETCH_DEPS_SH_NAME} and {EXPECTED_CRT_VER_CMAKE} are updated.") print("Don't forget to git add, commit, and push:\n") print(f" git checkout -b updateCrt/{latest_crt_version} && " - f"git add {CRT_DIR} {PREFETCH_DEPS_SH_NAME} && " + f"git add {CRT_DIR} {PREFETCH_DEPS_SH_NAME} {EXPECTED_CRT_VER_CMAKE} && " f"git commit -m \"Update CRT to {latest_crt_version}\" && " f"git push origin updateCrt/{latest_crt_version}")