Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(cocoapods 1.1.1) pod install on a project generated by cmake results in broken xcconfig file references #6268

Closed
GoatHunter opened this issue Dec 4, 2016 · 18 comments · Fixed by #9551
Assignees
Labels
s3:detailed Issues with in-depth explanations and examples that make it easier to troubleshoot t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome!
Milestone

Comments

@GoatHunter
Copy link

GoatHunter commented Dec 4, 2016

Report

What did you do?

Run the following commands on the attached project:

  • Note that the python (2.7.x) script works around another bug that makes cocoapods fail when used with cmake generated projects.
  • Note2: cmake version 3.7.1 was used.
 # assuming you're in a bash terminal and cd'd into the directory into which the attached
 # project was extracted.
 cd bin
 cmake ../HelloCocoaPods/ -GXcode
 python ../HelloCocoaPods/fix_pbxproj.py --input HelloCocoaPods.xcodeproj/project.pbxproj 
 pod install
 open HelloCocoaPods.xcworkspace/
 # Now, when in Xcode, compile the project (Xcode 8.1 was used)

What did you expect to happen?

xcconfig references are valid and project compiles successfully.

What happened instead?

Compilation error:
diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

CocoaPods Environment

Stack

   CocoaPods : 1.1.1
        Ruby : ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
    RubyGems : 2.0.14.1
        Host : Mac OS X 10.12.1 (16B2657)
       Xcode : 8.1 (8B62)
         Git : git version 2.9.3 (Apple Git-75)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 0ec2ec9dbf40a5353198ab3aa307644a0b217579

Installation Source

Executable Path: /[redacted]/rubygems/bin/pod

Plugins

cocoapods-deintegrate : 1.0.1
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.1.1
cocoapods-try         : 1.1.0

Podfile

platform :osx, '10.11' 


target "HelloCocoaPods" do
   pod 'Fabric'
end

Project that demonstrates the issue

[CocoapodsCMakeBugReproductionProject.zip]
(https://github.com/CocoaPods/CocoaPods/files/629579/CocoapodsCMakeBugReproductionProject.zip)

@GoatHunter
Copy link
Author

GoatHunter commented Dec 5, 2016

I realize that this happens due to xcconfigs are referenced at $SRCROOT/Pods/... dir, but $SRCROOT is set to HelloCocoaPods path whereas the Pods dir is in the bin directory.
So that's why the references are broken.

@mad-rain
Copy link

Have the same issue. Currently cocoapods is completely unusable with projects being generated by cmake.

@benasher44
Copy link
Member

benasher44 commented Jan 6, 2017

@GoatHunter a PR to fix would be much appreciated! I don't use cmake, so it'd also be helpful if someone with more experience could do some analysis and determine where the bug is, if a PR is too big of an ask.

@GoatHunter
Copy link
Author

@benasher44 Hey, can't commit to a PR atm :-/, but maybe sometime in the near future.

Regarding the analysis, the python script I wrote (attached to the reproduction example project) works around a bug that prevents Cocoapods from running on cmake generated project, so it can be traced back and fixed.

The bug which described in easier to understand using an example:
This is our directory structure:

HelloCocoaPods/main.m
HelloCocoaPods/CMakeLists.txt
bin/

I cd to bin, then run cmake and it generates in bin/HelloCocoaPods.xcodeproj, this causes PROJECT_DIR to be set to HelloCocoaPods/ and not bin/ , meaning that PROJECT_DIR is set to HelloCocoaPods, now, when I run pod install from bin/ it generates bin/Pods, and it also creates xcconfig files with paths used by the xcodeproj for resolving where the path to the project is, and it uses PROJECT_DIR, meaning it looks for Pods under ${PROJECT_DIR}/Pods which is missing, and therefore we get the error above.

One potential fix might be is to tell the pod binary where the Pods dir is e.g pod install --pods_path=~/proj/Example/bin/Pods or so.
Another might be not using PROJECT_DIR in the xcconfigs, but using the current absolute path instead.

In any case, @benasher44, considering my analysis do you think the suggested fixes above are valid or too much of a hack?

@benasher44
Copy link
Member

We already have --project-directory as a flag you can pass to pod install. Would that help?

@benasher44 benasher44 added the s3:detailed Issues with in-depth explanations and examples that make it easier to troubleshoot label Jan 9, 2017
@mad-rain
Copy link

mad-rain commented Mar 4, 2017

--project-directory doesn't help at all for me.

@stale stale bot added the s1:awaiting input Waiting for input from the original author label Jun 2, 2017
@stale
Copy link

stale bot commented Jun 2, 2017

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

@stale stale bot closed this as completed Jul 13, 2017
@stale
Copy link

stale bot commented Jul 13, 2017

This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to open a new one if you still experience this problem 👍

@johnb003
Copy link

Still an issue.

@dnkoutso dnkoutso reopened this Feb 13, 2018
@stale stale bot removed the s1:awaiting input Waiting for input from the original author label Feb 13, 2018
@segiddins segiddins added the t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome! label Feb 13, 2018
@davidstl
Copy link

I am having that issue right now with latest cocoapods.. can't get cocoapods to work at all with my cmake generated projects.

@Extrunder
Copy link

This code fixes path issues with cmake generated projects.

/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.7.0/lib/xcodeproj/project/object/helpers/groupable_helper.rb:140

          def source_tree_real_path(object)
            case object.source_tree
            when '<group>'
              if parent(object).isa == 'PBXProject'
                object.project.project_dir + object.project.root_object.project_dir_path
              else
                real_path(parent(object))
              end
            when 'SOURCE_ROOT'
              object.project.project_dir + object.project.root_object.project_dir_path
            when '<absolute>'
              nil
            else
              Pathname.new("${#{object.source_tree}}")
            end
          end

/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.0.beta.2/lib/cocoapods/installer/analyzer/target_inspection_result.rb:46

        def initialize(target_definition, project, project_target_uuids, build_configurations, platform, archs)
          @target_definition = target_definition
          @project = project
          @project_target_uuids = project_target_uuids
          @build_configurations = build_configurations
          @platform = platform
          @archs = archs
          @client_root = Pathname.new(project.project_dir + project.root_object.project_dir_path).realpath
        end

@mad-rain
Copy link

mad-rain commented Dec 3, 2018

I can confirm that patch actually works! The only remaining problem compiling HelloCocoaPods is that the project is unable to link:

ld: library not found for -lPods-HelloCocoaPods

But it links successfully after copying the lib manually by the command below:

cp build/Debug/libPods-HelloCocoaPods.a Debug/

@KonStg
Copy link

KonStg commented Dec 5, 2018

This could help you to control xcode output location:

install_dir=`pwd`/_install
xcodebuild -workspace project.xcworkspace -scheme ALL_BUILD BUILD_DIR="$install_dir" -configuration Debug -sdk iphoneos

@dnkoutso
Copy link
Contributor

dnkoutso commented Dec 5, 2018

@Extrunder @KonStg would anyone like to make a PR?

@mad-rain
Copy link

mad-rain commented Dec 5, 2018

@KonStg Thanks for the tip!

I have successfully compiled the app using the command below:

xcodebuild -workspace HelloCocoaPods.xcworkspace -scheme ALL_BUILD BUILD_DIR=${PWD} -configuration Debug

But there is still an error when compiling the app directly from Xcode.

@mad-rain
Copy link

@dnkoutso, made two PRs based on @Extrunder fixes.

@dnkoutso
Copy link
Contributor

@mad-rain cool! please add tests for both PRs.

@mad-rain
Copy link

mad-rain commented May 25, 2021

Its still unclear how to build a project without specifying BUILD_DIR in command line. Explicit BUILD_DIR breaks CMake paths for depend static libs. But without BUILD_DIR we're getting errors line this:
ld: library not found for -lPods-HelloCocoaPods

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s3:detailed Issues with in-depth explanations and examples that make it easier to troubleshoot t2:defect These are known bugs. The issue should also contain steps to reproduce. PRs welcome!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants