Commit 34efc528 authored by Fabio Pelosin's avatar Fabio Pelosin

[Sandbox] Add #relativize from LocalPod#relativize_from_sandbox

parent d24245fc
GIT
remote: git://github.com/CocoaPods/Core.git
revision: 294d7b2d911aad3e0ab70272115f2c3ee5307cda
revision: 72bb4fd0e0df8a9dd731ca3885ef4203967acce1
specs:
cocoapods-core (0.17.0.alpha)
activesupport (~> 3.2.6)
......@@ -78,7 +78,7 @@ GEM
multi_json (1.5.0)
multipart-post (1.1.5)
netrc (0.7.7)
octokit (1.21.0)
octokit (1.22.0)
addressable (~> 2.2)
faraday (~> 0.8)
faraday_middleware (~> 0.9)
......@@ -87,17 +87,17 @@ GEM
netrc (~> 0.7.7)
open4 (1.3.0)
posix-spawn (0.3.6)
pry (0.9.10)
pry (0.9.11.1)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
slop (~> 3.4)
pygments.rb (0.3.7)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0)
rake (0.9.6)
rb-fsevent (0.9.3)
redcarpet (2.2.2)
slop (3.3.3)
slop (3.4.3)
terminal-notifier (1.4.2)
yajl-ruby (1.1.0)
yard (0.8.3)
......
......@@ -234,7 +234,7 @@ module Pod
if target_definition.podfile.generate_bridge_support?
path = library.bridge_support_path
UI.message "- Generating BridgeSupport metadata at #{UI.path(path)}" do
relative_headers = pods.map { |pod| pod.relative_header_files }.flatten
relative_headers = pods.map { |pod| pod.header_files.map {|head| sandbox.relativize(head)} }.flatten
headers = relative_headers.map { |header| sandbox.root + header }
generator = Generator::BridgeSupport.new(headers)
generator.save_as(path)
......@@ -255,7 +255,7 @@ module Pod
def create_copy_resources_script
path = library.copy_resources_script_path
UI.message "- Generating copy resources script at #{UI.path(path)}" do
resources = pods.map { |p| p.relative_resource_files }.flatten
resources = pods.map { |p| p.resource_files.map {|res| sandbox.relativize(res)} }.flatten
resources << bridge_support_file if bridge_support_file
generator = Generator::CopyResourcesScript.new(resources)
generator.save_as(path)
......
......@@ -21,6 +21,7 @@ module Pod
# returns absolute paths.
#
class LocalPod
autoload :PathList, 'cocoapods/local_pod/path_list'
# @return [Specification] The specification that describes the pod.
......@@ -208,26 +209,6 @@ module Pod
# @!group Files
# @return [Pathname] Returns the relative path from the sandbox.
#
# @note If the two abosule paths don't share the same root directory an
# extra `../` is added to the result of {Pathname#relative_path_from}
#
# path = Pathname.new('/Users/dir')
# @sandbox
# #=> Pathname('/tmp/CocoaPods/Lint/Pods')
#
# p.relative_path_from(@sandbox
# #=> '../../../../Users/dir'
#
# relativize_from_sandbox(path)
# #=> '../../../../../Users/dir'
#
def relativize_from_sandbox(path)
result = path.relative_path_from(@sandbox.root)
result = Pathname.new('../') + result unless @sandbox.root.to_s.split('/')[1] == path.to_s.split('/')[1]
result
end
# @return [Array<Pathname>] The paths of the source files.
#
......@@ -235,19 +216,7 @@ module Pod
source_files_by_spec.values.flatten
end
# @return [Array<Pathname>] The *relative* paths of the source files.
#
def relative_source_files
source_files.map{ |p| relativize_from_sandbox(p) }
end
def relative_source_files_by_spec
result = {}
source_files_by_spec.each do |spec, paths|
result[spec] = paths.map{ |p| relativize_from_sandbox(p) }
end
result
end
# Finds the source files that every activated {Specification} requires.
#
......@@ -268,12 +237,6 @@ module Pod
header_files_by_spec.values.flatten
end
# @return [Array<Pathname>] The *relative* paths of the source files.
#
def relative_header_files
header_files.map{ |p| relativize_from_sandbox(p) }
end
# @return [Hash{Specification => Array<Pathname>}] The paths of the header
# files grouped by {Specification}.
#
......@@ -330,12 +293,6 @@ module Pod
alias :resources :resource_files
# @return [Array<Pathname>] The *relative* paths of the resources.
#
def relative_resource_files
resource_files.map{ |p| relativize_from_sandbox(p) }
end
# @return [Pathname] The absolute path of the prefix header file
#
def prefix_header_file
......@@ -471,11 +428,12 @@ module Pod
@file_references_by_spec = {}
parent_group = local? ? project.local_pods : project.pods
relative_source_files_by_spec.each do |spec, paths|
source_files_by_spec.each do |spec, paths|
group = project.add_spec_group(spec.name, parent_group)
file_references = []
paths.each do |path|
file_references << group.new_file(path)
relative = sandbox.relativize(path)
file_references << group.new_file(relative)
end
@file_references_by_spec[spec] = file_references
end
......
......@@ -78,6 +78,28 @@ module Pod
root.rmtree
end
# @return [Pathname] Returns the relative path from the sandbox.
#
# @note If the two absolute paths don't share the same root directory an
# extra `../` is added to the result of {Pathname#relative_path_from}
#
#
# @example
#
# path = Pathname.new('/Users/dir')
# @sandbox.root #=> Pathname('/tmp/CocoaPods/Lint/Pods')
#
# @sandbox.relativize(path) #=> '../../../../Users/dir'
# @sandbox.relativize(path) #=> '../../../../../Users/dir'
#
def relativize(path)
result = path.relative_path_from(root)
unless root.to_s.split('/')[1] == path.to_s.split('/')[1]
result = Pathname.new('../') + result
end
result
end
# @return [String] a string representation suitable for debugging.
#
def inspect
......
......@@ -3,7 +3,7 @@ require File.expand_path('../../spec_helper', __FILE__)
module Pod
describe Sandbox do
before do
@sandbox = Pod::Sandbox.new(temporary_directory + 'Sandbox')
......@@ -34,6 +34,23 @@ module Pod
File.directory?(temporary_directory + 'Sandbox').should.be.false
end
it "can return the relative path of a given absolute path" do
path = temporary_directory + 'Sandbox/file'
@sandbox.relativize(path).should == Pathname.new('file')
end
it "can return the relative path of a given absolute path outside the sandbox root" do
path = temporary_directory + 'file'
@sandbox.relativize(path).should == Pathname.new('../file')
end
it "can return the relative path of a given absolute path with another root directory" do
path = Pathname('/tmp/Lint')
expected = Pathname.new('../../../tmp/Lint')
@sandbox.instance_variable_set(:@root, Pathname.new('/Users/sandbox'))
@sandbox.relativize(path).should == expected
end
#--------------------------------------#
it "returns the path of the manifest" do
......@@ -79,7 +96,7 @@ module Pod
#---------------------------------------------------------------------------#
describe Sandbox::HeadersStore do
before do
@sandbox = Pod::Sandbox.new(temporary_directory + 'Sandbox')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment