yonaskolb / yonaskolb/XcodeGen
Support for ${platform} within template and access to ${target_name} without platform suffix
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 8.8k
- Forks
- 908
- Avg merge
- 17d 14h
- Merged PRs (30d)
- 2
Description
When a target is defined with multiple platforms, XcodeGen will generate a unique target for each platform and append the platform name as a suffix. For example, given this spec:
PlatformDemoKit:
type: framework
platform: [iOS, tvOS, watchOS]
templates:
- SharedSource
two platforms will be generated: PlatformDemoKit_iOS and PlatformDemoKit_tvOS. When accessing the ${target_name} variable from a template, the variable seems to include this suffix, which makes sense because it is part of the full target name.
I believe it would also be beneficial to be able to access the target name without the platform suffix and to have access to the ${platform} variable from within a template. This would make templates much more flexible.
Consider the following template:
targetTemplates:
SharedSource:
sources:
- path: ${target_name_no_suffix}
includes:
- "Shared/**"
- "*${platform}*/**"
This template is very similar to the way my targets are set up in my project today. Namely, all platforms for a target share the same root directory (the target name without the suffix). Beneath that, shared sources live in a Shared directory, and platform-specific sources live in a directory that contains the platform name. For example, if a source file lives at iOS+tvOS/Foo.swift, it will be included in PlatformDemoKit_iOS and PlatformDemoKit_tvOS, but not PlatformDemoKit_watchOS.
This does not appear to be possible today using templates because I cannot access the target name without the platform suffix, nor can I access the ${platform} variable.
I used ${target_name_no_suffix} above for illustration purposes, but I do not have a great idea for what the actual name should be. Perhaps something like ${target_root} or ${target_prefix}?
Please let me know if I'm overlooking an existing XcodeGen feature that makes this request superfluous. I'm aware of the templateAttributes field, but these attributes seem useful as standard variables along with `${target_name}.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how targetTemplates expand ${target_name} and how multi-platform targets are named. Review the existing templateAttributes behavior and determine how a platform value and an unsuffixed target name should be exposed; done means the illustrated template can select shared and platform-specific sources for each generated target, with coverage for the new variables.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- build-system, cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100