Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Compute PODS_ROOT Path relative to xcode project folder #138

Closed
wants to merge 6 commits into from

2 participants

@subdigital

This is just a start. I haven't verified this on my current project yet as the xcodeproject gem is choking on my project's plist values.

Any tips or ideas on how best to test this?

Summary of changes:

  • config now has a source_root option that defaults to the project_root. If an argument is passed in to the install command, source_root will contain the directory of the project file specified.
  • PODS_ROOT is now set to a path relative to the passed in project
  • PODS_ROOT is now used everywhere instead of SOURCE_ROOT
@alloy
Owner

I would add a unit test for the pods_path_relative_to_project method, with different values, and another one that checks that the xcconfig value changes too. (Both of these should go into https://github.com/CocoaPods/CocoaPods/blob/master/spec/unit/installer_spec.rb)

And I think that in this case it makes sense to add an example app to ./examples which uses this feature, which we can then run with the rake task: rake examples:build. (Unfortunately we can’t run those on Travis-CI, but these should be run before we release, so it’s a good integration check nonetheless.)

@subdigital

I put the target installer specs in a new file. It seemed to clutter up installer_specs with unrelated context/setup.

I'll work on the example app now.

@subdigital

I have it working in the example app, but there is a bit of a snag. If you ever type pod install without the project argument, then everything gets regenerated with the defaults.

I'm wondering if we need some sort of .pods metadata file so that we can keep track of where the xcodeproj is.

@alloy
Owner

Good point. I think we should glob the current work directory for *.xcodeproj and if it’s just one assume that that is the one to use, otherwise let people define the path to the xcodeproj from the Podfile.

This will be needed at some point anyways for once we support multiple xcodeprojs (multiple platforms) in one workspace anyways (see #76 and #63).

Something like:

xcodeproj 'subdir/App.xcodeproj'

For now the attribute could just be defined on the Podfile class directly, but later on we should move it to the TragetDefinition for multiple xcodeproj support.

This means that specifying the project to use to pod install will be deprecated.

@subdigital
@alloy
Owner

Yup!

@alloy alloy referenced this pull request
Closed

Relative pod root #154

@subdigital

Closing in favor of 154.

@subdigital subdigital closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -15,3 +15,4 @@ spec/fixtures/integration/Headers/
pod
/concatenated.*
spec/fixtures/mercurial-repo/.hg/*cache
+spec/fixtures/mercurial-repo/.hg/store/phaseroots
View
1  lib/cocoapods/command/install.rb
@@ -27,6 +27,7 @@ def initialize(argv)
config.clean = !argv.option('--no-clean')
@update_repo = !argv.option('--no-update')
@projpath = argv.shift_argument
+ config.source_root = Pathname.new(@projpath) if @projpath
super unless argv.empty?
end
View
6 lib/cocoapods/config.rb
@@ -10,7 +10,7 @@ def self.instance=(instance)
@instance = instance
end
- attr_accessor :repos_dir, :project_root, :project_pods_root, :rootspec, :clean, :verbose, :silent
+ attr_accessor :repos_dir, :project_root, :source_root, :project_pods_root, :rootspec, :clean, :verbose, :silent
alias_method :clean?, :clean
alias_method :verbose?, :verbose
alias_method :silent?, :silent
@@ -26,6 +26,10 @@ def project_root
@project_root ||= Pathname.pwd
end
+ def source_root
+ @source_root ||= project_root
+ end
+
def project_pods_root
@project_pods_root ||= project_root + 'Pods'
end
View
8 lib/cocoapods/generator/copy_resources_script.rb
@@ -8,12 +8,12 @@ class CopyResourcesScript
{
case $1 in
*\.xib)
- echo "ibtool --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename $1 .xib`.nib ${SRCROOT}/Pods/$1 --sdk ${SDKROOT}"
- ibtool --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename $1 .xib`.nib ${SRCROOT}/Pods/$1 --sdk ${SDKROOT}
+ echo "ibtool --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename $1 .xib`.nib ${PODS_ROOT}/$1 --sdk ${SDKROOT}"
+ ibtool --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename $1 .xib`.nib ${PODS_ROOT}/$1 --sdk ${SDKROOT}
;;
*)
- echo "cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
- cp -R "${SRCROOT}/Pods/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
+ echo "cp -R ${PODS_ROOT}/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
+ cp -R "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
;;
esac
}
View
2  lib/cocoapods/installer.rb
@@ -170,7 +170,7 @@ def configure_project(projpath)
end
copy_resources = app_project.add_shell_script_build_phase('Copy Pods Resources',
-%{"${SRCROOT}/Pods/Pods-resources.sh"\n})
+%{"${PODS_ROOT}/Pods-resources.sh"\n})
app_project.targets.each { |target| target.buildPhases << copy_resources }
app_project.save_as(projpath)
View
8 lib/cocoapods/installer/target_installer.rb
@@ -10,10 +10,16 @@ def initialize(podfile, project, definition)
@podfile, @project, @definition = podfile, project, definition
end
+ def pods_path_relative_to_project
+ pods_path = Pathname.new(config.project_pods_root)
+ source_path = Pathname.new(config.source_root)
+ Pathname.new(pods_path).relative_path_from(source_path)
+ end
+
def xcconfig
@xcconfig ||= Xcodeproj::Config.new({
# In a workspace this is where the static library headers should be found.
- 'PODS_ROOT' => '$(SRCROOT)/Pods',
+ 'PODS_ROOT' => "$(SRCROOT)/#{pods_path_relative_to_project}",
'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/Headers"',
'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build
# This makes categories from static libraries work, which many libraries
View
4 spec/unit/installer_spec.rb
@@ -14,6 +14,10 @@
@xcconfig['ALWAYS_SEARCH_USER_PATHS'].should == 'YES'
end
+ it "sets the PODS_ROOT environment variable relative to the Xcode project" do
+ @xcconfig['PODS_ROOT'].should == "$(SRCROOT)/Pods"
+ end
+
it "configures the project to load categories from the static library" do
@xcconfig['OTHER_LDFLAGS'].should == '-ObjC -all_load'
end
View
29 spec/unit/target_installer_spec.rb
@@ -0,0 +1,29 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+describe "Pod::Installer::TargetInstaller" do
+ before do
+ @target_installer = Pod::Installer::TargetInstaller.new(nil, nil, nil)
+ @config_before = config
+ Pod::Config.instance = nil
+ end
+
+ it "should work with paths one level up" do
+ config.source_root = "#{config.project_root}/subdir"
+ @target_installer.pods_path_relative_to_project.to_s.should == "../Pods"
+ end
+
+ it "should work with paths at the same level" do
+ @target_installer.pods_path_relative_to_project.to_s.should == "Pods"
+ end
+
+ it "should work with paths one level up" do
+ config.project_root = Pathname.new("/tmp/foo")
+ config.source_root = "/tmp"
+ @target_installer.pods_path_relative_to_project.to_s.should == "foo/Pods"
+ end
+
+ after do
+ Pod::Config.instance = @config_before
+ end
+end
+
Something went wrong with that request. Please try again.