wojciech-kulik / xcodebuild.nvim

Neovim plugin to Build, Debug, and Test applications created for Apple devices (iOS, macOS, watchOS, etc.)
MIT License
707 stars 18 forks source link

Adding files to Pods project when dealing with internal libs/pods #227

Open iMostfa opened 3 weeks ago

iMostfa commented 3 weeks ago

Hi, part of this issue #199 i found/faced a problem where adding a file to a local lib isn't working. in my initial (private project) it didn't show any error.

i tried to create a simple project to reproduce the issue here, and while creating it i got an error printed (as shown in the video)

https://github.com/iMostfa/SimpleNvimXcodeBuildProject

https://github.com/user-attachments/assets/f0c3b892-ad94-439b-a17d-d5fe61b0e886


  project_manager = {
        project_for_path = function(path)
          print(path)
          return "/Users/mostafa.essam/Desktop/SimpleNvimXcodeBuildProject/Pods/Pods.xcodeproj"
        end,
      },

could be that i faced two different problems ? i don't know.

i really thank you for your effort and huge work, i think that i'm coming with edge cases, also CocoaPods is kinda legacy, so i would understand if it's not a priority to tackle all problems related to it 🙏🏻

iMostfa commented 3 weeks ago

@wojciech-kulik to reproduce you can try to add a new file to the InternalLibrary folder.

Screenshot 2024-11-06 at 02 27 31
wojciech-kulik commented 3 weeks ago

Thank you for reporting the issue and for the sample project! I will take a look at it in the coming days.

In the meantime, could you try disabling guess_target and see if it changes anything?

  project_manager = {
    guess_target = false,
  }
iMostfa commented 3 weeks ago

no any change, still same error.

now since we are disucssing it, i think it could be confusing to have guess_target inside the integrations.nvim_tree, and inside project_manager

image
wojciech-kulik commented 3 weeks ago

It was changed in v4.0.0, now most of settings have been moved from specific integrations to general project_manager :). Check out wiki for the latest version of the config or :h xcodebuild.config

wojciech-kulik commented 3 weeks ago

Thank you for becoming the sponsor! I added you to "Sponsors" section in the README 🍻

wojciech-kulik commented 1 week ago

@iMostfa I think I was able to add support for development pods. Please switch to that branch and see if it works: https://github.com/wojciech-kulik/xcodebuild.nvim/pull/246

I checked on your project and it works, but you need to fix one thing. Your directory is named InternalLibrary but your pod is named internalLibrary. Therefore, if your run pod install it will generate internalLibrary group in your Pod project and the plugin won't be able to find the correct group. So you need to rename your dir to: internalLibrary.

Let me know if it works :)

wojciech-kulik commented 1 week ago

I noticed one problem. Your pod is mapping files from Classes to pod root and the plugin is not aware that there is a difference between the path that you have in internalLibrary and the path within Pods.xcodeproj. Adding new files should work well, but renaming old files or new files after running pod install may not work.

At this point, I think it would be hard to support it. As a workaround, you could change the podspec to:

  spec.source_files = "**/*.{h,m,swift}"

but you also must have at least 2 folders, otherwise Pods will flatten the structure.

iMostfa commented 1 week ago

Hi, thank a lot for the support.

i created the example project as a showcase for the problem, and it worked inside it after applying your suggested fixes.

yet, it didn't work on my -production- project, i see the message that a file was created and added in the target i selected, but in reality it wasn't added anywhere.

do you know if there's aways to attach any kind of logs for you ?

also, maybe it's out of context, but how do you debug the plugin ? is there a thing like this in nvim/lua ? or it's just relying on logs and text ? no breakpoints or any way to help you(or even me) debug a problem ?

wojciech-kulik commented 1 week ago

I just add prints here and there :D I saw somewhere that it’s possible to configure a debugger for lua but I haven’t done it yet. Regarding adding files the main part is in the ruby code in plugin’s tools directory. You could add there some print using “puts”

wojciech-kulik commented 1 week ago

Most likely the issue is with the folder structure.

If you add a file in:

/repo/your_pod/folder/file.swift

the plugin checks your Pods.xcodeproj location and takes its parent directory, so if you have:

/repo/Pods/Pods.xcodeproj

it takes

/repo

and it removes this path from your new file path to obtain the relative path dir path. So now you have:

your_pod/folder

Next, in your Pods.xcodeproj it is checked if a group with that path exists.

My guess is that there is a problem with paths, so it is unable to get the correct relative path. Please analyze this approach and let me know what's wrong.

This approach above assumes that your structure is:

-- root
---- SomePod
---- Pods
------ Pods.xcodeproj

If you have for example your pod libs in a nested folder, it won't work. Let me know what's your structure, maybe I will be able to make it more flexible.

wojciech-kulik commented 1 week ago

I added one more improvement to read Podfile and detect base path for pods, so that they can be structured like that:

-- root
---- SomeDir
------ Pod1
------ Pod2
---- Pods
------ Pods.xcodeproj

See if it helps

wojciech-kulik commented 1 week ago

I also wonder if it wouldn't be simpler to just run pod install whenever you change some Pod files?

You could even detect it in

        should_update_project = function(path) -- path can lead to directory or file
          return true
        end,

run pod install and return false

wojciech-kulik commented 1 week ago

@iMostfa Did you manage to check the updated version?