Add templating and template ASTPass.swift #408
Merged
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.
Implementation Overview
Adds templating to ASTPass.swift.
We refactored some of the calls to
process
andpostProcess
as their labels were inconsistently named.Templates have the extension
.template.swift
rather than.swift
.Generated sources are not committed to source control and rather are generated as part of the
generate
target (a requirement ofall
,release
,test
) to the.derived-sources
directory.Adds further node modules as dependencies. We already require node to run truffle so we think the impact of this is minimal. Installation is simplified by a top-level module in the root of the repository, so
npm install
should be run prior to compilation. We decided not to invoke NPM on every build because the installation of dependencies is a one-off process. Opinions on this decision are welcome.Adding new templates requires changes to a few parts of the build setup:
Package.swift
so that the project does not compile the.template.swift
file. We could have chosen a different file extension but these files are still inherently Swift and Xcode highlights any file with the.swift
extension automatically. Unfortunately exclusions don't support globs, or we would've excluded any file ending in.template.swift
..derived-sources
directory toPackage.swift
if templating a file outside of the AST module.We chose nunjucks as other Swift-first templating solutions don't work well on Linux, and nunjucks over jinja as we wanted to avoid adding Python as a(nother) dependency.
Notes
Implemented together with @Aurel300