Prune schemes with a test plan when generating the project with a focused subset of targets
What problem or need do you have?
My project spec includes a couple of extra schemes for the main iOS app that don't work when I use tuist generate MyTarget to focus on a target. I would like for these schemes to not be generated when I've focused on a subset of targets.
Potential solution
If my Project.swift file has additional context about the conditions under which it is being used, I can write code that checks whether to supply the schemes.
One way to do this would be:
- Collect the context into a
Codablestruct:
public struct Context {
/// The path to this manifest file.
public let path: String
/// The list of targets whose sources should be included. All targets if empty.
public let sources: Set<String>
/// The configuration to generate for.
public let configuration: String?
}
- Populate an instance of the context and serialize it as JSON
- Include the serialized context as an argument in
ManifestLoader.buildArguments(_:at:) - Add a
contextproperty toProjectDescription.Environmentthat reads the argument and decodes the context
This context would then be available in all the manifests.
Alternatively we could avoid using Codable and pass separate arguments instead. We'd parse them using ArgumentParser in Environment to populate a context struct.
macOS version
14.5
Tuist version
4.20.0
Xcode version
15.4
@hiltonc, thanks a lot for reporting this one. Would you mind including a project where we can reproduce the issue and the steps to reproduce it? Once we have that, we can then provide what we believe is the most sensible solution that aligns with the principles that we've been embracing.
In trying to create a minimal project to repro this I realized that you already have logic for pruning schemes 🎉. I think I ran into an edge case with my setup though. Here's a minimal project to repro:
-
tuist generate-> generates workspace withApp,Framework1, andCustom Schemeschemes. -
tuist generate Framework1-> generates workspace withFramework1andCustom Schemeschemes. Prints warning about missing target in the scheme:
Loading and constructing the graph
It might take a while if the cache is empty
Using cache binaries for the following targets:
Generating workspace Workspace.xcworkspace
Generating project MainApp
Project generated.
Total time taken: 0.624s
The following warnings need attention:
· Cannot find targets App (App) defined in Custom Scheme
I would expect this scheme to be pruned because App is not included in the focused subset of targets.
It looks like what is happening is that the targets are getting pruned, but the scheme is not because it has a test plan. There's no logic to either (a) prune targets from a test plan, or simpler (b) examine the targets in a test plan and prune the scheme if any of them are pruned.