Skip to content

Commit 62c0054

Browse files
Add CRT version check at cmake and runtime
1 parent 475e79d commit 62c0054

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if (LEGACY_BUILD)
7070
option(ENABLE_PROTOCOL_TESTS "Enable protocol tests" OFF)
7171
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)
7272
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)
73-
73+
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)
7474

7575
set(AWS_USER_AGENT_CUSTOMIZATION "" CACHE STRING "User agent extension")
7676
set(AWS_TEST_REGION "US_EAST_1" CACHE STRING "Region to target integration tests against")
@@ -249,6 +249,12 @@ if (LEGACY_BUILD)
249249
include(AwsFindPackage)
250250
set(IN_SOURCE_BUILD OFF)
251251
endif ()
252+
253+
if (ENABLE_CRT_VERSION_CHECK)
254+
include(check_crt_version)
255+
check_crt_version()
256+
endif()
257+
252258
aws_use_package(aws-crt-cpp)
253259
aws_use_package(aws-c-http)
254260
aws_use_package(aws-c-mqtt)

src/aws-cpp-sdk-core/source/Globals.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <aws/core/utils/memory/AWSMemory.h>
1313
#include <aws/auth/auth.h>
1414

15+
#include "aws/crt/Config.h"
16+
1517
namespace Aws
1618
{
1719
static const char TAG[] = "GlobalEnumOverflowContainer";
@@ -52,6 +54,19 @@ namespace Aws
5254
auto crtVersion = g_apiHandle->GetCrtVersion();
5355
AWS_LOGSTREAM_INFO(TAG, "Initialized AWS-CRT-CPP with version "
5456
<< crtVersion.major << "." << crtVersion.minor << "." << crtVersion.patch);
57+
58+
if(crtVersion.major != AWS_CRT_CPP_VERSION_MAJOR ||
59+
crtVersion.minor != AWS_CRT_CPP_VERSION_MINOR ||
60+
crtVersion.patch != AWS_CRT_CPP_VERSION_PATCH)
61+
{
62+
AWS_LOGSTREAM_ERROR(TAG, "AWS-CRT-CPP version mismatch detected.");
63+
AWS_LOGSTREAM_INFO(TAG, "Initialized CRT with version "
64+
<< crtVersion.major << "." << crtVersion.minor << "." << crtVersion.patch << "; "
65+
<< "However, the AWS-SDK-CPP had been built with CRT version: "
66+
<< AWS_CRT_CPP_VERSION_MAJOR << "."
67+
<< AWS_CRT_CPP_VERSION_MINOR << "."
68+
<< AWS_CRT_CPP_VERSION_PATCH << ";");
69+
}
5570
}
5671

5772
void CleanupCrt()

tools/scripts/ops/update_crt.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
"""
99

1010
import os
11+
import re
1112
import shutil
1213
import subprocess
1314
import time
1415

1516
from jinja2 import Environment, select_autoescape
1617

1718
PREFETCH_DEPS_SH_NAME = "prefetch_crt_dependency.sh"
19+
EXPECTED_CRT_VER_CMAKE = "cmake/expected_crt_version.cmake"
20+
CRT_VERSION_F = "VERSION"
1821
CRT_DIR = "./crt/aws-crt-cpp"
1922
GIT_EXE = shutil.which("git")
2023

24+
CRT_VERSION_PATTERN = re.compile("^(?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+).*")
2125

2226
PREFETCH_DEPS_TEMPLATE = \
2327
"""#!/bin/sh
@@ -64,6 +68,18 @@
6468
6569
"""
6670

71+
EXPECTED_CRT_VERSION_TEMPLATE = \
72+
"""# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
73+
# SPDX-License-Identifier: Apache-2.0.
74+
75+
set(EXPECTED_CRT_VERSION_MAJOR {{ t_major }})
76+
set(EXPECTED_CRT_VERSION_MINOR {{ t_minor }})
77+
set(EXPECTED_CRT_VERSION_PATCH {{ t_patch }})
78+
79+
set(EXPECTED_CRT_VERSION_MAJOR ${EXPECTED_CRT_VERSION_MAJOR} PARENT_SCOPE)
80+
set(EXPECTED_CRT_VERSION_MINOR ${EXPECTED_CRT_VERSION_MINOR} PARENT_SCOPE)
81+
set(EXPECTED_CRT_VERSION_PATCH ${EXPECTED_CRT_VERSION_PATCH} PARENT_SCOPE)
82+
"""
6783

6884
def call_git(cwd: str, timeout: int, command: str):
6985
git_cmd = [GIT_EXE]
@@ -114,12 +130,22 @@ def main():
114130
with open(f"{PREFETCH_DEPS_SH_NAME}", mode="w", encoding="utf-8") as prefetch_script_f:
115131
prefetch_script_f.write(rendered_script)
116132

133+
with open(f"{CRT_DIR}/{CRT_VERSION_F}", mode="r", encoding="utf-8") as version_f:
134+
ver_match = CRT_VERSION_PATTERN.match(version_f.read())
135+
cmake_exp_ver_template = jinja2_env.from_string(EXPECTED_CRT_VERSION_TEMPLATE)
136+
rendered_cmake_ver = cmake_exp_ver_template.render(t_major=ver_match.group("major"),
137+
t_minor=ver_match.group("minor"),
138+
t_patch=ver_match.group("patch"))
139+
140+
with open(f"{EXPECTED_CRT_VER_CMAKE}", mode="w", encoding="utf-8") as cmake_f:
141+
cmake_f.write(rendered_cmake_ver)
142+
117143
print(f"CRT submodule is updated to {latest_crt_version}\n"
118-
f"Script {PREFETCH_DEPS_SH_NAME} content is updated.")
144+
f"Scripts {PREFETCH_DEPS_SH_NAME} and {EXPECTED_CRT_VER_CMAKE} are updated.")
119145

120146
print("Don't forget to git add, commit, and push:\n")
121147
print(f" git checkout -b updateCrt/{latest_crt_version} && "
122-
f"git add {CRT_DIR} {PREFETCH_DEPS_SH_NAME} && "
148+
f"git add {CRT_DIR} {PREFETCH_DEPS_SH_NAME} {EXPECTED_CRT_VER_CMAKE} && "
123149
f"git commit -m \"Update CRT to {latest_crt_version}\" && "
124150
f"git push origin updateCrt/{latest_crt_version}")
125151

0 commit comments

Comments
 (0)