Idea - Chaining spec generation using projectReferences #891
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.
👋 I've been spending some time recently working out a plan for modularising our project and have been looking into recent discussions in the issues about how XcodeGen might be able to further help with this.
It mostly relates to the RFC/thread for workspace generation (#168) back in 2017, however since the original discussion, XcodeGen has grown quite a bit and now has support for things like subprojects using projectReferences that were introduced in #701.
From my (somewhat limited) understanding of the project, the projectReferences seem like a potentially good candidate for expansion to allow the automatic generation of a number of Xcode Projects so I tried putting some feelers out there in #776 but didn't get much of a response. Since I had some time this weekend, I wanted to give a POC a go to better understand things.
In this draft PR, I've expanded
SpecLoader
to introduce a new method:This method combined with the new optional
spec
property on aProjectReference
allows the loader to resolve all dependant specs in order to compute an array ofProject
objects that can then be passed into the generator to generate dependant projects in the correct order.As an example, lets say that I have the following specs in my workspace:
./Global/project.yml
./Frameworks/project.yml
./GlobalCore/project.yml*
./GlobalFeatures/Settings/project.yml
I can now run the generator command on my entry project, I'll get the following output:
As a result, I then end up with all four projects generated as I expect! This helps me to avoid having to maintain a wrapping script for XcodeGen that currently consists of me manually invoking the generator a given number of times since all of the specs are detected based on my
projectReferences
that I already have to define anyway 🚀So, while all of this works, it's far from being correct. I've identified a number of things that would probably need addressing before hand, but before we look into that, I want to get some thoughts on the concept in general 🙏
Here are a few things to discuss:
xcodegen
the CLI is very tailored to a specific project/spec since bothGenerateCommand
andDumpCommand
inherit fromProjectCommand
. Would this still make sense? Should this feature be implemented into a new command entirely, or should the existing CLI commands be rearchitected?dump
by being able to visualise the workspace/repo's dependencies cross-projectsprojectReferences
is keyed by thename
that is used for reference in the spec, this has the potential to be different to the name of the actual project and this could get confusing but this can't be solved unless we load the referenced specs before resolving the project itself.project
but maybe that breaks things since there are now multiple. Might be better to investigate loading multipleSpecFile
objects first and resolving them first?path
andspec
inProjectReference
could lead to misconfigurations where the same spec points to different project paths, or different project paths use the same spec. We can validate against that but maybe there would also be a way to avoid this?projectReferences
the right approach to this? By doing so, it means that you can use them both with existing xcodeproj references and also specs to be generated. I think that's a good thing but I might be overlooking something?I'm really keen to help out on a feature like this, but I think the idea still needs fleshing out a bit so any input on this would be great! Thanks!