Skip to content

Commit 023b8fe

Browse files
sebstoSebastien Stormacq
andauthored
Simplify local dependency injection for examples (#612)
See issue #536 All the examples are now depending on the runtime library located at `../..`. The `Package.swift` files contain a commented line with the `.package` to use when user wants to fetch the runtime from GitHub. --------- Co-authored-by: Sebastien Stormacq <stormacq@amazon.lu>
1 parent fb31389 commit 023b8fe

File tree

24 files changed

+123
-650
lines changed

24 files changed

+123
-650
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
name: "Integration tests"
3737
examples_enabled: true
38-
matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=../.. swift build"
38+
matrix_linux_command: "swift build"
3939
# We pass the list of examples here, but we can't pass an array as argument
4040
# Instead, we pass a String with a valid JSON array.
4141
# The workaround is mentioned here https://github.com/orgs/community/discussions/11692

.github/workflows/scripts/check-link-foundation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_Foundat
2525
pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}."
2626

2727
# recompile the example without the --static-swift-stdlib flag
28-
LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release || fatal "Failed to build the example."
28+
swift build -c release || fatal "Failed to build the example."
2929

3030
# check if the binary exists
3131
if [ ! -f "${OUTPUT_FILE}" ]; then

Examples/APIGatewayV1/Package.swift

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import PackageDescription
44

5-
// needed for CI to test the local version of the library
6-
import struct Foundation.URL
7-
85
let package = Package(
96
name: "swift-aws-lambda-runtime-example",
107
platforms: [.macOS(.v15)],
118
products: [
129
.executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"])
1310
],
1411
dependencies: [
15-
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
16-
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"),
12+
// For local development (default)
13+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
14+
15+
// For standalone usage, comment the line above and uncomment below:
16+
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
17+
1718
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"),
1819
],
1920
targets: [
@@ -27,30 +28,3 @@ let package = Package(
2728
)
2829
]
2930
)
30-
31-
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
32-
localDepsPath != "",
33-
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
34-
v.isDirectory == true
35-
{
36-
// when we use the local runtime as deps, let's remove the dependency added above
37-
let indexToRemove = package.dependencies.firstIndex { dependency in
38-
if case .sourceControl(
39-
name: _,
40-
location: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
41-
requirement: _
42-
) = dependency.kind {
43-
return true
44-
}
45-
return false
46-
}
47-
if let indexToRemove {
48-
package.dependencies.remove(at: indexToRemove)
49-
}
50-
51-
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
52-
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
53-
package.dependencies += [
54-
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
55-
]
56-
}

Examples/APIGatewayV2+LambdaAuthorizer/Package.swift

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import PackageDescription
44

5-
// needed for CI to test the local version of the library
6-
import struct Foundation.URL
7-
85
let package = Package(
96
name: "swift-aws-lambda-runtime-example",
107
platforms: [.macOS(.v15)],
@@ -13,8 +10,12 @@ let package = Package(
1310
.executable(name: "AuthorizerLambda", targets: ["AuthorizerLambda"]),
1411
],
1512
dependencies: [
16-
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
17-
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"),
13+
// For local development (default)
14+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
15+
16+
// For standalone usage, comment the line above and uncomment below:
17+
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
18+
1819
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"),
1920
],
2021
targets: [
@@ -34,30 +35,3 @@ let package = Package(
3435
),
3536
]
3637
)
37-
38-
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
39-
localDepsPath != "",
40-
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
41-
v.isDirectory == true
42-
{
43-
// when we use the local runtime as deps, let's remove the dependency added above
44-
let indexToRemove = package.dependencies.firstIndex { dependency in
45-
if case .sourceControl(
46-
name: _,
47-
location: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
48-
requirement: _
49-
) = dependency.kind {
50-
return true
51-
}
52-
return false
53-
}
54-
if let indexToRemove {
55-
package.dependencies.remove(at: indexToRemove)
56-
}
57-
58-
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
59-
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
60-
package.dependencies += [
61-
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
62-
]
63-
}

Examples/APIGatewayV2/Package.swift

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import PackageDescription
44

5-
// needed for CI to test the local version of the library
6-
import struct Foundation.URL
7-
85
let package = Package(
96
name: "swift-aws-lambda-runtime-example",
107
platforms: [.macOS(.v15)],
118
products: [
129
.executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"])
1310
],
1411
dependencies: [
15-
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
16-
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"),
12+
// For local development (default)
13+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
14+
15+
// For standalone usage, comment the line above and uncomment below:
16+
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
17+
1718
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"),
1819
],
1920
targets: [
@@ -27,30 +28,3 @@ let package = Package(
2728
)
2829
]
2930
)
30-
31-
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
32-
localDepsPath != "",
33-
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
34-
v.isDirectory == true
35-
{
36-
// when we use the local runtime as deps, let's remove the dependency added above
37-
let indexToRemove = package.dependencies.firstIndex { dependency in
38-
if case .sourceControl(
39-
name: _,
40-
location: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
41-
requirement: _
42-
) = dependency.kind {
43-
return true
44-
}
45-
return false
46-
}
47-
if let indexToRemove {
48-
package.dependencies.remove(at: indexToRemove)
49-
}
50-
51-
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
52-
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
53-
package.dependencies += [
54-
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
55-
]
56-
}

Examples/BackgroundTasks/Package.swift

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
import PackageDescription
44

5-
// needed for CI to test the local version of the library
6-
import struct Foundation.URL
7-
85
let package = Package(
96
name: "swift-aws-lambda-runtime-example",
107
platforms: [.macOS(.v15)],
118
products: [
129
.executable(name: "BackgroundTasks", targets: ["BackgroundTasks"])
1310
],
1411
dependencies: [
15-
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
16-
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0")
12+
// For local development (default)
13+
.package(name: "swift-aws-lambda-runtime", path: "../..")
14+
15+
// For standalone usage, comment the line above and uncomment below:
16+
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
1717
],
1818
targets: [
1919
.executableTarget(
@@ -25,30 +25,3 @@ let package = Package(
2525
)
2626
]
2727
)
28-
29-
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
30-
localDepsPath != "",
31-
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
32-
v.isDirectory == true
33-
{
34-
// when we use the local runtime as deps, let's remove the dependency added above
35-
let indexToRemove = package.dependencies.firstIndex { dependency in
36-
if case .sourceControl(
37-
name: _,
38-
location: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
39-
requirement: _
40-
) = dependency.kind {
41-
return true
42-
}
43-
return false
44-
}
45-
if let indexToRemove {
46-
package.dependencies.remove(at: indexToRemove)
47-
}
48-
49-
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
50-
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
51-
package.dependencies += [
52-
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
53-
]
54-
}

Examples/CDK/Package.swift

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import PackageDescription
44

5-
// needed for CI to test the local version of the library
6-
import struct Foundation.URL
7-
85
let package = Package(
96
name: "swift-aws-lambda-runtime-example",
107
platforms: [.macOS(.v15)],
118
products: [
129
.executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"])
1310
],
1411
dependencies: [
15-
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
16-
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.0.0"),
12+
// For local development (default)
13+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
14+
15+
// For standalone usage, comment the line above and uncomment below:
16+
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
17+
1718
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "1.0.0"),
1819
],
1920
targets: [
@@ -27,30 +28,3 @@ let package = Package(
2728
)
2829
]
2930
)
30-
31-
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
32-
localDepsPath != "",
33-
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
34-
v.isDirectory == true
35-
{
36-
// when we use the local runtime as deps, let's remove the dependency added above
37-
let indexToRemove = package.dependencies.firstIndex { dependency in
38-
if case .sourceControl(
39-
name: _,
40-
location: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
41-
requirement: _
42-
) = dependency.kind {
43-
return true
44-
}
45-
return false
46-
}
47-
if let indexToRemove {
48-
package.dependencies.remove(at: indexToRemove)
49-
}
50-
51-
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
52-
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
53-
package.dependencies += [
54-
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
55-
]
56-
}

Examples/HelloJSON/Package.swift

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
import PackageDescription
44

5-
// needed for CI to test the local version of the library
6-
import struct Foundation.URL
7-
85
let package = Package(
96
name: "swift-aws-lambda-runtime-example",
107
platforms: [.macOS(.v15)],
118
products: [
129
.executable(name: "HelloJSON", targets: ["HelloJSON"])
1310
],
1411
dependencies: [
15-
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
16-
.package(
17-
url: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
18-
from: "2.0.0"
19-
)
12+
// For local development (default)
13+
.package(name: "swift-aws-lambda-runtime", path: "../..")
14+
15+
// For standalone usage, comment the line above and uncomment below:
16+
// .package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "1.0.0"),
2017
],
2118
targets: [
2219
.executableTarget(
@@ -27,30 +24,3 @@ let package = Package(
2724
)
2825
]
2926
)
30-
31-
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
32-
localDepsPath != "",
33-
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
34-
v.isDirectory == true
35-
{
36-
// when we use the local runtime as deps, let's remove the dependency added above
37-
let indexToRemove = package.dependencies.firstIndex { dependency in
38-
if case .sourceControl(
39-
name: _,
40-
location: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
41-
requirement: _
42-
) = dependency.kind {
43-
return true
44-
}
45-
return false
46-
}
47-
if let indexToRemove {
48-
package.dependencies.remove(at: indexToRemove)
49-
}
50-
51-
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
52-
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
53-
package.dependencies += [
54-
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
55-
]
56-
}

0 commit comments

Comments
 (0)