-
Notifications
You must be signed in to change notification settings - Fork 113
Add support for resources when packaging using the SwiftPM plugin #333
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
Merged
sebsto
merged 6 commits into
swift-server:main
from
camdenfullmer:plugin-resources-support
Aug 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86dd1a7
Add support for resources when packaging using the SwiftPM plugin.
camdenfullmer 91e0fec
Merge branch 'main' into plugin-resources-support
sebsto 7554ed7
Copy the resources directory to the working directory instead of recr…
camdenfullmer 05dee34
Add resource packaging example.
camdenfullmer 33f2952
Use the bundle's url function to locate the file url.
camdenfullmer 7623f28
Fix year for soundness check.
camdenfullmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use |
||
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") | ||
|
@@ -213,6 +232,7 @@ struct AWSLambdaPackager: CommandPlugin { | |
try self.execute( | ||
executable: zipToolPath, | ||
arguments: arguments, | ||
customWorkingDirectory: workingDirectory, | ||
logLevel: verboseLogging ? .debug : .silent | ||
) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ? MaybeResources
is enoughThere was a problem hiding this comment.
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 theContents
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package#Access-a-resource-in-code