Skip to content

Target template path resolution #521

Open
@haritowa

Description

@haritowa

Hi, I’m trying to organize a monorepo project using XcodeGen. My general module structure looks like:

.
├── Core
│   ├── Sources
│   │   └── CoreClass.swift
│   ├── TestData
│   ├── Tests
│   └── project.yml
├── SomeFeature
│   ├── Sources
│   │   └── SomeFeature.swift
│   ├── TestData
│   ├── Tests
│   └── project.yml
└── baseProject.yml

Where Sources is lib sources, TestData contains mocks and stubs, Tests contains tests and so on. Each module will have several development targets(main, tests, test data, etc), so I’m trying to use target templates feature to formalize and automate development process.

name: BaseProject
targetTemplates:
  Core:
    platform: iOS
    type: framework
    info:
      path: $target_name_info.plist
    sources: Sources
    scheme:
      testTargets:
        - $target_nameUnitTests
      gatherCoverageData: true
  CoreUnitTests:
    platform: iOS
    type: bundle.unit-test
    sources: Tests

All templates are described in the baseProject.yml file(which is located in the root folder). Module spec is located in the module directory(Core/project.yml; Feature/Auth/project.yml, for example). Each module spec includes baseProject, so it looks like:

name: Core
include:
  - path: ../baseProject.yml
    relativePaths: false
targets:
  Core:
    templates: 
      - Core
  CoreUnitTests:
    templates:
      - CoreUnitTests

Unfortunately, target templates are resolved after the path resolution process, so all paths are always the same, no matter where base spec is included from.

For example, let’s take a project with two modules: A and B. B depends on A (project.zip).

.
├── A
│   ├── Sources
│   │   └── AClass.swift
│   └── project.yml
├── B
│   ├── Sources
│   │   └── BClass.swift
│   └── project.yml
└── baseProject.yml

XcodeGen for B spec (xcodegen -s B/project.yml) ends up with a messed project, where both A and B Sources folder is B/Sources.

So, my question is: is it a bug, intended behavior or limitation? I “fixed” it, so now XcodeGen suits my needs, but I may create a PR if you want similar behavior in the upstream.

Same config and actions with my version leads to this result:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions