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

feature(SPM): adds support for local development #27

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ __pycache__/
awsconfiguration.json
amplifyconfiguration.json
credentials-mc.json

XCF
15 changes: 12 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ let latestVersion = "2.25.0"

// Hosting url where the release artifacts are hosted.
let hostingUrl = "https://releases.amplify.aws/aws-sdk-ios/"
let localPath = "XCF/"
let localPathEnabled = false

// Map between the available frameworks and the checksum
//
Expand Down Expand Up @@ -65,10 +67,17 @@ let frameworksToChecksum = [

var products = frameworksToChecksum.keys.map {Product.library(name: $0, targets: [$0])}

func createTarget(framework: String, checksum: String) -> Target {
localPathEnabled ?
Target.binaryTarget(name: framework,
path: "\(localPath)/\(framework).xcframework") :
Target.binaryTarget(name: framework,
url: "\(hostingUrl)\(framework)-\(latestVersion).zip",
checksum: checksum)
}

var targets = frameworksToChecksum.map { framework, checksum in
Target.binaryTarget(name: framework,
url: "\(hostingUrl)\(framework)-\(latestVersion).zip",
checksum: checksum)
createTarget(framework: framework, checksum: checksum)
}

let package = Package(
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ To use the AWS SDK for iOS, you will need the following installed on your develo
* Xcode 11.0 or later
* iOS 9 or later


## Adding AWS SDK iOS via Swift Package Manager

1. Open your project in Xcode 11.0 or above
Expand All @@ -25,3 +24,15 @@ To use the AWS SDK for iOS, you will need the following installed on your develo
**NOTE:** The AWS Mobile SDK for iOS [does not follow Semantic Versioning](https://docs.amplify.aws/sdk/configuration/setup-options/q/platform/ios#aws-sdk-version-vs-semantic-versioning).

5. Choose the packages required for your project and click **Finish**

## Local Development

It you are using SPM to do development and are modifying the source in the AWS SDK iOS code base you will need to work with a locally built copy of the XCF files. Running `local.sh` will produce all of the XCF files and copy them to a directory in this repo so that `Package.swift` can be updated to reference them. Once the XCF files are in place change the value for `localPathEnabled` to `true` and the package will reference the local path. The Swift package can then be used locally with any changes made in the cloned copy of the aws-sdk-ios repo.

### Requirements

In order to do local development the XCF directory must be populated with the XCF files. These files can be generated from the aws-sdk-ios repo which is expected to be cloned alongside this repo. The Python script which is used to create the XCF files for deployment will be used to prepare these files which are then copied into a folder named XCF in this repo's directory. Then `Package.swift` can be changed to use the local path.

1. Clone aws-sdk-ios to the same directory as this repo
2. Run `local.sh` to prepare the XCF files (this can take a while)
3. Update `Package.swift` to set `localPathEnabled` to `true`
29 changes: 29 additions & 0 deletions local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# Uses aws-sdk-ios repo to create local copies of the XCF binaries
# so that modified source can be used to consume the SPM package.

export SOURCE_REPO_DIR=../aws-sdk-ios
export XCF_OUTPUT_DIR=xcframeworks/output/XCF

if [ ! -d "${SOURCE_REPO_DIR}" ]; then
echo "AWS SDK iOS repo is required: ${SOURCE_REPO_DIR}"
exit 0
fi

if [ ! -d "${SOURCE_REPO_DIR}/${XCF_OUTPUT_DIR}" ]; then
# builds packages and produces XCF files
pushd .
cd "${SOURCE_REPO_DIR}"
python3 ./CircleciScripts/create_xcframeworks.py
popd
fi

if [ ! -d "XCF" ]; then
# Copy XCF output into SPM repo
mkdir -p XCF
cp -rp "${SOURCE_REPO_DIR}/${XCF_OUTPUT_DIR}" .
fi

# Manually enable local repo when it is being used locally
echo "Update ${XCF_OUTPUT_DIR}/Package.swift to use local XCF files"