Compute PODS_ROOT Path relative to xcode project folder #138

Closed
wants to merge 6 commits into
from
View
@@ -15,3 +15,4 @@ spec/fixtures/integration/Headers/
pod
/concatenated.*
spec/fixtures/mercurial-repo/.hg/*cache
+spec/fixtures/mercurial-repo/.hg/store/phaseroots
@@ -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
@@ -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
@@ -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
}
@@ -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)
@@ -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
@@ -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
@@ -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
+