I have a simple task… I just want to output a version number when I run
langsrv -v. Is that so hard? Well, if you’re using Swift, yes.
I make mistakes, so manual steps for me are both error prone and tiresome. When I update the version, I also need to make sure my git tag will be correct. So… how do we accomplish this in Swift?
Just follow these easy steps!
- Create a
Makefile– yep, just get used to it. SwiftPM should be though of as simply the mechanism to save you from writing some of the
swiftcarguments directly. Sure, it also makes downloading some dependencies a bit easier too.
- Create a new module, say
- Create a template Swift file, say
- Create a version info file, say
- Create a script that will parse that
VersionInfo.yamlfile and generate the appropriate
- Import your
VersionInfomodule in your
- Reference that version info however you’d like.
- Update your
Makefileto include a
tagto create the correct git tag.
Yeah… I think that is all of the steps.
And finally, my
Now when I want to update the version, I simply edit the
VersionInfo.yaml file, build, and run
make tag before I push my changes.
Of course, if we had compiler variables in Swift, I could have avoided nearly all of this work…