Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Generate package manifest for preview builds #1863

Merged
merged 13 commits into from
Jan 14, 2025
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ codegen/protocol-test-codegen-local/smithy-build.json
codegen/protocol-test-codegen/smithy-build.json
SmokeTests/

# Preview embedded dependencies
/smithy-swift/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll be embedding smithy-swift in the SDK repo in preview build artifacts. This .gitignore will make it so that if a preview customer wants to push their SDK up to Git, smithy-swift won't get pushed with it.

# vim temporary files
*.swp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ struct GeneratePackageManifestCommand: ParsableCommand {
@Flag(help: "If the package manifest should exclude runtime tests.")
var excludeRuntimeTests = false

@Flag(help: "If the package manifest should be configured for a preview build.")
var previewBuild = false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI flag that is being added. Note it defaults to false, which renders a manifest with current behavior.

func run() throws {
let generatePackageManifest = GeneratePackageManifest.standard(
repoPath: repoPath,
packageFileName: packageFileName,
clientRuntimeVersion: clientRuntimeVersion,
crtVersion: crtVersion,
services: services.isEmpty ? nil : services,
excludeRuntimeTests: excludeRuntimeTests
excludeRuntimeTests: excludeRuntimeTests,
previewBuild: previewBuild
)
try generatePackageManifest.run()
}
Expand All @@ -67,6 +71,8 @@ struct GeneratePackageManifest {
let services: [String]?
/// If the package manifest should exclude runtime unit tests.
let excludeRuntimeTests: Bool
/// If the package manifest should be configured for a preview build.
let previewBuild: Bool

typealias BuildPackageManifest = (
_ clientRuntimeVersion: Version,
Expand Down Expand Up @@ -199,21 +205,24 @@ extension GeneratePackageManifest {
crtVersion: Version? = nil,
services: [String]? = nil,
excludeAWSServices: Bool = false,
excludeRuntimeTests: Bool = false
excludeRuntimeTests: Bool = false,
previewBuild: Bool = false
) -> Self {
GeneratePackageManifest(
repoPath: repoPath,
packageFileName: packageFileName,
clientRuntimeVersion: clientRuntimeVersion,
crtVersion: crtVersion,
services: services,
excludeRuntimeTests: excludeRuntimeTests
excludeRuntimeTests: excludeRuntimeTests,
previewBuild: previewBuild
) { _clientRuntimeVersion, _crtVersion, _services in
let builder = PackageManifestBuilder(
clientRuntimeVersion: _clientRuntimeVersion,
crtVersion: _crtVersion,
services: _services,
excludeRuntimeTests: excludeRuntimeTests
excludeRuntimeTests: excludeRuntimeTests,
previewBuild: previewBuild
)
return try builder.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct PackageManifestBuilder {
let crtVersion: Version
let services: [Service]
let excludeRuntimeTests: Bool
let previewBuild: Bool
let prefixContents: () throws -> String
let basePackageContents: () throws -> String

Expand All @@ -26,13 +27,15 @@ struct PackageManifestBuilder {
crtVersion: Version,
services: [Service],
excludeRuntimeTests: Bool,
previewBuild: Bool,
prefixContents: @escaping () throws -> String,
basePackageContents: @escaping () throws -> String
) {
self.clientRuntimeVersion = clientRuntimeVersion
self.crtVersion = crtVersion
self.services = services
self.excludeRuntimeTests = excludeRuntimeTests
self.previewBuild = previewBuild
self.prefixContents = prefixContents
self.basePackageContents = basePackageContents
}
Expand All @@ -41,13 +44,15 @@ struct PackageManifestBuilder {
clientRuntimeVersion: Version,
crtVersion: Version,
services: [Service],
excludeRuntimeTests: Bool
excludeRuntimeTests: Bool,
previewBuild: Bool
) {
self.init(
clientRuntimeVersion: clientRuntimeVersion,
crtVersion: crtVersion,
services: services,
excludeRuntimeTests: excludeRuntimeTests,
previewBuild: previewBuild,
prefixContents: Self.contentReader(filename: "Package.Prefix"),
basePackageContents: Self.contentReader(filename: "Package.Base")
)
Expand Down Expand Up @@ -96,6 +101,9 @@ struct PackageManifestBuilder {
// Remove the runtime tests if needed
buildRuntimeTests(),
"",
// Configure for preview or regular build
buildPreviewFlag(),
"",
// Add the generated content that defines the list of services to include
buildServiceTargets(),
"",
Expand Down Expand Up @@ -123,6 +131,10 @@ struct PackageManifestBuilder {
"let excludeRuntimeUnitTests = \(excludeRuntimeTests)"
}

private func buildPreviewFlag() -> String {
"let isPreviewBuild = \(previewBuild)"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple boolean variable is rendered into the Package.swift. It is true when the CLI flag is set.

/// Builds the list of services to include.
/// This generates an array of strings, where the each item is a name of a service
/// and calls the `addServiceTarget` for each item.
Expand Down
11 changes: 9 additions & 2 deletions AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ private func productForService(_ service: String) -> Product {
// MARK: Dependencies

private var clientRuntimeDependency: Package.Dependency {
let path = "../smithy-swift"
let previewPath = "./smithy-swift"
let developmentPath = "../smithy-swift"
let gitURL = "https://github.com/smithy-lang/smithy-swift"
let useLocalDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_LOCAL_DEPS"] != nil
return useLocalDeps ? .package(path: path) : .package(url: gitURL, exact: clientRuntimeVersion)
if isPreviewBuild {
return .package(path: previewPath)
} else if useLocalDeps {
return .package(path: developmentPath)
} else {
return .package(url: gitURL, exact: clientRuntimeVersion)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If isPreviewBuild is set, a copy of smithy-swift that is in a subfolder in the root of the SDK project will be used.

Otherwise, the smithy-swift dependency will be set according to the current logic.

}

private var crtDependency: Package.Dependency {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ extension GeneratePackageManifest {
crtVersion: Version? = nil,
services: [String]? = nil,
excludeRuntimeTests: Bool = false,
previewBuild: Bool = false,
buildPackageManifest: @escaping BuildPackageManifest = { (_,_,_) throws -> String in "" }
) -> GeneratePackageManifest {
GeneratePackageManifest(
Expand All @@ -124,6 +125,7 @@ extension GeneratePackageManifest {
crtVersion: crtVersion,
services: services,
excludeRuntimeTests: excludeRuntimeTests,
previewBuild: previewBuild,
buildPackageManifest: buildPackageManifest
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,72 @@ import XCTest

class PackageManifestBuilderTests: XCTestCase {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below, manifest generator tests are added/modified for the new flag.

let expected = """
<contents of prefix>
// MARK: - Dynamic Content
func testBuildWithDefaults() throws {
let expected = """
<contents of prefix>
// MARK: - Dynamic Content

let clientRuntimeVersion: Version = "1.2.3"
let crtVersion: Version = "4.5.6"
let clientRuntimeVersion: Version = "1.2.3"
let crtVersion: Version = "4.5.6"

let excludeRuntimeUnitTests = false
let excludeRuntimeUnitTests = false

let serviceTargets: [String] = [
"A",
"B",
"C",
"D",
"E",
]
let isPreviewBuild = false

<contents of base package>
"""
let serviceTargets: [String] = [
"A",
"B",
"C",
"D",
"E",
]

func testBuild() throws {
<contents of base package>
"""
let subject = try PackageManifestBuilder(
clientRuntimeVersion: .init("1.2.3"),
crtVersion: .init("4.5.6"),
services: ["A","B","C","D","E"].map { PackageManifestBuilder.Service(name: $0) },
excludeRuntimeTests: false,
previewBuild: false,
prefixContents: { "<contents of prefix>" },
basePackageContents: { "<contents of base package>" }
)
let result = try! subject.build()
print("")
print(result)
print("")
XCTAssertEqual(result, expected)
}

func testBuildWithPreviewBuildAndExcludedTests() throws {
let expected = """
<contents of prefix>
// MARK: - Dynamic Content

let clientRuntimeVersion: Version = "1.2.3"
let crtVersion: Version = "4.5.6"

let excludeRuntimeUnitTests = true

let isPreviewBuild = true

let serviceTargets: [String] = [
"A",
"B",
"C",
"D",
"E",
]

<contents of base package>
"""
let subject = try PackageManifestBuilder(
clientRuntimeVersion: .init("1.2.3"),
crtVersion: .init("4.5.6"),
services: ["A","B","C","D","E"].map { PackageManifestBuilder.Service(name: $0) },
excludeRuntimeTests: true,
previewBuild: true,
prefixContents: { "<contents of prefix>" },
basePackageContents: { "<contents of base package>" }
)
Expand Down
13 changes: 11 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let crtVersion: Version = "0.43.0"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regenerated manifest with changes is below.

let excludeRuntimeUnitTests = false

let isPreviewBuild = false

let serviceTargets: [String] = [
"AWSACM",
"AWSACMPCA",
Expand Down Expand Up @@ -496,10 +498,17 @@ private func productForService(_ service: String) -> Product {
// MARK: Dependencies

private var clientRuntimeDependency: Package.Dependency {
let path = "../smithy-swift"
let previewPath = "./smithy-swift"
let developmentPath = "../smithy-swift"
let gitURL = "https://github.com/smithy-lang/smithy-swift"
let useLocalDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_LOCAL_DEPS"] != nil
return useLocalDeps ? .package(path: path) : .package(url: gitURL, exact: clientRuntimeVersion)
if isPreviewBuild {
return .package(path: previewPath)
} else if useLocalDeps {
return .package(path: developmentPath)
} else {
return .package(url: gitURL, exact: clientRuntimeVersion)
}
}

private var crtDependency: Package.Dependency {
Expand Down
Loading