From 2b95d259c20f2dac8fa422a9a115daaf0f229dfe Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 20 Aug 2024 15:52:09 -0700 Subject: [PATCH 01/24] fix bugs for Swift 6 --- Package.swift | 6 ++- aws-common-runtime/aws-c-auth | 2 +- aws-common-runtime/aws-c-cal | 2 +- aws-common-runtime/aws-c-common | 2 +- aws-common-runtime/aws-c-event-stream | 2 +- aws-common-runtime/aws-c-http | 2 +- aws-common-runtime/config/aws/common/config.h | 41 +++---------------- aws-common-runtime/s2n | 2 +- 8 files changed, 17 insertions(+), 42 deletions(-) diff --git a/Package.swift b/Package.swift index d67f7cafb..d84fa7905 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,11 @@ var package = Package(name: "aws-crt-swift", ) let cSettings: [CSetting] = [ - .define("DEBUG_BUILD", .when(configuration: .debug)) + .define("DEBUG_BUILD", .when(configuration: .debug)), +/* Disable Intel VTune tracing API here since aws-crt-swift doesn't use CMake */ + .define("INTEL_NO_ITTNOTIFY_API"), +/* Don't use APIs forbidden by App Stores (e.g. non-public system APIs) */ + .defien("AWS_APPSTORE_SAFE"), ] ////////////////////////////////////////////////////////////////////// diff --git a/aws-common-runtime/aws-c-auth b/aws-common-runtime/aws-c-auth index d78952529..52bf59161 160000 --- a/aws-common-runtime/aws-c-auth +++ b/aws-common-runtime/aws-c-auth @@ -1 +1 @@ -Subproject commit d7895252915259d037f10be223369eb99e837471 +Subproject commit 52bf591613d1a001c43ec99af7376f871759c5fe diff --git a/aws-common-runtime/aws-c-cal b/aws-common-runtime/aws-c-cal index bc0d71b66..77ca3aea8 160000 --- a/aws-common-runtime/aws-c-cal +++ b/aws-common-runtime/aws-c-cal @@ -1 +1 @@ -Subproject commit bc0d71b66deea9e1a2d3a073c9f1ece9286b9e60 +Subproject commit 77ca3aea879bc768082fe7ec715adcde8e98c332 diff --git a/aws-common-runtime/aws-c-common b/aws-common-runtime/aws-c-common index 2add521b7..672cc0032 160000 --- a/aws-common-runtime/aws-c-common +++ b/aws-common-runtime/aws-c-common @@ -1 +1 @@ -Subproject commit 2add521b78d69f9f043a701232e751f43cf123e6 +Subproject commit 672cc0032eb28d69fbdd22c9463253c89d7a6f30 diff --git a/aws-common-runtime/aws-c-event-stream b/aws-common-runtime/aws-c-event-stream index 1a70c50f7..1b3825fc9 160000 --- a/aws-common-runtime/aws-c-event-stream +++ b/aws-common-runtime/aws-c-event-stream @@ -1 +1 @@ -Subproject commit 1a70c50f78a6e706f1f91a4ed138478271b6d9d3 +Subproject commit 1b3825fc9cae2e9c7ed7479ee5d354d52ebdf7a0 diff --git a/aws-common-runtime/aws-c-http b/aws-common-runtime/aws-c-http index a2fb16c43..4e74ab1e3 160000 --- a/aws-common-runtime/aws-c-http +++ b/aws-common-runtime/aws-c-http @@ -1 +1 @@ -Subproject commit a2fb16c431152bd677093f9910f405a37533ad5a +Subproject commit 4e74ab1e3702763e0b87bd1752f5a37c2f0400ac diff --git a/aws-common-runtime/config/aws/common/config.h b/aws-common-runtime/config/aws/common/config.h index 7fc013617..4208ebc8b 100644 --- a/aws-common-runtime/config/aws/common/config.h +++ b/aws-common-runtime/config/aws/common/config.h @@ -1,48 +1,19 @@ -#ifdef __APPLE__ -# include -#endif - -#ifndef AWS_COMMON_CONFIG_H -# define AWS_COMMON_CONFIG_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ + +#ifndef AWS_COMMON_CONFIG_H +#define AWS_COMMON_CONFIG_H /* * This header exposes compiler feature test results determined during cmake * configure time to inline function implementations. The macros defined here * should be considered to be an implementation detail, and can change at any * time. */ -# if TARGET_OS_IPHONE -# define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS -# define AWS_HAVE_GCC_INLINE_ASM -/* #undef AWS_HAVE_MSVC_MULX */ -# define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H -# elif TARGET_OS_SIMULATOR -# define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS -# define AWS_HAVE_GCC_INLINE_ASM -/* #undef AWS_HAVE_MSVC_MULX */ -# define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H -# elif TARGET_OS_MAC -# define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS -# define AWS_HAVE_GCC_INLINE_ASM -/* #undef AWS_HAVE_MSVC_MULX */ -# define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H -# endif -#else -# define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS -# define AWS_HAVE_GCC_INLINE_ASM -/* #undef AWS_HAVE_MSVC_MULX */ -# define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H -#endif +#define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS +#define AWS_HAVE_GCC_INLINE_ASM #define AWS_UNSTABLE_TESTING_API 1 - #define AWS_AFFINITY_METHOD 0 - #define AWS_HAVE_EXECINFO 1 -/* Disable Intel VTune tracing API here since aws-crt-swift doesn't use CMake */ -#define INTEL_NO_ITTNOTIFY_API - -/* Don't use APIs forbidden by App Stores (e.g. non-public system APIs) */ -#define AWS_APPSTORE_SAFE 1 +#endif diff --git a/aws-common-runtime/s2n b/aws-common-runtime/s2n index 138e3ece9..87f4a0585 160000 --- a/aws-common-runtime/s2n +++ b/aws-common-runtime/s2n @@ -1 +1 @@ -Subproject commit 138e3ece9e457c2f824a85b63095737f30d624a9 +Subproject commit 87f4a0585dc3056433f193b9305f587cff239be3 From b87740237072ca009fa2ccc5560f89a8fd56c9ff Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 20 Aug 2024 15:53:15 -0700 Subject: [PATCH 02/24] fix typo --- Package.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index d84fa7905..e366c5911 100644 --- a/Package.swift +++ b/Package.swift @@ -16,10 +16,10 @@ var package = Package(name: "aws-crt-swift", let cSettings: [CSetting] = [ .define("DEBUG_BUILD", .when(configuration: .debug)), -/* Disable Intel VTune tracing API here since aws-crt-swift doesn't use CMake */ + // Disable Intel VTune tracing API here since aws-crt-swift doesn't use CMake .define("INTEL_NO_ITTNOTIFY_API"), -/* Don't use APIs forbidden by App Stores (e.g. non-public system APIs) */ - .defien("AWS_APPSTORE_SAFE"), + // Don't use APIs forbidden by App Stores (e.g. non-public system APIs) + .define("AWS_APPSTORE_SAFE"), ] ////////////////////////////////////////////////////////////////////// From f3bbdaf933208462eb3a99aff1c1c6d2b40a9a0d Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 20 Aug 2024 16:09:33 -0700 Subject: [PATCH 03/24] fix for apple os --- aws-common-runtime/config/aws/common/config.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aws-common-runtime/config/aws/common/config.h b/aws-common-runtime/config/aws/common/config.h index 4208ebc8b..cc464d8ef 100644 --- a/aws-common-runtime/config/aws/common/config.h +++ b/aws-common-runtime/config/aws/common/config.h @@ -1,10 +1,13 @@ +#ifdef __APPLE__ +# include +#endif + +#ifndef AWS_COMMON_CONFIG_H +# define AWS_COMMON_CONFIG_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ - -#ifndef AWS_COMMON_CONFIG_H -#define AWS_COMMON_CONFIG_H /* * This header exposes compiler feature test results determined during cmake * configure time to inline function implementations. The macros defined here @@ -13,6 +16,9 @@ */ #define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS #define AWS_HAVE_GCC_INLINE_ASM +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR || TARGET_OS_MAC +# define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H +#endif #define AWS_UNSTABLE_TESTING_API 1 #define AWS_AFFINITY_METHOD 0 #define AWS_HAVE_EXECINFO 1 From 06ca2376a58aeadd0cfe9764370db12fe53848f7 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 09:12:04 -0700 Subject: [PATCH 04/24] refactor config --- aws-common-runtime/config/aws/common/config.h | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/aws-common-runtime/config/aws/common/config.h b/aws-common-runtime/config/aws/common/config.h index cc464d8ef..8c325dcbe 100644 --- a/aws-common-runtime/config/aws/common/config.h +++ b/aws-common-runtime/config/aws/common/config.h @@ -1,25 +1,27 @@ -#ifdef __APPLE__ -# include -#endif - -#ifndef AWS_COMMON_CONFIG_H -# define AWS_COMMON_CONFIG_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ + +#ifndef AWS_COMMON_CONFIG_H +#define AWS_COMMON_CONFIG_H /* * This header exposes compiler feature test results determined during cmake * configure time to inline function implementations. The macros defined here * should be considered to be an implementation detail, and can change at any * time. */ +#ifdef __APPLE__ +/* This is a trick to skip OpenSSL header on Apple platforms since Swift Package Manager is not smart enough to exclude + * some headers. + */ +# define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H +#endif #define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS #define AWS_HAVE_GCC_INLINE_ASM -#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR || TARGET_OS_MAC -# define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H -#endif + #define AWS_UNSTABLE_TESTING_API 1 #define AWS_AFFINITY_METHOD 0 #define AWS_HAVE_EXECINFO 1 + #endif From a7935a0dd312b20819ec718f6431b059234de2ba Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 09:36:43 -0700 Subject: [PATCH 05/24] update exlcudes --- Package.swift | 5 ++--- aws-common-runtime/aws-c-compression | 2 +- aws-common-runtime/config/aws/common/config.h | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index e366c5911..b82571f43 100644 --- a/Package.swift +++ b/Package.swift @@ -2,7 +2,7 @@ import PackageDescription let excludesFromAll = ["tests", "cmake", "CONTRIBUTING.md", - "LICENSE", "format-check.sh", "NOTICE", "builder.json", + "LICENSE", "format-check.py", "NOTICE", "builder.json", "CMakeLists.txt", "README.md"] var packageTargets: [Target] = [] @@ -112,7 +112,7 @@ packageTargets.append(.target( /// aws-c-io ////////////////////////////////////////////////////////////////////// var ioDependencies: [Target.Dependency] = ["AwsCCommon", "AwsCCal"] -var awsCIoPlatformExcludes = ["docs", "CODE_OF_CONDUCT.md", "codebuild", "PKCS11.md", "THIRD-PARTY-LICENSES.txt", +var awsCIoPlatformExcludes = ["docs", "CODE_OF_CONDUCT.md", "codebuild", "PKCS11.md", "source/pkcs11/v2.40"] + excludesFromAll var cSettingsIO = cSettings @@ -144,7 +144,6 @@ var awsCChecksumsExcludes = [ "LICENSE", "builder.json", "README.md", - "format-check.sh", "cmake", "tests"] diff --git a/aws-common-runtime/aws-c-compression b/aws-common-runtime/aws-c-compression index ea1d421a4..f36d01672 160000 --- a/aws-common-runtime/aws-c-compression +++ b/aws-common-runtime/aws-c-compression @@ -1 +1 @@ -Subproject commit ea1d421a421ad83a540309a94c38d50b6a5d836b +Subproject commit f36d01672d61e49d96a777870d456f66fa391cd4 diff --git a/aws-common-runtime/config/aws/common/config.h b/aws-common-runtime/config/aws/common/config.h index 8c325dcbe..7d00728c9 100644 --- a/aws-common-runtime/config/aws/common/config.h +++ b/aws-common-runtime/config/aws/common/config.h @@ -17,8 +17,6 @@ */ # define AWS_C_CAL_OPENSSLCRYPTO_COMMON_H #endif -#define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS -#define AWS_HAVE_GCC_INLINE_ASM #define AWS_UNSTABLE_TESTING_API 1 #define AWS_AFFINITY_METHOD 0 From 485f21e79f9df3ae669d580e9b0912697d6b8b84 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 09:37:31 -0700 Subject: [PATCH 06/24] s2n excludes --- Package.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Package.swift b/Package.swift index b82571f43..ee34d3be2 100644 --- a/Package.swift +++ b/Package.swift @@ -88,7 +88,6 @@ awsCCalPlatformExcludes.append("source/unix") // add pq-crypto back after adding in platform and chipset detection let s2nExcludes = ["bin", "codebuild", "coverage", "docker-images", "docs", "lib", "pq-crypto/kyber_r3", - "pq-crypto/README.md", "pq-crypto/Makefile", "pq-crypto/s2n_pq_asm.mk", "libcrypto-build", "scram", "s2n.mk", "Makefile", "stuffer/Makefile", "crypto/Makefile", "tls/Makefile", "utils/Makefile", "error/Makefile", "tls/extensions/Makefile", From 1b0852318e159c8e9ea4df08cc161d6ed50d7905 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 09:38:48 -0700 Subject: [PATCH 07/24] another exlude --- Package.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index ee34d3be2..b34f4dcd7 100644 --- a/Package.swift +++ b/Package.swift @@ -85,9 +85,8 @@ awsCCalPlatformExcludes.append("source/unix") /// s2n-tls ////////////////////////////////////////////////////////////////////// #if os(Linux) -// add pq-crypto back after adding in platform and chipset detection let s2nExcludes = ["bin", "codebuild", "coverage", "docker-images", - "docs", "lib", "pq-crypto/kyber_r3", + "docs", "lib", "libcrypto-build", "scram", "s2n.mk", "Makefile", "stuffer/Makefile", "crypto/Makefile", "tls/Makefile", "utils/Makefile", "error/Makefile", "tls/extensions/Makefile", From 1b32200fdc22d4bd3d05af1186cb12a44466d580 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 09:40:18 -0700 Subject: [PATCH 08/24] disable trailing comma warning --- .swiftlint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 8f0fcb44f..fe0783153 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -16,7 +16,8 @@ disabled_rules: - file_length - syntactic_sugar - unused_capture_list - - blanket_disable_command + - blanket_disable_command. + - trailing_comma opt_in_rules: - empty_count From de8039ed061326f1ff0d2efff85f7ddee386c88e Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 09:40:44 -0700 Subject: [PATCH 09/24] remove dot --- .swiftlint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index fe0783153..bb0848844 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -16,7 +16,7 @@ disabled_rules: - file_length - syntactic_sugar - unused_capture_list - - blanket_disable_command. + - blanket_disable_command - trailing_comma opt_in_rules: From 0420db4ee6d72c30c7c9a7dfe3ac3e7280115663 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 10:05:40 -0700 Subject: [PATCH 10/24] fix creds tests --- Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt | 3 +-- .../auth/CredentialsProviderTests.swift | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt b/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt index 2eeb45d9a..f8d07bff4 100644 --- a/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt +++ b/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt @@ -1,9 +1,8 @@ [default] aws_access_key_id = default_access_key_id aws_secret_access_key = default_secret_access_key +[profile process] credential_process = echo '{"Version": 1, "AccessKeyId": "AccessKey123", "SecretAccessKey": "SecretAccessKey123", "SessionToken": "SessionToken123","Expiration":"2020-02-25T06:03:31Z"}' -s3 = - max_concurrent_requests = 20 [profile crt_user] aws_access_key_id = example_access_key_id aws_secret_access_key = example_secret_access_key diff --git a/Test/AwsCommonRuntimeKitTests/auth/CredentialsProviderTests.swift b/Test/AwsCommonRuntimeKitTests/auth/CredentialsProviderTests.swift index ef95cbc85..f8bc6adfb 100644 --- a/Test/AwsCommonRuntimeKitTests/auth/CredentialsProviderTests.swift +++ b/Test/AwsCommonRuntimeKitTests/auth/CredentialsProviderTests.swift @@ -133,7 +133,8 @@ class CredentialsProviderTests: XCBaseTestCase { do { let provider = try CredentialsProvider(source: .process( fileBasedConfiguration: FileBasedConfiguration( - configFilePath: Bundle.module.path(forResource: "example_profile", ofType: "txt")!), + configFilePath: Bundle.module.path(forResource: "example_profile", ofType: "txt")!), + profileFileNameOverride: "process", shutdownCallback: getShutdownCallback())) let credentials = try await provider.getCredentials() XCTAssertNotNil(credentials) From 2c2ad5f4e94ceb3e250a799305d7e165cf4d4af7 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 10:13:33 -0700 Subject: [PATCH 11/24] fix profile again --- Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt b/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt index f8d07bff4..bfe634507 100644 --- a/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt +++ b/Test/AwsCommonRuntimeKitTests/Resources/example_profile.txt @@ -1,8 +1,12 @@ [default] aws_access_key_id = default_access_key_id aws_secret_access_key = default_secret_access_key +s3 = + max_concurrent_requests = 20 + [profile process] credential_process = echo '{"Version": 1, "AccessKeyId": "AccessKey123", "SecretAccessKey": "SecretAccessKey123", "SessionToken": "SessionToken123","Expiration":"2020-02-25T06:03:31Z"}' + [profile crt_user] aws_access_key_id = example_access_key_id aws_secret_access_key = example_secret_access_key From ae1aad1d034ca8562473d60a9e840d0eb52dca33 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 10:49:47 -0700 Subject: [PATCH 12/24] fix elastic curl --- Source/Elasticurl/Elasticurl.swift | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Source/Elasticurl/Elasticurl.swift b/Source/Elasticurl/Elasticurl.swift index 29e6e20f9..57a623687 100644 --- a/Source/Elasticurl/Elasticurl.swift +++ b/Source/Elasticurl/Elasticurl.swift @@ -276,22 +276,6 @@ struct Elasticurl { } httpRequest.addHeaders(headers: headers) - let onResponse: HTTPRequestOptions.OnResponse = { _, headers in - for header in headers { - print(header.name + " : " + header.value) - } - } - - let onBody: HTTPRequestOptions.OnIncomingBody = { bodyChunk in - writeData(data: bodyChunk) - } - - let onComplete: HTTPRequestOptions.OnStreamComplete = { result in - print(result) - - semaphore.signal() - } - let httpClientOptions = HTTPClientConnectionOptions(clientBootstrap: bootstrap, hostName: context.url.host!, initialWindowSize: Int.max, From f776ce27fc88d4da924158e89e3337e8c6a84ba5 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 10:51:48 -0700 Subject: [PATCH 13/24] fix elastic curl --- Source/Elasticurl/Elasticurl.swift | 61 +++++++++++++++++++----------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/Source/Elasticurl/Elasticurl.swift b/Source/Elasticurl/Elasticurl.swift index 57a623687..63debb72b 100644 --- a/Source/Elasticurl/Elasticurl.swift +++ b/Source/Elasticurl/Elasticurl.swift @@ -1,9 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0. +import _Concurrency import AwsCommonRuntimeKit import Foundation -import _Concurrency // swiftlint:disable cyclomatic_complexity function_body_length struct Context { @@ -15,16 +15,15 @@ struct Context { public var certificate: String? public var privateKey: String? public var connectTimeout: Int = 3000 - public var headers: [String: String] = [String: String]() + public var headers: [String: String] = .init() public var includeHeaders: Bool = false public var outputFileName: String? public var traceFile: String? public var insecure: Bool = false - public var url: URL = URL(fileURLWithPath: "") + public var url: URL = .init(fileURLWithPath: "") public var data: Data? public var alpnList: [String] = [] public var outputStream = FileHandle.standardOutput - } @main @@ -33,7 +32,6 @@ struct Elasticurl { private static var context = Context() static func parseArguments() { - let optionString = "a:b:c:e:f:H:d:g:j:l:m:M:GPHiko:t:v:VwWh" let options = [ElasticurlOptions.caCert.rawValue, ElasticurlOptions.caPath.rawValue, @@ -100,7 +98,6 @@ struct Elasticurl { } if let dataFilePath = argumentsDict["g"] as? String { - guard let url = URL(string: dataFilePath) else { print("path to data file is incorrect or does not exist") exit(-1) @@ -161,7 +158,7 @@ struct Elasticurl { context.alpnList.append("h2") } - if argumentsDict["w"] == nil && argumentsDict["W"] == nil { + if argumentsDict["w"] == nil, argumentsDict["W"] == nil { context.alpnList.append("h2") context.alpnList.append("http/1.1") } @@ -173,7 +170,8 @@ struct Elasticurl { // make sure a url was given before we do anything else guard let urlString = CommandLine.arguments.last, - let url = URL(string: urlString) else { + let url = URL(string: urlString) + else { print("Invalid URL: \(CommandLine.arguments.last!)") exit(-1) } @@ -258,8 +256,6 @@ struct Elasticurl { let socketOptions = SocketOptions(socketType: .stream) - let semaphore = DispatchSemaphore(value: 0) - var stream: HTTPStream? let path = context.url.path == "" ? "/" : context.url.path let httpRequest: HTTPRequest = try HTTPRequest(method: context.verb, path: path) @@ -286,21 +282,40 @@ struct Elasticurl { monitoringOptions: nil) let connectionManager = try HTTPClientConnectionManager(options: httpClientOptions) - do { - let connection = try await connectionManager.acquireConnection() - let requestOptions = HTTPRequestOptions(request: httpRequest, - onResponse: onResponse, - onIncomingBody: onBody, - onStreamComplete: onComplete) - stream = try connection.makeRequest(requestOptions: requestOptions) - try stream!.activate() - - } catch { - print("connection has shut down with error: \(error.localizedDescription)" ) - semaphore.signal() + let connection = try await connectionManager.acquireConnection() + try await withCheckedThrowingContinuation { continuation in + let onResponse: HTTPRequestOptions.OnResponse = { _, headers in + for header in headers { + print(header.name + " : " + header.value) + } + } + + let onBody: HTTPRequestOptions.OnIncomingBody = { bodyChunk in + writeData(data: bodyChunk) + } + + let onComplete: HTTPRequestOptions.OnStreamComplete = { result in + switch result { + case let .success(status): + print("response status:\(status)") + continuation.resume(returning: ()) + case let .failure(error): + continuation.resume(throwing: error) + } + } + + do { + let requestOptions = HTTPRequestOptions(request: httpRequest, + onResponse: onResponse, + onIncomingBody: onBody, + onStreamComplete: onComplete) + stream = try connection.makeRequest(requestOptions: requestOptions) + try stream!.activate() + } catch { + continuation.resume(throwing: error) + } } - semaphore.wait() exit(EXIT_SUCCESS) } catch let err { showHelp() From de5eee6a7c64cf1040b39c1077a4ff7f0c249088 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 10:56:30 -0700 Subject: [PATCH 14/24] filebased test fix --- .../sdkutils/FileBasedConfigurationTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/AwsCommonRuntimeKitTests/sdkutils/FileBasedConfigurationTests.swift b/Test/AwsCommonRuntimeKitTests/sdkutils/FileBasedConfigurationTests.swift index 62513eaf6..2a69e9254 100644 --- a/Test/AwsCommonRuntimeKitTests/sdkutils/FileBasedConfigurationTests.swift +++ b/Test/AwsCommonRuntimeKitTests/sdkutils/FileBasedConfigurationTests.swift @@ -13,7 +13,7 @@ class FileBasedConfigurationTests: XCBaseTestCase { let fileBasedConfiguration = try FileBasedConfiguration(configFilePath: profilePath, credentialsFilePath: configPath) XCTAssertNotNil(fileBasedConfiguration) let defaultSection = fileBasedConfiguration.getSection(name: "default", sectionType: .profile)! - XCTAssertEqual(defaultSection.propertyCount, 4) + XCTAssertEqual(defaultSection.propertyCount, 3) let property = defaultSection.getProperty(name: "aws_access_key_id")! XCTAssertEqual("accessKey", property.value) From 49860d455876625876113cb9f770bffaa44c10c6 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 11:14:07 -0700 Subject: [PATCH 15/24] fix creds provider --- .../auth/credentials/CredentialsProvider.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift index 934017aed..88620d0b2 100644 --- a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift +++ b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift @@ -1,5 +1,4 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0. +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0. import AwsCAuth import AwsCIo @@ -570,6 +569,10 @@ private func onGetCredentials(credentials: OpaquePointer?, continuationCore.continuation.resume(returning: Credentials(rawValue: credentials!)) } +struct SendablePointer: @unchecked Sendable { + let pointer: UnsafeMutableRawPointer +} + private func getCredentialsDelegateFn(_ delegatePtr: UnsafeMutableRawPointer!, _ callbackFn: (@convention(c) ( OpaquePointer?, @@ -579,14 +582,15 @@ private func getCredentialsDelegateFn(_ delegatePtr: UnsafeMutableRawPointer!, let delegate = Unmanaged> .fromOpaque(delegatePtr) .takeUnretainedValue().contents + let userData = SendablePointer(pointer: userData); Task { do { let credentials = try await delegate.getCredentials() - callbackFn(credentials.rawValue, AWS_OP_SUCCESS, userData) + callbackFn(credentials.rawValue, AWS_OP_SUCCESS, userData.pointer) } catch CommonRunTimeError.crtError(let crtError) { - callbackFn(nil, crtError.code, userData) + callbackFn(nil, crtError.code, userData.pointer) } catch { - callbackFn(nil, Int32(AWS_AUTH_CREDENTIALS_PROVIDER_DELEGATE_FAILURE.rawValue), userData) + callbackFn(nil, Int32(AWS_AUTH_CREDENTIALS_PROVIDER_DELEGATE_FAILURE.rawValue), userData.pointer) } } return AWS_OP_SUCCESS From 03096507743351de345dbd85194f1e3d5f555f6c Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 11:16:44 -0700 Subject: [PATCH 16/24] comment --- .../auth/credentials/CredentialsProvider.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift index 88620d0b2..31ec0836f 100644 --- a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift +++ b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift @@ -569,6 +569,9 @@ private func onGetCredentials(credentials: OpaquePointer?, continuationCore.continuation.resume(returning: Credentials(rawValue: credentials!)) } +// We need to share this pointer to C in a task block but Swift compiler complains +// that Pointer does not conform to Sendable. Wrap the pointer in a @unchecked Sendable block +// for Swift compiler to stop complaining. struct SendablePointer: @unchecked Sendable { let pointer: UnsafeMutableRawPointer } From e3d3939c9f62d61dde05470b50c46396e6aa081f Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 11:28:46 -0700 Subject: [PATCH 17/24] fix ; --- .../auth/credentials/CredentialsProvider.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift index 31ec0836f..c4d3f1591 100644 --- a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift +++ b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift @@ -585,7 +585,7 @@ private func getCredentialsDelegateFn(_ delegatePtr: UnsafeMutableRawPointer!, let delegate = Unmanaged> .fromOpaque(delegatePtr) .takeUnretainedValue().contents - let userData = SendablePointer(pointer: userData); + let userData = SendablePointer(pointer: userData) Task { do { let credentials = try await delegate.getCredentials() From ee7859184c6e8349c7882e45f6217bfbc93940e3 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 21 Aug 2024 11:29:49 -0700 Subject: [PATCH 18/24] fix copy --- .../auth/credentials/CredentialsProvider.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift index c4d3f1591..ce2da756c 100644 --- a/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift +++ b/Source/AwsCommonRuntimeKit/auth/credentials/CredentialsProvider.swift @@ -1,4 +1,5 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0. +// Copyright Amazon.com, Inc. or its affiliates. +// All Rights Reserved. SPDX-License-Identifier: Apache-2.0. import AwsCAuth import AwsCIo From 60a8abe17b0c17bf719a5ed2e07479492aa3d2ab Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 9 Sep 2024 10:11:09 -0700 Subject: [PATCH 19/24] fix logger --- Package.swift | 1 + .../crt/CommonRuntimeError.swift | 8 ++- Source/AwsCommonRuntimeKit/crt/Logger.swift | 62 ++++++++++++------- Source/Elasticurl/Elasticurl.swift | 6 +- .../XCBaseTestCase.swift | 2 +- aws-common-runtime/aws-c-auth | 2 +- aws-common-runtime/aws-c-cal | 2 +- aws-common-runtime/aws-c-common | 2 +- aws-common-runtime/aws-c-compression | 2 +- aws-common-runtime/aws-c-event-stream | 2 +- aws-common-runtime/aws-c-http | 2 +- aws-common-runtime/aws-checksums | 2 +- aws-common-runtime/s2n | 2 +- 13 files changed, 57 insertions(+), 38 deletions(-) diff --git a/Package.swift b/Package.swift index d67f7cafb..9bd8e172c 100644 --- a/Package.swift +++ b/Package.swift @@ -136,6 +136,7 @@ awsCIoPlatformExcludes.append("source/s2n") /// aws-c-checksums ////////////////////////////////////////////////////////////////////// var awsCChecksumsExcludes = [ + "bin", "CMakeLists.txt", "LICENSE", "builder.json", diff --git a/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift b/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift index 2441ebc90..4e5c6817b 100644 --- a/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift +++ b/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift @@ -13,13 +13,17 @@ public struct CRTError: Equatable { public let message: String public let name: String - public init(code: T) { + public init(code: T, context: String? = nil) { if code > INT32_MAX || code <= 0 { self.code = Int32(AWS_ERROR_UNKNOWN.rawValue) } else { self.code = Int32(code) } - self.message = String(cString: aws_error_str(self.code)) + var message = String(cString: aws_error_str(self.code)) + if let context { + message += ". " + context; + } + self.message = message self.name = String(cString: aws_error_name(self.code)) } diff --git a/Source/AwsCommonRuntimeKit/crt/Logger.swift b/Source/AwsCommonRuntimeKit/crt/Logger.swift index a456e1ce6..bf9399a7e 100644 --- a/Source/AwsCommonRuntimeKit/crt/Logger.swift +++ b/Source/AwsCommonRuntimeKit/crt/Logger.swift @@ -2,38 +2,52 @@ // SPDX-License-Identifier: Apache-2.0. import AwsCCommon -var logger: aws_logger? +import Foundation + +public enum LogTarget { + case standardOutput + case standardError + case filePath(String) +} public struct Logger { - public static func initialize(pipe: UnsafeMutablePointer?, level: LogLevel) { - // Clean up the logger if it was previously initialized - if var logger = logger { - aws_logger_clean_up(&logger) - aws_logger_set(nil) + private static var logger: aws_logger? = nil + private static let lock = NSLock() + + /// Initializes the CRT logger based on the specified log target and log level. The CRT logger must be only initialized once in your application. Initializing the logger multiple times is not supported. + /// - Parameters: + /// - target: The logging target, which can be standard output, standard error, or a custom file path. + /// - level: The logging level, represented by the `LogLevel` enum. + /// - Throws: CommonRunTimeError.crtException + public static func initialize(target: LogTarget, level: LogLevel) throws { + lock.lock() + defer { lock.unlock() } + + // Check if the logger is already initialized + guard logger == nil else { + throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_UNSUPPORTED_OPERATION.rawValue, context: "Initializing the CRT Logger multiple times is not supported.")) } + + // Initialize the logger logger = aws_logger() var options = aws_logger_standard_options() options.level = level.rawValue - options.file = pipe - aws_logger_init_standard(&logger!, allocator.rawValue, &options) - aws_logger_set(&logger!) - } - public static func initilize(filePath: String, level: LogLevel) { - // Clean up the logger if it was previously initialized - if var logger = logger { - aws_logger_clean_up(&logger) - aws_logger_set(nil) - } - logger = aws_logger() - - filePath.withCString { cFilePath in - var options = aws_logger_standard_options() - options.level = level.rawValue - options.filename = cFilePath - aws_logger_init_standard(&logger!, allocator.rawValue, &options) - aws_logger_set(&logger!) + // Set options based on the logging target + switch target { + case .standardOutput: + options.file = stdout + case .standardError: + options.file = stderr + case .filePath(let filePath): + filePath.withCString { cFilePath in + options.filename = cFilePath + } } + + // Initialize and set the logger + aws_logger_init_standard(&logger!, allocator.rawValue, &options) + aws_logger_set(&logger!) } } diff --git a/Source/Elasticurl/Elasticurl.swift b/Source/Elasticurl/Elasticurl.swift index 29e6e20f9..464dc8441 100644 --- a/Source/Elasticurl/Elasticurl.swift +++ b/Source/Elasticurl/Elasticurl.swift @@ -1,4 +1,4 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.elastic // SPDX-License-Identifier: Apache-2.0. import AwsCommonRuntimeKit @@ -222,10 +222,10 @@ struct Elasticurl { createOutputFile() if let traceFile = context.traceFile { print("enable logging with trace file") - Logger.initilize(filePath: traceFile, level: context.logLevel) + try! Logger.initialize(target: .filePath(traceFile), level: context.logLevel) } else { print("enable logging with stdout") - Logger.initialize(pipe: stdout, level: context.logLevel) + try! Logger.initialize(target: .standardOutput, level: context.logLevel) } await run() diff --git a/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift b/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift index fd2c7cdfd..d37d33872 100644 --- a/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift +++ b/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift @@ -13,7 +13,7 @@ class XCBaseTestCase: XCTestCase { // XCode currently lacks a way to enable logs exclusively for failed tests only. // To prevent log spamming, we use `error` log level to only print error message. // We should update this once a more efficient log processing method becomes available. - Logger.initialize(pipe: stdout, level: .error) + try! Logger.initialize(target: .standardOutput, level: .error) // Override the allocator with tracing allocator allocator = tracingAllocator.rawValue diff --git a/aws-common-runtime/aws-c-auth b/aws-common-runtime/aws-c-auth index d78952529..e930f1a64 160000 --- a/aws-common-runtime/aws-c-auth +++ b/aws-common-runtime/aws-c-auth @@ -1 +1 @@ -Subproject commit d7895252915259d037f10be223369eb99e837471 +Subproject commit e930f1a64cb3d6b13dbd89c5c9badc5d9d3de1c3 diff --git a/aws-common-runtime/aws-c-cal b/aws-common-runtime/aws-c-cal index bc0d71b66..2cb1d2eac 160000 --- a/aws-common-runtime/aws-c-cal +++ b/aws-common-runtime/aws-c-cal @@ -1 +1 @@ -Subproject commit bc0d71b66deea9e1a2d3a073c9f1ece9286b9e60 +Subproject commit 2cb1d2eac925e2dbc45025eb89af82bd790c23a0 diff --git a/aws-common-runtime/aws-c-common b/aws-common-runtime/aws-c-common index 2add521b7..b9959f592 160000 --- a/aws-common-runtime/aws-c-common +++ b/aws-common-runtime/aws-c-common @@ -1 +1 @@ -Subproject commit 2add521b78d69f9f043a701232e751f43cf123e6 +Subproject commit b9959f5922a4b969beab8f0b99aa0b34bc9ee55c diff --git a/aws-common-runtime/aws-c-compression b/aws-common-runtime/aws-c-compression index ea1d421a4..f36d01672 160000 --- a/aws-common-runtime/aws-c-compression +++ b/aws-common-runtime/aws-c-compression @@ -1 +1 @@ -Subproject commit ea1d421a421ad83a540309a94c38d50b6a5d836b +Subproject commit f36d01672d61e49d96a777870d456f66fa391cd4 diff --git a/aws-common-runtime/aws-c-event-stream b/aws-common-runtime/aws-c-event-stream index 1a70c50f7..1b3825fc9 160000 --- a/aws-common-runtime/aws-c-event-stream +++ b/aws-common-runtime/aws-c-event-stream @@ -1 +1 @@ -Subproject commit 1a70c50f78a6e706f1f91a4ed138478271b6d9d3 +Subproject commit 1b3825fc9cae2e9c7ed7479ee5d354d52ebdf7a0 diff --git a/aws-common-runtime/aws-c-http b/aws-common-runtime/aws-c-http index a2fb16c43..4e74ab1e3 160000 --- a/aws-common-runtime/aws-c-http +++ b/aws-common-runtime/aws-c-http @@ -1 +1 @@ -Subproject commit a2fb16c431152bd677093f9910f405a37533ad5a +Subproject commit 4e74ab1e3702763e0b87bd1752f5a37c2f0400ac diff --git a/aws-common-runtime/aws-checksums b/aws-common-runtime/aws-checksums index aac442a2d..779b5f350 160000 --- a/aws-common-runtime/aws-checksums +++ b/aws-common-runtime/aws-checksums @@ -1 +1 @@ -Subproject commit aac442a2dbbb5e72d0a3eca8313cf65e7e1cac2f +Subproject commit 779b5f350eed7fb784bb3c6700b7532e3fdd84ff diff --git a/aws-common-runtime/s2n b/aws-common-runtime/s2n index 138e3ece9..08d413a0b 160000 --- a/aws-common-runtime/s2n +++ b/aws-common-runtime/s2n @@ -1 +1 @@ -Subproject commit 138e3ece9e457c2f824a85b63095737f30d624a9 +Subproject commit 08d413a0b9b3226e775a38f04e3cf02230cc97c4 From 44daac8a3c3868bb79633a31f41b4edceea1fafb Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 9 Sep 2024 10:25:00 -0700 Subject: [PATCH 20/24] fix logger --- Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift | 5 ++++- Source/AwsCommonRuntimeKit/crt/Logger.swift | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift b/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift index 4e5c6817b..a086e7f34 100644 --- a/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift +++ b/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift @@ -21,7 +21,10 @@ public struct CRTError: Equatable { } var message = String(cString: aws_error_str(self.code)) if let context { - message += ". " + context; + if message.last != "." { + message += "."; + } + message += " " + context; } self.message = message self.name = String(cString: aws_error_name(self.code)) diff --git a/Source/AwsCommonRuntimeKit/crt/Logger.swift b/Source/AwsCommonRuntimeKit/crt/Logger.swift index bf9399a7e..c39ee2641 100644 --- a/Source/AwsCommonRuntimeKit/crt/Logger.swift +++ b/Source/AwsCommonRuntimeKit/crt/Logger.swift @@ -37,16 +37,18 @@ public struct Logger { switch target { case .standardOutput: options.file = stdout + aws_logger_init_standard(&logger!, allocator.rawValue, &options) case .standardError: options.file = stderr + aws_logger_init_standard(&logger!, allocator.rawValue, &options) case .filePath(let filePath): filePath.withCString { cFilePath in options.filename = cFilePath + aws_logger_init_standard(&logger!, allocator.rawValue, &options) } } // Initialize and set the logger - aws_logger_init_standard(&logger!, allocator.rawValue, &options) aws_logger_set(&logger!) } } From 7f565778d5bca54053171000b73cb4788e7c2438 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 9 Sep 2024 10:28:42 -0700 Subject: [PATCH 21/24] fix lint warnings --- Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift | 4 ++-- Source/AwsCommonRuntimeKit/crt/Logger.swift | 6 ++++-- Source/Elasticurl/Elasticurl.swift | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift b/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift index a086e7f34..c57b21820 100644 --- a/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift +++ b/Source/AwsCommonRuntimeKit/crt/CommonRuntimeError.swift @@ -22,9 +22,9 @@ public struct CRTError: Equatable { var message = String(cString: aws_error_str(self.code)) if let context { if message.last != "." { - message += "."; + message += "." } - message += " " + context; + message += " " + context } self.message = message self.name = String(cString: aws_error_name(self.code)) diff --git a/Source/AwsCommonRuntimeKit/crt/Logger.swift b/Source/AwsCommonRuntimeKit/crt/Logger.swift index c39ee2641..03d24ba6b 100644 --- a/Source/AwsCommonRuntimeKit/crt/Logger.swift +++ b/Source/AwsCommonRuntimeKit/crt/Logger.swift @@ -11,7 +11,7 @@ public enum LogTarget { } public struct Logger { - private static var logger: aws_logger? = nil + private static var logger: aws_logger? private static let lock = NSLock() /// Initializes the CRT logger based on the specified log target and log level. The CRT logger must be only initialized once in your application. Initializing the logger multiple times is not supported. @@ -25,7 +25,9 @@ public struct Logger { // Check if the logger is already initialized guard logger == nil else { - throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_UNSUPPORTED_OPERATION.rawValue, context: "Initializing the CRT Logger multiple times is not supported.")) + throw CommonRunTimeError.crtError(CRTError( + code: AWS_ERROR_UNSUPPORTED_OPERATION.rawValue, + context: "Initializing the CRT Logger multiple times is not supported.")) } // Initialize the logger diff --git a/Source/Elasticurl/Elasticurl.swift b/Source/Elasticurl/Elasticurl.swift index 3a89159b1..1369cb9d7 100644 --- a/Source/Elasticurl/Elasticurl.swift +++ b/Source/Elasticurl/Elasticurl.swift @@ -220,10 +220,10 @@ struct Elasticurl { createOutputFile() if let traceFile = context.traceFile { print("enable logging with trace file") - try! Logger.initialize(target: .filePath(traceFile), level: context.logLevel) + try? Logger.initialize(target: .filePath(traceFile), level: context.logLevel) } else { print("enable logging with stdout") - try! Logger.initialize(target: .standardOutput, level: context.logLevel) + try? Logger.initialize(target: .standardOutput, level: context.logLevel) } await run() From a35b76608afb1241f7585562d7b79f9a1d4595e7 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 9 Sep 2024 10:50:07 -0700 Subject: [PATCH 22/24] move logger to class init --- Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift b/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift index d37d33872..65c44a999 100644 --- a/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift +++ b/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift @@ -8,12 +8,16 @@ import AwsCCommon class XCBaseTestCase: XCTestCase { internal let tracingAllocator = TracingAllocator(tracingStacksOf: allocator) + override class func setUp() { + super.setUp() + try! Logger.initialize(target: .standardOutput, level: .error) + } + override func setUp() { super.setUp() // XCode currently lacks a way to enable logs exclusively for failed tests only. // To prevent log spamming, we use `error` log level to only print error message. // We should update this once a more efficient log processing method becomes available. - try! Logger.initialize(target: .standardOutput, level: .error) // Override the allocator with tracing allocator allocator = tracingAllocator.rawValue From 6e100797616ff3307c934b97f0cb8487a7c094f6 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 9 Sep 2024 11:00:23 -0700 Subject: [PATCH 23/24] try? for logger --- Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift b/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift index 65c44a999..ed5c5ee15 100644 --- a/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift +++ b/Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift @@ -7,17 +7,13 @@ import AwsCCommon class XCBaseTestCase: XCTestCase { internal let tracingAllocator = TracingAllocator(tracingStacksOf: allocator) - - override class func setUp() { - super.setUp() - try! Logger.initialize(target: .standardOutput, level: .error) - } override func setUp() { super.setUp() // XCode currently lacks a way to enable logs exclusively for failed tests only. // To prevent log spamming, we use `error` log level to only print error message. // We should update this once a more efficient log processing method becomes available. + try? Logger.initialize(target: .standardOutput, level: .error) // Override the allocator with tracing allocator allocator = tracingAllocator.rawValue From ed450746c6557fbfa21917d88c13390913bd0b1a Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 10 Sep 2024 10:55:06 -0700 Subject: [PATCH 24/24] fix typo --- Source/Elasticurl/Elasticurl.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Elasticurl/Elasticurl.swift b/Source/Elasticurl/Elasticurl.swift index 1369cb9d7..bc782e230 100644 --- a/Source/Elasticurl/Elasticurl.swift +++ b/Source/Elasticurl/Elasticurl.swift @@ -1,4 +1,4 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.elastic +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0. import _Concurrency