-
-
Notifications
You must be signed in to change notification settings - Fork 518
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 Files Resource Synthesizer #3584
Conversation
@@ -64,7 +64,7 @@ let package = Package( | |||
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "0.4.3")), | |||
.package(url: "https://github.com/maparoni/Zip.git", .revision("059e7346082d02de16220cd79df7db18ddeba8c3")), | |||
.package(url: "https://github.com/tuist/GraphViz.git", .branch("tuist")), | |||
.package(url: "https://github.com/fortmarek/SwiftGen", .branch("stable")), | |||
.package(url: "https://github.com/SwiftGen/SwiftGen", .upToNextMajor(from: "6.5.1")), |
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.
Switched to SwiftGen
repository instead of a fork. The reason behind using a fork was that PathKit
used to be below 1.0.0
in the main repo that has changed.
@@ -0,0 +1,117 @@ | |||
// swiftlint:disable line_length | |||
extension SynthesizedResourceInterfaceTemplates { | |||
static let filesTemplate = """ |
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.
The template is taken from SwiftGen
repository: https://github.com/SwiftGen/SwiftGen/blob/stable/Sources/SwiftGenCLI/templates/files/structured-swift5.stencil
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.
@mollyIV would you mind adding that link in a documentation comment?
let file = name + (ext.flatMap { "." + $0 } ?? "") | ||
fatalError("Could not locate file named" + file) |
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.
These two lines have been modified slightly in order to make the compiler happy:
- let file = name + (ext.flatMap { ".\($0)" } ?? "")
- fatalError("Could not locate file named \(file)")
+ let file = name + (ext.flatMap { "." + $0 } ?? "")
+ fatalError("Could not locate file named" + file)
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.
Any idea why the other code was not working? π€
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.
Basically, the compiler is not happy with it when the content is wrapper into """ """:
let string = """
let name = "a name"
print("Hello \(name)" // <-- The compiler will complain saying "Cannot find 'name' in scope"
"""
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.
I think you just need to escape the \ in this case?
let string = """
let name = "a name"
print("Hello \\(name)" // <-- The compiler will complain saying "Cannot find 'name' in scope"
"""
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.
That's another way of solving the same problem π
Unfortunately didn't find existing unit tests for parsers, neither acceptance tests. What's the recommended strategy of parsers / resource synthesizer testing then? π€ I performed a manual testing and the files parser is working as expected. To test the feature:
Accessing the files:
|
let file = name + (ext.flatMap { "." + $0 } ?? "") | ||
fatalError("Could not locate file named" + file) |
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.
Any idea why the other code was not working? π€
I've created an acceptance test based on your sample project here: 9af9b0d. This will verify that the project generates and builds. It will also run the project's unit tests, so just replace the placeholder in |
Resolves #3583
Short description π
This pull request is adding the support for Files Parser to Resource Synthesizer.
Example of code generated by the bundled template:
I added a few comments to highlight the most important changes and some to ask questions about the implementation π
Checklist β
CHANGELOG.md
has been updated to reflect the changes. In case of a breaking change, it's been flagged as such.