Easiest way to update lldb.xcodeproj/project.pbxproj?

(Marc Rasi) #1

I'd like to add some files to lldb.xcodeproj/project.pbxproj. (Because I added some files in https://github.com/apple/swift-lldb/pull/1269 and didn't add them to lldb.xcodeproj/project.pbxproj, without realizing that the Mac build needed them in lldb.xcodeproj/project.pbxproj).

If I try to open the project in XCode and add files through the UI, XCode makes a huge change in lldb.xcodeproj/project.pbxproj that reorders a bunch of stuff and changes some comments. I tried XCode 9.4.1 and XCode 10.1.

I notice that the git history for lldb.xcodeproj/project.pbxproj is full of small commits that just add a few files. Is there an easy way to achieve this? I think I could probably manually figure out the edits that I need, but that seems a bit tedious, so I'm wondering if there is a more automatic way.

(Adrian Prantl) #2

There is a sort-pbxproj.rb script in scripts/ that should help with this.

1 Like
(Marc Rasi) #3

Awesome, that makes the diff much smaller. Exactly what I was looking for. Thanks!

1 Like
(Marc Rasi) #4

In case anyone is searching for answers in the future, here's the full process I used to add files to lldb.xcodeproj/project.pbxproj.

First, open the lldb repo directory on a Mac with XCode and double click on "lldb.xcodeproj". Then, for each file that you want to add,

  1. Figure out where it should go in the project. You can guess based on where the file is located in the directory structure. For example, "Source/Plugins/Language/Swift/SwiftCodeCompletion.cpp" should go in "Source > Plugins > Language > Swift". To be completely sure, look at where adjacent files are included in the project (e.g. notice that "Source/Plugins/Language/Swift/SwiftLanguage.cpp" is in "Source > Plugins > Language > Swift").
  2. Determine what the target membership for the file should be. One way to do this is to open similar files and see what is checked on the "Target Membership" section of the bar on the right side of XCode.
  3. On the bar on the left side of XCode, navigate to the project location where the file should go. Right click it and select "Add files to lldb".
  4. A dialog will pop up. Select the file that you want to add. Set the target membership to whatever you determined in step 2. Click "Add".

Finally, run scripts/sort-pbxproj.rb.

(edited: I said wrong things about target membership. I think I fixed them now.)

1 Like
(Jim Ingham) #5

Marc rules are good. Couple of other details:

  1. If you are adding a file that is or should be in llvm.org lldb, then you must add the file to the xcode project in the llvm.org repository first. Then merge the change from that repository to the swift repository. Entries in the Xcode Project have a GUID, and if the same file gets added on the llvm.org side and the swift.org side, they will have different GUID's and many things will go wrong. Any change that is not swift specific should first go into llvm.org.

  2. For pretty much everything you are likely to add, the lldbcore target is the right target.

  3. We do add header files to the project as well as .cpp files. That way you can search, set persistent breakpoints, etc in them more effectively. But, while we add header files to the project, we don't add them to any target. That's because if we do Xcode will use it's header map magic to find intra-project header dependencies, which can make the Xcode build different from the cmake build in confusing and hard to diagnose ways.

  4. SB files are the exception to rules 2 & 3. SB API files all go in the API group. Both the .cpp and .h files get added to the lldb framework target. The .h files get set to Public (in the RHS inspector). That will cause them to get copied into the Framework headers.