XcodeGen icon indicating copy to clipboard operation
XcodeGen copied to clipboard

Project w/ 2 app targets loses linked libraries to 2nd app after Xcode modification

Open mthole opened this issue 4 years ago • 7 comments

I have a moderately complex XcodeGen set up involving multiple internal libraries/frameworks and produces multiple application targets. It works great, until you try to modify the project in Xcode (e.g. by adding a new file). Xcode then ends up stripping the libraries from all but the first application target(!)

Simplified Reproduction

I've created a simplified example project to illustrate the issue: XcodeGenBugExample.zip

  1. Download the .zip, use make to run xcodegen on the 3 included projects
➜  XcodeGenBugExample
 make
⚙️  Generating plists...
⚙️  Generating project...
⚙️  Writing project...
Created project at /Users/mthole/XcodeGenTest/LibraryA/LibraryA.xcodeproj
⚙️  Generating plists...
⚙️  Generating project...
⚙️  Writing project...
Created project at /Users/mthole/XcodeGenTest/LibraryB/LibraryB.xcodeproj
⚙️  Generating plists...
⚙️  Generating project...
⚙️  Writing project...
Created project at /Users/mthole/XcodeGenTest/App/App.xcodeproj
  1. Open the App.xcodeproj, and examine the App1 and App2 targets. They both link to the libLibraryA.a and libLibraryB.a libraries. All is well.

image image

  1. Go and add a new .swift file to the App target. (Or do a number of other Xcode operations that trigger whatever re-evaluation is happening...). I added File.swift to the App1 and App2 targets.

  2. Examine the App1 and App2 targets. Notice that App2 is now missing both libLibraryA.a and libLibraryB.a. Sadface!

image image

We expect App1 and App2 to still be linked to both libraries. Mysteriously, only App1 is!?

Next Steps

I've been using Xcode 12.4. If anyone has any ideas, I'm happy to help investigate further here.

mthole avatar Feb 11 '21 00:02 mthole

This seems to be related to projectReferences. If I smash everything into a single .xcodeproj, I cannot reproduce this. (That's not a tenable workaround for my real life use case, unfortunately.)

e.g. a project defined like this behaves as expected

name: App

options:
  minimumXcodeGenVersion: 2.18
  xcodeVersion: 12.4
  deploymentTarget:
    iOS: 13.0

targets:
  App1:
    type: application
    platform: iOS
    sources:
      - path: App.swift
    dependencies:
      - target: LibraryA
      - target: LibraryB
  App2:
    type: application
    platform: iOS
    sources:
      - path: App.swift
    dependencies:
      - target: LibraryA
      - target: LibraryB
  LibraryA:
    type: library.static
    platform: iOS
    sources:
      - path: ../LibraryA
  LibraryB:
      type: library.static
      platform: iOS
      sources:
        - path: ../LibraryB

mthole avatar Feb 11 '21 00:02 mthole

Just wanted to bump this and say I've tested with XcodeGen 2.24.0, but the exact same behavior remains.

mthole avatar Sep 22 '21 21:09 mthole

Have you managed to solve it with projectreferences in Xcodegen 2.26.0?

kbhavyas avatar Feb 18 '22 10:02 kbhavyas

I also want to bump this. I have a similar project structure and am seeing the same behavior described in this issue. I'm running Xcode 14.2 and Xcodegen 2.35.0.

mccorkill1 avatar Jul 25 '23 15:07 mccorkill1

@mthole I am investigating this. Unfortunately, I am not familiar -yet- with Xcodegen's source code. I did try a sort of brute force approach to understanding the issue.

I performed several tests to that effect and this one stands out:

  1. using you starter project, I generated the pbxproj file using xcodegen.
  2. I removed and added back the two libs in BUILD PHASES' section "Link Binary with Libraries" for target APP2. I did nothing else. This resulted in Xcode modifying the pbxproj.
  3. I added a new file. This resulted in no lost references. This tells me that something about that pbxproj is causing Xcode to not strip the libraries references.

Here is a patch that shows the changes made by Xcode in step 2.

The next step would be to identify what is wrong in the xcodegen-generated pbxproj.

ajRiverav avatar Aug 06 '23 18:08 ajRiverav

@mthole since you may be familiar with the generator for this file, does anything stand out?

ajRiverav avatar Aug 07 '23 22:08 ajRiverav

@mthole since you may be familiar with the generator for this file, does anything stand out?

Sorry, nothing jumps out immediately. I've lost most of the context I had here back in 2021.

mthole avatar Aug 07 '23 22:08 mthole