From 86a8726fa1b504bbbaf095ff0b72c445f89c5489 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Thu, 11 Aug 2022 09:48:22 +1000 Subject: [PATCH 1/2] Add additional generator options. --- Package.resolved | 114 +++++++++--------- Package.swift | 4 +- .../SmokeFrameworkCodeGen.swift | 4 + .../main.swift | 24 ++++ ...eGenerator+generateOperationsContext.swift | 11 +- .../SmokeFrameworkCodeGeneration.swift | 39 ++++-- 6 files changed, 127 insertions(+), 69 deletions(-) diff --git a/Package.resolved b/Package.resolved index bc54db2..21bb595 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,61 +1,59 @@ { - "object": { - "pins": [ - { - "package": "OpenAPIKit", - "repositoryURL": "https://github.com/mattpolzin/OpenAPIKit.git", - "state": { - "branch": null, - "revision": "0c668112f9803c1858ed070f9e8ce84922a0b41f", - "version": "3.0.0-alpha.4" - } - }, - { - "package": "ServiceModelSwiftCodeGenerate", - "repositoryURL": "https://github.com/amzn/service-model-swift-code-generate.git", - "state": { - "branch": null, - "revision": "286181816fccc2b6ec92049ba68426d08cbe0059", - "version": "3.0.0-beta.1" - } - }, - { - "package": "SmokeAWSGenerate", - "repositoryURL": "https://github.com/amzn/smoke-aws-generate.git", - "state": { - "branch": null, - "revision": "2d2902403408d4c7a9f6c69c90975cc048759f95", - "version": "3.0.0-beta.1" - } - }, - { - "package": "SwaggerParser", - "repositoryURL": "https://github.com/tachyonics/SwaggerParser.git", - "state": { - "branch": null, - "revision": "c0eb70485c59a9d7dd6765dcd303b49fdb3040ee", - "version": "0.6.4" - } - }, - { - "package": "swift-argument-parser", - "repositoryURL": "https://github.com/apple/swift-argument-parser", - "state": { - "branch": null, - "revision": "6b2aa2748a7881eebb9f84fb10c01293e15b52ca", - "version": "0.5.0" - } - }, - { - "package": "Yams", - "repositoryURL": "https://github.com/jpsim/Yams.git", - "state": { - "branch": null, - "revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", - "version": "4.0.6" - } + "pins" : [ + { + "identity" : "openapikit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattpolzin/OpenAPIKit.git", + "state" : { + "revision" : "0c668112f9803c1858ed070f9e8ce84922a0b41f", + "version" : "3.0.0-alpha.4" } - ] - }, - "version": 1 + }, + { + "identity" : "service-model-swift-code-generate", + "kind" : "remoteSourceControl", + "location" : "https://github.com/amzn/service-model-swift-code-generate.git", + "state" : { + "branch" : "main", + "revision" : "ed2c9497e0e596b9b1ef40b12a219436c88a2ea6" + } + }, + { + "identity" : "smoke-aws-generate", + "kind" : "remoteSourceControl", + "location" : "https://github.com/amzn/smoke-aws-generate.git", + "state" : { + "branch" : "main", + "revision" : "4a4a01557c23cd5d205ee0202be75587d48635c8" + } + }, + { + "identity" : "swaggerparser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tachyonics/SwaggerParser.git", + "state" : { + "revision" : "c0eb70485c59a9d7dd6765dcd303b49fdb3040ee", + "version" : "0.6.4" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser", + "state" : { + "revision" : "6b2aa2748a7881eebb9f84fb10c01293e15b52ca", + "version" : "0.5.0" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", + "version" : "4.0.6" + } + } + ], + "version" : 2 } diff --git a/Package.swift b/Package.swift index 25abcc5..1031742 100644 --- a/Package.swift +++ b/Package.swift @@ -38,8 +38,8 @@ let package = Package( targets: ["SmokeFrameworkGenerateHttp1"]), ], dependencies: [ - .package(url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-beta.1"), - .package(url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-beta.1"), + .package(url: "https://github.com/amzn/smoke-aws-generate.git", branch: "main"), + .package(url: "https://github.com/amzn/service-model-swift-code-generate.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"), ], targets: [ diff --git a/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift b/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift index 41105da..c17e1ea 100644 --- a/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift +++ b/Sources/SmokeFrameworkApplicationGenerate/SmokeFrameworkCodeGen.swift @@ -38,5 +38,9 @@ struct SmokeFrameworkCodeGen: Codable { let initializationType: InitializationType? let testDiscovery: CodeGenFeatureStatus? let mainAnnotation: CodeGenFeatureStatus? + let addSendableConformance: CodeGenFeatureStatus? + let eventLoopFutureClientAPIs: CodeGenFeatureStatus? + let minimumCompilerSupport: MinimumCompilerSupport? + let clientConfigurationType: ClientConfigurationType? let operationStubGenerationRule: OperationStubGenerationRule } diff --git a/Sources/SmokeFrameworkApplicationGenerate/main.swift b/Sources/SmokeFrameworkApplicationGenerate/main.swift index fefa746..30616da 100644 --- a/Sources/SmokeFrameworkApplicationGenerate/main.swift +++ b/Sources/SmokeFrameworkApplicationGenerate/main.swift @@ -47,6 +47,10 @@ struct Parameters { var initializationType: InitializationType? var testDiscovery: CodeGenFeatureStatus? var mainAnnotation: CodeGenFeatureStatus? + var addSendableConformance: CodeGenFeatureStatus? + var eventLoopFutureClientAPIs: CodeGenFeatureStatus? + var minimumCompilerSupport: MinimumCompilerSupport? + var clientConfigurationType: ClientConfigurationType? var operationStubGenerationRule: OperationStubGenerationRule } @@ -97,6 +101,10 @@ private func startCodeGeneration( initializationType: InitializationType, testDiscovery: CodeGenFeatureStatus, mainAnnotation: CodeGenFeatureStatus, + addSendableConformance: CodeGenFeatureStatus, + eventLoopFutureClientAPIs: CodeGenFeatureStatus, + minimumCompilerSupport: MinimumCompilerSupport, + clientConfigurationType: ClientConfigurationType, operationStubGenerationRule: OperationStubGenerationRule, modelOverride: ModelOverride?) throws -> ServiceModel { let validationErrorDeclaration = ErrorDeclaration.external( @@ -107,6 +115,10 @@ private func startCodeGeneration( validationErrorDeclaration: validationErrorDeclaration, unrecognizedErrorDeclaration: unrecognizedErrorDeclaration, asyncAwaitAPIs: asyncAwait.clientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + addSendableConformance: addSendableConformance, + minimumCompilerSupport: minimumCompilerSupport, + clientConfigurationType: clientConfigurationType, generateModelShapeConversions: true, optionalsInitializeEmpty: true, fileHeader: nil, @@ -203,6 +215,10 @@ func handleApplication(parameters: Parameters) throws { initializationType: parameters.initializationType ?? .original, testDiscovery: parameters.testDiscovery ?? .disabled, mainAnnotation: parameters.mainAnnotation ?? .disabled, + addSendableConformance: parameters.addSendableConformance ?? .disabled, + eventLoopFutureClientAPIs: parameters.eventLoopFutureClientAPIs ?? .enabled, + minimumCompilerSupport: parameters.minimumCompilerSupport ?? .unknown, + clientConfigurationType: parameters.clientConfigurationType ?? .generator, operationStubGenerationRule: parameters.operationStubGenerationRule, modelOverride: modelOverride) @@ -233,6 +249,10 @@ func handleApplication(parameters: Parameters) throws { initializationType: parameters.initializationType, testDiscovery: parameters.testDiscovery, mainAnnotation: parameters.mainAnnotation, + addSendableConformance: parameters.addSendableConformance, + eventLoopFutureClientAPIs: parameters.eventLoopFutureClientAPIs, + minimumCompilerSupport: parameters.minimumCompilerSupport, + clientConfigurationType: parameters.clientConfigurationType, operationStubGenerationRule: .allFunctionsWithinContextExceptStandaloneFunctionsFor(existingOperations.sorted(by: <))) let jsonEncoder = JSONEncoder() @@ -418,6 +438,10 @@ struct SmokeFrameworkApplicationGenerateCommand: ParsableCommand { initializationType: config?.initializationType, testDiscovery: config?.testDiscovery, mainAnnotation: config?.mainAnnotation, + addSendableConformance: config?.addSendableConformance, + eventLoopFutureClientAPIs: config?.eventLoopFutureClientAPIs, + minimumCompilerSupport: config?.minimumCompilerSupport, + clientConfigurationType: config?.clientConfigurationType, operationStubGenerationRule: operationStubGenerationRule) try handleApplication(parameters: parameters) diff --git a/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift b/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift index fb4857c..3406b19 100644 --- a/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift +++ b/Sources/SmokeFrameworkCodeGeneration/ServiceModelCodeGenerator+generateOperationsContext.swift @@ -37,6 +37,15 @@ extension ServiceModelCodeGenerator { } } + var conformingProtocols: [String] = [] + var conformancePadding: String = "" + if case .enabled = self.customizations.addSendableConformance { + conformingProtocols.append("Sendable") + conformancePadding = " " + } + + let conformingProtocolsString = conformingProtocols.joined(separator: ", ") + fileBuilder.appendLine(""" // // \(baseName)OperationsContext.swift @@ -49,7 +58,7 @@ extension ServiceModelCodeGenerator { /** The context to be passed to each of the \(baseName) operations. */ - public struct \(baseName)OperationsContext { + public struct \(baseName)OperationsContext \(conformingProtocolsString)\(conformancePadding){ let logger: Logger // TODO: Add properties to be accessed by the operation handlers diff --git a/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift b/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift index d5ee8f6..85aefd7 100644 --- a/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift +++ b/Sources/SmokeFrameworkCodeGeneration/SmokeFrameworkCodeGeneration.swift @@ -167,6 +167,9 @@ public struct SmokeFrameworkCodeGeneration { serviceModel: ModelType) throws { try codeGenerator.generateFromModel(serviceModel: serviceModel, generationType: generationType, asyncAwaitClientAPIs: customizations.asyncAwaitAPIs, + eventLoopFutureClientAPIs: customizations.eventLoopFutureClientAPIs, + minimumCompilerSupport: customizations.minimumCompilerSupport, + clientConfigurationType: customizations.clientConfigurationType, initializationType: initializationType, testDiscovery: testDiscovery, mainAnnotation: mainAnnotation, @@ -190,6 +193,9 @@ extension ServiceModelCodeGenerator { func generateFromModel(serviceModel: ModelType, generationType: GenerationType, asyncAwaitClientAPIs: CodeGenFeatureStatus, + eventLoopFutureClientAPIs: CodeGenFeatureStatus, + minimumCompilerSupport: MinimumCompilerSupport, + clientConfigurationType: ClientConfigurationType, initializationType: InitializationType, testDiscovery: CodeGenFeatureStatus, mainAnnotation: CodeGenFeatureStatus, @@ -199,17 +205,26 @@ extension ServiceModelCodeGenerator { eventLoopFutureOperationHandlers: CodeGenFeatureStatus) throws { let clientProtocolDelegate = ClientProtocolDelegate( baseName: applicationDescription.baseName, - asyncAwaitAPIs: asyncAwaitClientAPIs) + asyncAwaitAPIs: asyncAwaitClientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport) let mockClientDelegate = MockClientDelegate( baseName: applicationDescription.baseName, isThrowingMock: false, - asyncAwaitAPIs: asyncAwaitClientAPIs) + asyncAwaitAPIs: asyncAwaitClientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport) let throwingClientDelegate = MockClientDelegate( baseName: applicationDescription.baseName, isThrowingMock: true, - asyncAwaitAPIs: asyncAwaitClientAPIs) + asyncAwaitAPIs: asyncAwaitClientAPIs, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport) let awsClientDelegate = APIGatewayClientDelegate( baseName: applicationDescription.baseName, asyncAwaitAPIs: asyncAwaitClientAPIs, + addSendableConformance: customizations.addSendableConformance, + eventLoopFutureClientAPIs: eventLoopFutureClientAPIs, + minimumCompilerSupport: minimumCompilerSupport, contentType: "application/json", signAllHeaders: false, defaultInvocationTraceContext: InvocationTraceContextDeclaration(name: "SmokeInvocationTraceContext", importPackage: "SmokeOperationsHTTP1")) let awsModelErrorsDelegate = SmokeFrameworkModelErrorsDelegate() @@ -230,11 +245,19 @@ extension ServiceModelCodeGenerator { } if generationType.needsClient { - generateClient(delegate: clientProtocolDelegate, isGenerator: false) - generateClient(delegate: mockClientDelegate, isGenerator: false) - generateClient(delegate: throwingClientDelegate, isGenerator: false) - generateClient(delegate: awsClientDelegate, isGenerator: false) - generateClient(delegate: awsClientDelegate, isGenerator: true) + let generatorFileType: ClientFileType + switch clientConfigurationType { + case .configurationObject: + generatorFileType = .clientConfiguration + case .generator: + generatorFileType = .clientGenerator + } + + generateClient(delegate: clientProtocolDelegate, fileType: .clientImplementation) + generateClient(delegate: mockClientDelegate, fileType: .clientImplementation) + generateClient(delegate: throwingClientDelegate, fileType: .clientImplementation) + generateClient(delegate: awsClientDelegate, fileType: .clientImplementation) + generateClient(delegate: awsClientDelegate, fileType: generatorFileType) generateOperationsReporting() generateInvocationsReporting() generateModelOperationClientInput() From a24cedf652b92d7c92d6896123c1da0a238caed0 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Thu, 11 Aug 2022 10:30:21 +1000 Subject: [PATCH 2/2] Fix compilation of older compiler versions. --- .gitignore | 4 +- Package.resolved | 114 ++++++++++++++++++++-------------------- Package@swift-5.4.swift | 4 +- Package@swift-5.5.swift | 4 +- 4 files changed, 65 insertions(+), 61 deletions(-) diff --git a/.gitignore b/.gitignore index 412279e..cb694f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ build .DS_Store .build/ -.swiftpm/ *.xcodeproj +.swift-version +.swiftpm/ *~ +.vscode/ diff --git a/Package.resolved b/Package.resolved index 21bb595..9ca1f49 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,59 +1,61 @@ { - "pins" : [ - { - "identity" : "openapikit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mattpolzin/OpenAPIKit.git", - "state" : { - "revision" : "0c668112f9803c1858ed070f9e8ce84922a0b41f", - "version" : "3.0.0-alpha.4" + "object": { + "pins": [ + { + "package": "OpenAPIKit", + "repositoryURL": "https://github.com/mattpolzin/OpenAPIKit.git", + "state": { + "branch": null, + "revision": "0c668112f9803c1858ed070f9e8ce84922a0b41f", + "version": "3.0.0-alpha.4" + } + }, + { + "package": "ServiceModelSwiftCodeGenerate", + "repositoryURL": "https://github.com/amzn/service-model-swift-code-generate.git", + "state": { + "branch": "main", + "revision": "4c0ccda7df61c87538df34fc47982435c4a52206", + "version": null + } + }, + { + "package": "SmokeAWSGenerate", + "repositoryURL": "https://github.com/amzn/smoke-aws-generate.git", + "state": { + "branch": "main", + "revision": "4a4a01557c23cd5d205ee0202be75587d48635c8", + "version": null + } + }, + { + "package": "SwaggerParser", + "repositoryURL": "https://github.com/tachyonics/SwaggerParser.git", + "state": { + "branch": null, + "revision": "c0eb70485c59a9d7dd6765dcd303b49fdb3040ee", + "version": "0.6.4" + } + }, + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser", + "state": { + "branch": null, + "revision": "6b2aa2748a7881eebb9f84fb10c01293e15b52ca", + "version": "0.5.0" + } + }, + { + "package": "Yams", + "repositoryURL": "https://github.com/jpsim/Yams.git", + "state": { + "branch": null, + "revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", + "version": "4.0.6" + } } - }, - { - "identity" : "service-model-swift-code-generate", - "kind" : "remoteSourceControl", - "location" : "https://github.com/amzn/service-model-swift-code-generate.git", - "state" : { - "branch" : "main", - "revision" : "ed2c9497e0e596b9b1ef40b12a219436c88a2ea6" - } - }, - { - "identity" : "smoke-aws-generate", - "kind" : "remoteSourceControl", - "location" : "https://github.com/amzn/smoke-aws-generate.git", - "state" : { - "branch" : "main", - "revision" : "4a4a01557c23cd5d205ee0202be75587d48635c8" - } - }, - { - "identity" : "swaggerparser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/tachyonics/SwaggerParser.git", - "state" : { - "revision" : "c0eb70485c59a9d7dd6765dcd303b49fdb3040ee", - "version" : "0.6.4" - } - }, - { - "identity" : "swift-argument-parser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser", - "state" : { - "revision" : "6b2aa2748a7881eebb9f84fb10c01293e15b52ca", - "version" : "0.5.0" - } - }, - { - "identity" : "yams", - "kind" : "remoteSourceControl", - "location" : "https://github.com/jpsim/Yams.git", - "state" : { - "revision" : "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", - "version" : "4.0.6" - } - } - ], - "version" : 2 + ] + }, + "version": 1 } diff --git a/Package@swift-5.4.swift b/Package@swift-5.4.swift index e56153b..faa3de5 100644 --- a/Package@swift-5.4.swift +++ b/Package@swift-5.4.swift @@ -30,9 +30,9 @@ let package = Package( ], dependencies: [ .package(name: "SmokeAWSGenerate", - url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/smoke-aws-generate.git", .branch("main")), .package(name: "ServiceModelSwiftCodeGenerate", - url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/service-model-swift-code-generate.git", .branch("main")), .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"), ], targets: [ diff --git a/Package@swift-5.5.swift b/Package@swift-5.5.swift index e56153b..faa3de5 100644 --- a/Package@swift-5.5.swift +++ b/Package@swift-5.5.swift @@ -30,9 +30,9 @@ let package = Package( ], dependencies: [ .package(name: "SmokeAWSGenerate", - url: "https://github.com/amzn/smoke-aws-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/smoke-aws-generate.git", .branch("main")), .package(name: "ServiceModelSwiftCodeGenerate", - url: "https://github.com/amzn/service-model-swift-code-generate.git", from: "3.0.0-beta.1"), + url: "https://github.com/amzn/service-model-swift-code-generate.git", .branch("main")), .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"), ], targets: [