|
| 1 | +// swift-tools-version: 6.0 |
| 2 | +// The swift-tools-version declares the minimum version of Swift required to build this package. |
| 3 | + |
| 4 | +import PackageDescription |
| 5 | + |
| 6 | +let package = Package( |
| 7 | + name: "Palindrome", |
| 8 | + platforms: [ .macOS(.v15)], |
| 9 | + dependencies: [ |
| 10 | + .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"), |
| 11 | + ], |
| 12 | + targets: [ |
| 13 | + // Targets are the basic building blocks of a package, defining a module or a test suite. |
| 14 | + // Targets can depend on other targets in this package and products from dependencies. |
| 15 | + .executableTarget( |
| 16 | + name: "Palindrome", |
| 17 | + dependencies: [ |
| 18 | + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), |
| 19 | + ]), |
| 20 | + ] |
| 21 | +) |
| 22 | + |
| 23 | +import struct Foundation.URL |
| 24 | + |
| 25 | +if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], |
| 26 | + localDepsPath != "", |
| 27 | + let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), |
| 28 | + v.isDirectory == true |
| 29 | +{ |
| 30 | + // when we use the local runtime as deps, let's remove the dependency added above |
| 31 | + let indexToRemove = package.dependencies.firstIndex { dependency in |
| 32 | + if case .sourceControl( |
| 33 | + name: _, |
| 34 | + location: "https://github.com/swift-server/swift-aws-lambda-runtime.git", |
| 35 | + requirement: _ |
| 36 | + ) = dependency.kind { |
| 37 | + return true |
| 38 | + } |
| 39 | + return false |
| 40 | + } |
| 41 | + if let indexToRemove { |
| 42 | + package.dependencies.remove(at: indexToRemove) |
| 43 | + } |
| 44 | + |
| 45 | + // then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) |
| 46 | + print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") |
| 47 | + package.dependencies += [ |
| 48 | + .package(name: "swift-aws-lambda-runtime", path: localDepsPath) |
| 49 | + ] |
| 50 | +} |
0 commit comments