33import PackageDescription
44
55// needed for CI to test the local version of the library
6- import class Foundation. ProcessInfo
76import struct Foundation. URL
87
98#if os(macOS)
@@ -16,17 +15,16 @@ let package = Package(
1615 name: " swift-aws-lambda-runtime-example " ,
1716 platforms: platforms,
1817 products: [
19- . executable( name: " APIGAtewayLambda " , targets: [ " APIGAtewayLambda " ] )
18+ . executable( name: " APIGatewayLambda " , targets: [ " APIGatewayLambda " ] )
2019 ] ,
2120 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 " ) ,
2624 ] ,
2725 targets: [
2826 . executableTarget(
29- name: " APIGAtewayLambda " ,
27+ name: " APIGatewayLambda " ,
3028 dependencies: [
3129 . product( name: " AWSLambdaRuntime " , package : " swift-aws-lambda-runtime " ) ,
3230 . product( name: " AWSLambdaEvents " , package : " swift-aws-lambda-events " ) ,
@@ -36,20 +34,29 @@ let package = Package(
3634 ]
3735)
3836
39- if let localDepsPath = ProcessInfo . processInfo . environment [ " LAMBDA_USE_LOCAL_DEPS " ] ,
37+ if let localDepsPath = Context . environment [ " LAMBDA_USE_LOCAL_DEPS " ] ,
4038 localDepsPath != " " ,
4139 let v = try ? URL ( fileURLWithPath: localDepsPath) . resourceValues ( forKeys: [ . isDirectoryKey] ) ,
42- let _ = v. isDirectory
40+ v. isDirectory == true
4341{
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 ../..)
4458 print ( " [INFO] Compiling against swift-aws-lambda-runtime located at \( localDepsPath) " )
4559 package . dependencies += [
4660 . package ( name: " swift-aws-lambda-runtime " , path: localDepsPath)
4761 ]
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- ]
5562}
0 commit comments