yonaskolb / XcodeGen

A Swift command line tool for generating your Xcode project
MIT License
6.88k stars 809 forks source link

Specify additional build/run targets for target-scheme #1456

Open Uki19 opened 4 months ago

Uki19 commented 4 months ago

Similarly to testTargets, it would be useful to be able to define additional targets within target-scheme.

For example, Widgets target scheme should have AppTarget added as build target, but currently it doesn't seem possible.

targets:
  AppTarget:
     ...

  Widgets:
      type: app-extension
      subtype: widgetkit-extension
      platform: iOS
      deploymentTarget: 15.0
      configFiles:
        DEV Debug: some-dev.xcconfig
        DEV Release: some-dev.xcconfig
        PROD Debug: some-prod.xcconfig
        PROD Release: some-prod.xcconfig
      scheme:
        configVariants:
          - DEV
          - PROD

It is possible to do using top level scheme, but since we have 3+ configVariants in 3+ app "flavours" (whitelabel app), we'd like to rely on using configVariants and avoid manually specifying scheme for each target/config/flavour combination

yonaskolb commented 2 months ago

@Uki19 do you have a proposal for how this would look? Also if using the more fully featured schemes is difficult, there are also scheme templates that may cut down on the boilerplate required for you, if you weren't aware of them https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#scheme-template

Uki19 commented 2 months ago

for example, there could be buildTargets or additionalTargets, like there's testTargets option:

targets:
  AppTarget:
     ...

  Widgets:
      type: app-extension
      subtype: widgetkit-extension
      platform: iOS
      deploymentTarget: 15.0
      configFiles:
        DEV Debug: some-dev.xcconfig
        DEV Release: some-dev.xcconfig
        PROD Debug: some-prod.xcconfig
        PROD Release: some-prod.xcconfig
      scheme:
        configVariants:
          - DEV
          - PROD
        buildTargets: <-- here
           - AppTarget: all
           - AppIntentsExtension: all
           ...

AppTarget name could be derived via target_name variable, or passed in as templateAttributes:

// templates:
Widgets:
    ...
    buildTargets: <-- here
      - ${mainTargetName}: all
      - ${mainTargetName}ntentsExtension: all

// actual targets:
targets:
    AppWidgets:
       templates:
         - Widgets
       templateAttributes:
         mainTargetName: App

We ended up using schemeTemplates for now which did reduce the boilerplate, but this could help us improve it even further 🙂