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

chore: Make main branch buildable #664

Merged
merged 36 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e70cbbe
Generate manifest during CRT builder pre-build step
jbelkins Nov 2, 2022
3c88f48
Disable all but one CI run
jbelkins Nov 2, 2022
a8a1263
Fix json
jbelkins Nov 2, 2022
e86ac5a
Add .gitkeep in release/
jbelkins Nov 2, 2022
da26b34
Script cd's relative to its location
jbelkins Nov 2, 2022
7b396d4
Lock to smithy 1.26.0
jbelkins Nov 2, 2022
6381a28
Empty commit
jbelkins Nov 2, 2022
973fe59
Re-enable all CI jobs, remove path detection from CRT builder setup
jbelkins Nov 2, 2022
974248b
Remove protocol test logic from package script
jbelkins Nov 2, 2022
a9fcd79
Generate manifest for release, improve script
jbelkins Nov 2, 2022
8ab7ebe
Remove extras in script
jbelkins Nov 2, 2022
502e1a4
Merge remote-tracking branch 'origin/main' into jbe/crt_builder_with_…
jbelkins Nov 2, 2022
cfb09f9
Revert smithy version spec
jbelkins Nov 2, 2022
3afb4c9
Create release/ before running manifest script
jbelkins Nov 2, 2022
ce09c22
Delete release/ dir during pre-build
jbelkins Nov 2, 2022
9aac50e
Fix json
jbelkins Nov 2, 2022
cea0f90
Force release to use main branch
jbelkins Nov 2, 2022
91409e5
aws-sdk-swift release build artifacts
Nov 2, 2022
2e4b730
Revert "aws-sdk-swift release build artifacts"
jbelkins Nov 3, 2022
552fbc0
Revert "Force release to use main branch"
jbelkins Nov 3, 2022
f8eeaa9
Merge remote-tracking branch 'origin/main' into release/jbe_test_rele…
jbelkins Nov 3, 2022
1adf37b
Merge branch 'main' into jbe/crt_builder_with_dynamic_manifest
jbelkins Nov 3, 2022
a72c123
Add doc comments to script
jbelkins Nov 3, 2022
66c4f2f
Merge branch 'jbe/crt_builder_with_dynamic_manifest' of github.com:aw…
jbelkins Nov 3, 2022
af63225
Merge remote-tracking branch 'origin/main' into jbe/crt_builder_with_…
jbelkins Nov 7, 2022
9b9a2f0
kick off release 0.5.0
epau Nov 9, 2022
3a2b889
aws-sdk-swift release build artifacts
Nov 9, 2022
6d9101d
Merge branch 'main' into jbe/crt_builder_with_dynamic_manifest
jbelkins Nov 9, 2022
6981897
Update scripts/generatePackageSwift.swift
jbelkins Nov 9, 2022
344af7b
Add link to CRT builder script in script docs
jbelkins Nov 9, 2022
b6b7a77
Merge branch 'jbe/crt_builder_with_dynamic_manifest' of github.com:aw…
jbelkins Nov 9, 2022
4e533ec
Merge branch 'main' into jbe/crt_builder_with_dynamic_manifest
jbelkins Nov 9, 2022
b3b4065
Lock smithy-swift & aws-crt-swift to main branch when not releasing
jbelkins Nov 9, 2022
a40fd97
Rename versionDependencies to packageDependencies
jbelkins Nov 9, 2022
7caad0d
Merge tag '0.5.0' into jbe/crt_builder_with_dynamic_manifest
jbelkins Nov 9, 2022
e7b88da
sdk.properties configures codegen
jbelkins Nov 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
./gradlew -p codegen/sdk-codegen build
./gradlew -p codegen/sdk-codegen stageSdks
./scripts/mergeModels.sh release
./scripts/generatePackageSwift.swift > Package.swift
AWS_SDK_RELEASE_IN_PROGRESS=1 ./scripts/generatePackageSwift.swift > Package.swift
cat Package.swift
- name: Commit Changes
uses: EndBug/add-and-commit@v7
Expand Down
129 changes: 17 additions & 112 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,115 +1,16 @@
// swift-tools-version:5.4
// swift-tools-version:5.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 PackageDescription
import class Foundation.FileManager
import class Foundation.ProcessInfo
import struct Foundation.URL

/*
This Package.swift file is used to compile against locally
- generated version of the AWS Swift SDK
- checked out version of ClientRuntime
- checked out version of AwsCrt

Note: This Package.swift file is overwritten in our tagged releases


In order to use setup local development:

1. Install a Java 18 JDK if one is not already installed to your system.
The OpenJDK-based Amazon Corretto JDK is available at https://aws.amazon.com/corretto .

2. Create a folder:
mkdir -p ~/Projects/Amplify/SwiftSDK
cd ~/Projects/Amplify/SwiftSDK

3. Checkout projects:
git clone https://github.com/awslabs/aws-sdk-swift.git
git clone https://github.com/awslabs/smithy-swift.git
git clone https://github.com/awslabs/aws-crt-swift.git --recursive

4. Build
cd ~/Projects/Amplify/SwiftSDK/aws-sdk-swift
echo "compositeProjects=$HOME/Projects/Amplify/SwiftSDK/smithy-swift" >> local.properties
./gradlew -p codegen/sdk-codegen build
./gradlew -p codegen/sdk-codegen stageSdks

As a result, there should be a folder called 'release' in aws-sdk-swift.

To depend on these locally generated SDKs, change your project's
Package.swift file to something like:
// This manifest is auto-generated. Do not commit edits to this file;
// they will be overwritten.

let package = Package(
name: "YourNameHere",
platforms: [.macOS(.v10_15), .iOS(.v13)],
dependencies: [
.package(path: "/Users/<YourUserName>/Projects/Amplify/SwiftSDK/aws-sdk-swift")
],
targets: [
.target(
name: "YourNameHere",
dependencies: [.product(name: "AWSS3", package: "aws-sdk-swift")])
]
)
*/

let RELEASE = "release"
let LOCAL_BASE_DIR = "Projects/Amplify/SwiftSDK"
let AWS_SDK_SWIFT_DIR = "\(LOCAL_BASE_DIR)/aws-sdk-swift"
let AWS_CRT_SWIFT_DIR = "\(LOCAL_BASE_DIR)/aws-crt-swift"
let SMITHY_SWIFT_DIR = "\(LOCAL_BASE_DIR)/smithy-swift"

let homePath = FileManager.default.homeDirectoryForCurrentUser
let env = ProcessInfo.processInfo.environment

let awsSDKSwiftDir, awsCRTSwiftDir, smithySwiftDir: URL
if let awsSDKSwiftCIPath = env["AWS_SDK_SWIFT_CI_DIR"], let awsCRTSwiftCIPath = env["AWS_CRT_SWIFT_CI_DIR"],
let smithySwiftCIPath = env["SMITHY_SWIFT_CI_DIR"] {
awsSDKSwiftDir = URL(fileURLWithPath: awsSDKSwiftCIPath)
awsCRTSwiftDir = URL(fileURLWithPath: awsCRTSwiftCIPath)
smithySwiftDir = URL(fileURLWithPath: smithySwiftCIPath)
} else {
awsSDKSwiftDir = homePath.appendingPathComponent(AWS_SDK_SWIFT_DIR)
awsCRTSwiftDir = homePath.appendingPathComponent(AWS_CRT_SWIFT_DIR)
smithySwiftDir = homePath.appendingPathComponent(SMITHY_SWIFT_DIR)
}

let localReleaseSwiftSDKDir = awsSDKSwiftDir.appendingPathComponent(RELEASE)

private extension Package {

func setupDependencies() -> Package {
dependencies += [
.package(path: awsCRTSwiftDir.path),
.package(path: smithySwiftDir.path)
]

let sdksToIncludeInTargets = try! FileManager.default.contentsOfDirectory(atPath: localReleaseSwiftSDKDir.path)
.filter { target in
!target.hasPrefix(".")
}
includeTargets(package: self, releasedSDKs: sdksToIncludeInTargets)
return self
}

private func includeTargets(package: Package, releasedSDKs: [String]) {
var libs: [PackageDescription.Product] = []
var targets: [PackageDescription.Target] = []
for sdkName in releasedSDKs {
libs.append(.library(name: sdkName, targets: [sdkName]))
targets.append(.target(name: sdkName,
dependencies: [.product(name: "ClientRuntime", package: "smithy-swift"), "AWSClientRuntime"],
path: "./\(RELEASE)/\(sdkName)"))
}
package.products += libs
package.targets += targets
}
}
import PackageDescription

let package = Package(
name: "aws-sdk-swift",
Expand All @@ -118,7 +19,11 @@ let package = Package(
.iOS(.v13)
],
products: [
.library(name: "AWSClientRuntime", targets: ["AWSClientRuntime"])
.library(name: "AWSClientRuntime", targets: ["AWSClientRuntime"]),
],
dependencies: [
.package(url: "https://github.com/awslabs/smithy-swift", .exact("0.5.0")),
.package(url: "https://github.com/awslabs/aws-crt-swift", .exact("0.3.1"))
],
targets: [
.target(
Expand All @@ -137,6 +42,6 @@ let package = Package(
.product(name: "ClientRuntime", package: "smithy-swift")
],
path: "./AWSClientRuntime/Tests"
)
),
]
).setupDependencies()
)
4 changes: 4 additions & 0 deletions builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"variables": {
"gradlew": "{source_dir}/gradlew"
},
"pre_build_steps": [
"cd {source_dir} && rm -rf release",
"cd {source_dir} && ./scripts/setup_for_crt_builder.sh"
],
"build_steps": [
"{gradlew} -p {source_dir}/codegen/smithy-aws-swift-codegen build",
"{gradlew} -p {source_dir}/codegen/protocol-test-codegen build",
Expand Down
98 changes: 86 additions & 12 deletions scripts/generatePackageSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,84 @@
* SPDX-License-Identifier: Apache-2.0.
*/

import Foundation
#if os(Linux)
import Glibc
#else
import Darwin
#endif
import class Foundation.PropertyListDecoder
import class Foundation.ProcessInfo
import class Foundation.FileManager

let env = ProcessInfo.processInfo.environment

// This struct is read from the .plist stored at versionDependencies.plist
struct VersionDeps: Codable {
jbelkins marked this conversation as resolved.
Show resolved Hide resolved
// Versions will always be defined in versionDependencies.plist
// Versions are the only reference used when releasing.
var awsCRTSwiftVersion: String
var clientRuntimeVersion: String
// Branches are not normally defined in versionDependencies.plist,
// but may be set during development on a feature branch if desired.
// These values override environment vars set on CI.
// Branches are ignored when building a release.
var awsCRTSwiftBranch: String?
var clientRuntimeBranch: String?
// Paths may be used to point to paths on a development machine.
// They may be set by the developer during testing, but should
// never be set outside a development branch.
// On CI, paths may be read from env vars and set at build time.
// Paths are ignored when building a release.
var awsCRTSwiftPath: String?
var clientRuntimePath: String?
}

// When AWS_SDK_RELEASE_IN_PROGRESS is set, the manifest will require
// exact versions of smithy-swift and aws-crt-swift no matter what
// branches or paths are set.
let releaseInProgress: Bool = {
env["AWS_SDK_RELEASE_IN_PROGRESS"] != nil
}()

let plistFile = "versionDependencies.plist"

func getVersionsOfDependencies() -> VersionDeps? {
guard let versionsPlist = FileManager.default.contents(atPath: plistFile),
let deps = try? PropertyListDecoder().decode(VersionDeps.self, from: versionsPlist)
var deps = try? PropertyListDecoder().decode(VersionDeps.self, from: versionsPlist)
else {
return nil
}
// If env vars are set for package paths in the AWS CRT Builder script, use them
// unless generating the manifest for release
if let awsCRTSwiftCIPath = env["AWS_CRT_SWIFT_CI_DIR"], let smithySwiftCIPath = env["SMITHY_SWIFT_CI_DIR"] {
deps.awsCRTSwiftPath = awsCRTSwiftCIPath
deps.clientRuntimePath = smithySwiftCIPath
}
return deps
}

func generateHeader() {
let header = """
// swift-tools-version:5.5

//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

// This manifest is auto-generated. Do not commit edits to this file;
// they will be overwritten.

import PackageDescription
import class Foundation.FileManager

"""
print(header)
}

func generatePackageHeader() {
let packageHeader = """
let packageHeader = """
let package = Package(
name: "aws-sdk-swift",
platforms: [
Expand All @@ -43,26 +94,49 @@ let package = Package(
}

func generateProducts(_ releasedSDKs: [String]) {

print(" products: [")
print(" .library(name: \"AWSClientRuntime\", targets: [\"AWSClientRuntime\"]),")
for sdk in releasedSDKs {
print(" .library(name: \"\(sdk)\", targets: [\"\(sdk)\"]),")
}
print(" ],")

}

func generateDependencies(versions: VersionDeps) {
let crtSwiftDependency = dependency(
url: "https://github.com/awslabs/aws-crt-swift",
version: versions.awsCRTSwiftVersion,
branch: versions.awsCRTSwiftBranch,
path: versions.awsCRTSwiftPath
)
let clientRuntimeDependency = dependency(
url: "https://github.com/awslabs/smithy-swift",
version: versions.clientRuntimeVersion,
branch: versions.clientRuntimeBranch,
path: versions.clientRuntimePath
)
let dependencies = """
dependencies: [
.package(url: "https://github.com/awslabs/aws-crt-swift.git", .exact("\(versions.awsCRTSwiftVersion)")),
.package(url: "https://github.com/awslabs/smithy-swift.git", .exact("\(versions.clientRuntimeVersion)"))
\(clientRuntimeDependency),
\(crtSwiftDependency)
],
"""
print(dependencies)
}

private func dependency(url: String, version: String, branch: String?, path: String?) -> String {
if !releaseInProgress {
if let path = path {
return ".package(path: \"\(path)\")"
} else if let branch = branch {
return ".package(url: \"\(url)\", branch: \"\(branch)\")"
}
}
// When generating the manifest for release or when no path/branch is set,
// lock dependencies to published versions
return ".package(url: \"\(url)\", .exact(\"\(version)\"))"
}

func generateTargets(_ releasedSDKs: [String]) {
let targetsBeginning = """
targets: [
Expand All @@ -88,12 +162,12 @@ func generateTargets(_ releasedSDKs: [String]) {
for sdk in releasedSDKs {
print(" .target(name: \"\(sdk)\", dependencies: [.product(name: \"ClientRuntime\", package: \"smithy-swift\"), \"AWSClientRuntime\"], path: \"./release/\(sdk)\"),")
}
print(" ]")

print(" ]")
}

let sdksToIncludeInTargets = try! FileManager.default.contentsOfDirectory(atPath: "release")
let releasedSDKs = sdksToIncludeInTargets.sorted()
let releasedSDKs = try! FileManager.default
.contentsOfDirectory(atPath: "release")
.filter { !$0.hasPrefix(".") }.sorted()

guard let versions = getVersionsOfDependencies() else {
print("Failed to get version dependencies")
Expand Down
18 changes: 18 additions & 0 deletions scripts/setup_for_crt_builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -x

# Generates the Package.swift file, configured to work properly when using the
# CRT builder script.
# For use only as a pre-build step when using the CRT builder script on CI.
jbelkins marked this conversation as resolved.
Show resolved Hide resolved

# Ensure that the release/ directory is present.
mkdir -p release

# Regenerate the Package.swift file.
# The env vars AWS_CRT_SWIFT_CI_DIR and SMITHY_SWIFT_CI_DIR must be defined by
# the CI environment, and will be used as the local paths to those dependencies.
swift ./scripts/generatePackageSwift.swift > Package.swift

# Dump the Package.swift to logs for troubleshooting.
cat Package.swift