3
3
import PackageDescription
4
4
5
5
// needed for CI to test the local version of the library
6
- import class Foundation. ProcessInfo
7
6
import struct Foundation. URL
8
7
9
8
#if os(macOS)
@@ -16,17 +15,16 @@ let package = Package(
16
15
name: " swift-aws-lambda-runtime-example " ,
17
16
platforms: platforms,
18
17
products: [
19
- . executable( name: " APIGAtewayLambda " , targets: [ " APIGAtewayLambda " ] )
18
+ . executable( name: " APIGatewayLambda " , targets: [ " APIGatewayLambda " ] )
20
19
] ,
21
20
dependencies: [
22
- // dependency on swift-aws-lambda-runtime is added dynamically below
23
- // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
24
-
25
- . package ( url: " https://github.com/swift-server/swift-aws-lambda-events.git " , branch: " main " )
21
+ // during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
22
+ . package ( url: " https://github.com/swift-server/swift-aws-lambda-runtime.git " , branch: " main " ) ,
23
+ . package ( url: " https://github.com/swift-server/swift-aws-lambda-events.git " , branch: " main " ) ,
26
24
] ,
27
25
targets: [
28
26
. executableTarget(
29
- name: " APIGAtewayLambda " ,
27
+ name: " APIGatewayLambda " ,
30
28
dependencies: [
31
29
. product( name: " AWSLambdaRuntime " , package : " swift-aws-lambda-runtime " ) ,
32
30
. product( name: " AWSLambdaEvents " , package : " swift-aws-lambda-events " ) ,
@@ -36,20 +34,29 @@ let package = Package(
36
34
]
37
35
)
38
36
39
- if let localDepsPath = ProcessInfo . processInfo . environment [ " LAMBDA_USE_LOCAL_DEPS " ] ,
37
+ if let localDepsPath = Context . environment [ " LAMBDA_USE_LOCAL_DEPS " ] ,
40
38
localDepsPath != " " ,
41
39
let v = try ? URL ( fileURLWithPath: localDepsPath) . resourceValues ( forKeys: [ . isDirectoryKey] ) ,
42
- let _ = v. isDirectory
40
+ v. isDirectory == true
43
41
{
42
+ // when we use the local runtime as deps, let's remove the dependency added above
43
+ let indexToRemove = package . dependencies. firstIndex { dependency in
44
+ if case . sourceControl(
45
+ name: _,
46
+ location: " https://github.com/swift-server/swift-aws-lambda-runtime.git " ,
47
+ requirement: _
48
+ ) = dependency. kind {
49
+ return true
50
+ }
51
+ return false
52
+ }
53
+ if let indexToRemove {
54
+ package . dependencies. remove ( at: indexToRemove)
55
+ }
56
+
57
+ // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
44
58
print ( " [INFO] Compiling against swift-aws-lambda-runtime located at \( localDepsPath) " )
45
59
package . dependencies += [
46
60
. package ( name: " swift-aws-lambda-runtime " , path: localDepsPath)
47
61
]
48
-
49
- } else {
50
- print ( " [INFO] LAMBDA_USE_LOCAL_DEPS is not pointing to your local swift-aws-lambda-runtime code " )
51
- print ( " [INFO] This project will compile against the main branch of the Lambda Runtime on GitHub " )
52
- package . dependencies += [
53
- . package ( url: " https://github.com/swift-server/swift-aws-lambda-runtime.git " , branch: " main " )
54
- ]
55
62
}
0 commit comments