yonaskolb / XcodeGen

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

Including target from existing external Xcode project #806

Open mobileben opened 4 years ago

mobileben commented 4 years ago

I'm currently working on a build system that uses prebuilts for dependency frameworks/libraries. We want the ability to use the project file instead of the prebuilt library for debug. I have a model working which I manually built a workspace, but am aiming to build this workspace dynamically with xcodegen. This is because the blend of prebuilts to projects is dependent upon the scenario. The main application project always exists in the workspace.

The key to how this works is creating a "bootstrap" project. This bootstrap contains an aggregate target which is really just a dummy target for the scheme. The scheme does all the work to make this work. The scheme contains a preaction script. This preaction script copies over necessary configurations (in particular, anxcconfig file). The scheme also has the application's target as a build target.

There are really 2 issues here I've encountered when trying to get xcodegen to generate the bootstrap project file.

So the two questions are:

Note I generate the workspace with XcodeProj. The code seems relatively difficult for creating the project and adding custom schemes (based on looking at some of the XcodeGen code). Thus why I'm looking at this. Right now the plan is to call do this via the command line, but ideally I'd like to do this via using XcodeGen as a library, but it also isn't clear in this latter case if I lose the niceties done by the generate command.

mobileben commented 4 years ago

I've made some progress in this, but also some setbacks.

For example the start of the script in the YAML looks like

      preActions:
        - name: Bootstrap Script
          script: |+
            #!/bin/bash
            # Update xcconfig and yaml or remove if doesn't exist
            # yaml probably should go elsewhere but for making this easier right now, this is where they all go
            XCCONFIG="Custom.xcconfig"\n
            FRAMEWORKS_YAML="frameworks.yml"
            RESOURCES_YAML="resources.yml"

I'm not an YAML expert, but from my understanding |+ should keep newlines. Instead this gets inserted as one full line, which, because there is a she bang and comments up front ... means this script does nothing.

Some other issues I've run in.

The trick seems to use projectReferences, however I'd like to have a projectReference where in the end, the project is not inserted in the project. I really only need to scheme to hold the path to the project. But otherwise, this is not needed in my case.

Some of the items listed above still hold (like not being able to define the shell for the preaction).