Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for resources when packaging using the SwiftPM plugin #333

Merged
merged 6 commits into from
Aug 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Plugins/AWSLambdaPackager/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,27 @@ struct AWSLambdaPackager: CommandPlugin {
try FileManager.default.copyItem(atPath: artifactPath.string, toPath: relocatedArtifactPath.string)
try FileManager.default.createSymbolicLink(atPath: symbolicLinkPath.string, withDestinationPath: relocatedArtifactPath.lastComponent)

// add resources
let contentsDirectory = workingDirectory.appending("Contents")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need a Contents directory ? Maybe Resources is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some more testing the correct bundle to use is Bundle.module. So instead of recreating the Contents directory I am just copying the .resources directory that is in the artifacts directory to the working directory to be zipped. This has the benefit of working on Lambda as well as when running locally on macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try FileManager.default.createDirectory(atPath: contentsDirectory.string, withIntermediateDirectories: true)
let relocatedResourcesDirectory = contentsDirectory.appending("Resources")
let artifactDirectory = artifactPath.removingLastComponent()
let resourcesDirectoryName = try FileManager.default.contentsOfDirectory(atPath: artifactDirectory.string)
.first(where: { $0.hasSuffix(".resources") && $0.contains(product.name) })
if let resourcesDirectoryName {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use guard or if on line 210. This line is not necessary

let resourcesDirectory = artifactDirectory.appending(resourcesDirectoryName)
try FileManager.default.copyItem(atPath: resourcesDirectory.string, toPath: relocatedResourcesDirectory.string)
}

#if os(macOS) || os(Linux)
let arguments = ["--junk-paths", "--symlinks", zipfilePath.string, relocatedArtifactPath.string, symbolicLinkPath.string]
let arguments = [
"--recurse-paths",
"--symlinks",
zipfilePath.lastComponent,
relocatedArtifactPath.lastComponent,
symbolicLinkPath.lastComponent,
contentsDirectory.lastComponent,
]
#else
let arguments = [String]()
throw Errors.unsupportedPlatform("can't or don't know how to create a zip file on this platform")
Expand All @@ -213,6 +232,7 @@ struct AWSLambdaPackager: CommandPlugin {
try self.execute(
executable: zipToolPath,
arguments: arguments,
customWorkingDirectory: workingDirectory,
logLevel: verboseLogging ? .debug : .silent
)

Expand Down