Skip to content

Commit b5a31b4

Browse files
committed
Merge branch 'sebsto/examples' of github.com:sebsto/swift-aws-lambda-runtime into sebsto/examples
2 parents dadc879 + 426e658 commit b5a31b4

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

Plugins/AWSLambdaPackager/Plugin.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,12 @@ struct AWSLambdaPackager: CommandPlugin {
133133
// because Examples' Package.swift have a dependency on ../..
134134
// just like Package.swift's examples assume ../.., we assume we are two levels below the root project
135135
let slice = packageDirectory.pathComponents.suffix(2)
136-
let beforeLastComponent = packageDirectory.pathComponents[slice.startIndex]
137-
let lastComponent = packageDirectory.pathComponents[slice.endIndex - 1]
138136
try Utils.execute(
139137
executable: dockerToolPath,
140138
arguments: [
141139
"run", "--rm", "--env", "LAMBDA_USE_LOCAL_DEPS=true", "-v",
142140
"\(packageDirectory.path())../..:/workspace", "-w",
143-
"/workspace/\(beforeLastComponent)/\(lastComponent)", baseImage, "bash", "-cl", buildCommand,
141+
"/workspace/\(slice.joined(separator: "/"))", baseImage, "bash", "-cl", buildCommand,
144142
],
145143
logLevel: verboseLogging ? .debug : .output
146144
)
@@ -237,17 +235,26 @@ struct AWSLambdaPackager: CommandPlugin {
237235

238236
// add resources
239237
var artifactPathComponents = artifactPath.pathComponents
240-
_ = artifactPathComponents.removeLast()
241-
let artifactDirectory = artifactPathComponents.joined(separator: "/")
242-
let resourcesDirectoryName = "\(packageName)_\(product.name).resources"
243-
let resourcesDirectory = artifactDirectory.appending(resourcesDirectoryName)
244-
let relocatedResourcesDirectory = workingDirectory.appending(path: resourcesDirectoryName)
245-
if FileManager.default.fileExists(atPath: resourcesDirectory) {
246-
try FileManager.default.copyItem(
247-
atPath: resourcesDirectory,
248-
toPath: relocatedResourcesDirectory.path()
249-
)
250-
arguments.append(resourcesDirectoryName)
238+
_ = artifactPathComponents.removeFirst() // Get rid of beginning "/"
239+
_ = artifactPathComponents.removeLast() // Get rid of the name of the package
240+
let artifactDirectory = "/\(artifactPathComponents.joined(separator: "/"))"
241+
for fileInArtifactDirectory in try FileManager.default.contentsOfDirectory(atPath: artifactDirectory) {
242+
guard let artifactURL = URL(string: "\(artifactDirectory)/\(fileInArtifactDirectory)") else {
243+
continue
244+
}
245+
246+
guard artifactURL.pathExtension == "resources" else {
247+
continue // Not resources, so don't copy
248+
}
249+
let resourcesDirectoryName = artifactURL.lastPathComponent
250+
let relocatedResourcesDirectory = workingDirectory.appending(path: resourcesDirectoryName)
251+
if FileManager.default.fileExists(atPath: artifactURL.path()) {
252+
try FileManager.default.copyItem(
253+
atPath: artifactURL.path(),
254+
toPath: relocatedResourcesDirectory.path()
255+
)
256+
arguments.append(resourcesDirectoryName)
257+
}
251258
}
252259

253260
// run the zip tool

0 commit comments

Comments
 (0)