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

Open
GoatHunter opened this issue Dec 4, 2016 · 17 comments

Comments

@GoatHunter
Copy link

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link

commented Dec 23, 2016

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

@benasher44

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented Jan 8, 2017

@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

This comment has been minimized.

Copy link
Member

commented Jan 9, 2017

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

@Zer0xFF Zer0xFF referenced this issue Feb 9, 2017
10 of 10 tasks complete
@mad-rain

This comment has been minimized.

Copy link

commented Mar 4, 2017

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

@stale stale bot added the s1:awaiting input label Jun 2, 2017

@stale

This comment has been minimized.

Copy link

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 Jul 13, 2017

@stale

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Feb 13, 2018

Still an issue.

@davidstl

This comment has been minimized.

Copy link

commented Sep 25, 2018

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

@Extrunder

This comment has been minimized.

Copy link

commented Dec 3, 2018

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2018

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

@mad-rain

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Dec 14, 2018

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

@dnkoutso

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.