Commit 8f7fef11 authored by Fabio Pelosin's avatar Fabio Pelosin

Merge branch 'local_source' into pod_update

* local_source:
  [LocalSource] Specs.
  [LocalSource] Tuning.
  [ExternalSources] Better robustness :-)
  [ExternalSources] Robustness.
  [LocalSource] Initial draft.

Conflicts:
	lib/cocoapods/installer.rb
parents 4b4c0c7a fbcb700b
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
- Added `pod outdated` - Added `pod outdated`
- An error is presented if a podspec can’t be found in the root of an external source. - An error is presented if a podspec can’t be found in the root of an external source.
- Meaningful error for unrecognized commands/arguments. - Meaningful error for unrecognized commands/arguments.
- Added `:local` option for dependencies. [#458](https://github.com/CocoaPods/CocoaPods/issues/458),[#415](https://github.com/CocoaPods/CocoaPods/issues/415),[#156](https://github.com/CocoaPods/CocoaPods/issues/156)
###### Bug fixes ###### Bug fixes
......
...@@ -138,6 +138,8 @@ module Pod ...@@ -138,6 +138,8 @@ module Pod
GitSource.new(name, params) GitSource.new(name, params)
elsif params.key?(:podspec) elsif params.key?(:podspec)
PodspecSource.new(name, params) PodspecSource.new(name, params)
elsif params.key?(:local)
LocalSource.new(name, params)
else else
raise Informative, "Unknown external source parameters for #{name}: #{params}" raise Informative, "Unknown external source parameters for #{name}: #{params}"
end end
...@@ -202,7 +204,9 @@ module Pod ...@@ -202,7 +204,9 @@ module Pod
output_path = sandbox.root + "Local Podspecs/#{name}.podspec" output_path = sandbox.root + "Local Podspecs/#{name}.podspec"
output_path.dirname.mkpath output_path.dirname.mkpath
puts "-> Fetching podspec for `#{name}' from: #{@params[:podspec]}" unless config.silent? puts "-> Fetching podspec for `#{name}' from: #{@params[:podspec]}" unless config.silent?
open(@params[:podspec]) do |io| path = @params[:podspec]
path = Pathname.new(path).expand_path if path.start_with?("~")
open(path) do |io|
output_path.open('w') { |f| f << io.read } output_path.open('w') { |f| f << io.read }
end end
end end
...@@ -211,6 +215,35 @@ module Pod ...@@ -211,6 +215,35 @@ module Pod
"from `#{@params[:podspec]}'" "from `#{@params[:podspec]}'"
end end
end end
class LocalSource < AbstractExternalSource
def pod_spec_path
path = Pathname.new(@params[:local]).expand_path + "#{name}.podspec"
raise Informative, "No podspec found for `#{name}` in #{description}" unless path.exist?
path
end
def copy_external_source_into_sandbox(sandbox, _)
output_path = sandbox.root + "Local Podspecs/#{name}.podspec"
output_path.dirname.mkpath
FileUtils.copy(pod_spec_path, output_path)
end
def specification_from_local(sandbox, platform)
specification_from_external(sandbox, platform)
end
def specification_from_external(sandbox, platform)
copy_external_source_into_sandbox(sandbox, platform)
spec = Specification.from_file(pod_spec_path)
spec.source = @params
spec
end
def description
"from `#{@params[:local]}'"
end
end
end end
end end
end end
...@@ -22,7 +22,8 @@ module Pod ...@@ -22,7 +22,8 @@ module Pod
pods.each do |pod| pods.each do |pod|
# Add all source files to the project grouped by pod # Add all source files to the project grouped by pod
pod.relative_source_files_by_spec.each do |spec, paths| pod.relative_source_files_by_spec.each do |spec, paths|
group = @project.add_spec_group(spec.name) parent_group = pod.local? ? @project.local_pods : @project.pods
group = @project.add_spec_to_group(pod.name, parent_group)
paths.each do |path| paths.each do |path|
group.files.new('path' => path.to_s) group.files.new('path' => path.to_s)
end end
...@@ -194,7 +195,11 @@ module Pod ...@@ -194,7 +195,11 @@ module Pod
specs_by_target.each do |target_definition, specs| specs_by_target.each do |target_definition, specs|
@pods_by_spec[target_definition.platform] = {} @pods_by_spec[target_definition.platform] = {}
result[target_definition] = specs.map do |spec| result[target_definition] = specs.map do |spec|
@sandbox.local_pod_for_spec(spec, target_definition.platform) if spec.local?
LocalPod::LocalSourcedPod.new(spec, sandbox, target_definition.platform)
else
@sandbox.local_pod_for_spec(spec, target_definition.platform)
end
end.uniq.compact end.uniq.compact
end end
result result
......
...@@ -98,9 +98,7 @@ module Pod ...@@ -98,9 +98,7 @@ module Pod
# the pods comes from a local source. # the pods comes from a local source.
# #
def to_s def to_s
result = top_specification.to_s top_specification.to_s
result << " [LOCAL]" if top_specification.local?
result
end end
# @return [String] The name of the Pod. # @return [String] The name of the Pod.
...@@ -142,6 +140,10 @@ module Pod ...@@ -142,6 +140,10 @@ module Pod
root.rmtree if exists? root.rmtree if exists?
end end
def local?
false
end
# @!group Cleaning # @!group Cleaning
# Deletes any path that is not used by the pod. # Deletes any path that is not used by the pod.
...@@ -510,5 +512,39 @@ module Pod ...@@ -510,5 +512,39 @@ module Pod
Pathname.glob(pattern, File::FNM_CASEFOLD) Pathname.glob(pattern, File::FNM_CASEFOLD)
end.flatten end.flatten
end end
# A {LocalSourcedPod} is a {LocalPod} that interacts with the files of
# a folder controlled by the users. As such this class does not alter
# in any way the contents of the folder.
#
class LocalSourcedPod < LocalPod
def downloaded?
true
end
def create
# No ops
end
def root
@root ||= Pathname.new(@top_specification.source[:local]).expand_path
end
def implode
# No ops
end
def clean!
# No ops
end
def to_s
super + " [LOCAL]"
end
def local?
true
end
end
end end
end end
...@@ -34,9 +34,14 @@ module Pod ...@@ -34,9 +34,14 @@ module Pod
groups.find { |g| g.name == 'Pods' } || groups.new({ 'name' => 'Pods' }) groups.find { |g| g.name == 'Pods' } || groups.new({ 'name' => 'Pods' })
end end
# Shortcut access to the `Local Pods' PBXGroup.
def local_pods
groups.find { |g| g.name == 'Local Pods' } || groups.new({ 'name' => 'Local Pods' })
end
# Adds a group as child to the `Pods' group namespacing subspecs. # Adds a group as child to the `Pods' group namespacing subspecs.
def add_spec_group(name) def add_spec_to_group(name, parent_group)
groups = pods.groups groups = parent_group.groups
group = nil group = nil
name.split('/').each do |name| name.split('/').each do |name|
group = groups.find { |g| g.name == name } || groups.new({ 'name' => name }) group = groups.find { |g| g.name == name } || groups.new({ 'name' => name })
......
...@@ -408,16 +408,8 @@ module Pod ...@@ -408,16 +408,8 @@ module Pod
!source.nil? && !source[:local].nil? !source.nil? && !source[:local].nil?
end end
def local_path
Pathname.new(File.expand_path(source[:local]))
end
def pod_destroot def pod_destroot
if local? config.project_pods_root + top_level_parent.name
local_path
else
config.project_pods_root + top_level_parent.name
end
end end
def self.pattern_list(patterns) def self.pattern_list(patterns)
......
...@@ -323,4 +323,57 @@ describe Pod::LocalPod do ...@@ -323,4 +323,57 @@ describe Pod::LocalPod do
public_headers.should == %w{ UIKit.h } public_headers.should == %w{ UIKit.h }
end end
end end
describe "concerning a Pod with a local source" do
extend SpecHelper::TemporaryDirectory
before do
@local_path = temporary_directory + 'localBanana'
@sandbox = temporary_sandbox
@spec = fixture_spec('banana-lib/BananaLib.podspec')
@spec.source = {:local => @local_path}
@pod = Pod::LocalPod::LocalSourcedPod.new(@spec, @sandbox, Pod::Platform.new(:ios))
end
it "is marked as local" do
@pod.to_s.should.include? '[LOCAL]'
end
it "is marked as downloaded" do
@pod.downloaded?.should.be.true
end
it "correctly repports the root of the pod" do
@pod.root.should == @local_path
end
it "doesn't create the root" do
@pod.create
@local_path.exist?.should.be.false
end
before do
FileUtils.cp_r(fixture('banana-lib'), @local_path)
end
it "doesn't cleans the user files" do
useless_file = @local_path + 'useless.txt'
FileUtils.touch (useless_file)
@pod.root.should == @local_path
@pod.clean!
useless_file.exist?.should.be.true
end
it "doesn't implode" do
@pod.implode
@local_path.exist?.should.be.true
end
it "detects the files of the pod" do
@pod.source_files.map {|path| path.to_s.gsub(/.*tmp\//,'') }.sort.should == [
"localBanana/Classes/Banana.m",
"localBanana/Classes/Banana.h"
].sort
end
end
end end
...@@ -12,7 +12,7 @@ describe 'Pod::Project' do ...@@ -12,7 +12,7 @@ describe 'Pod::Project' do
end end
it "adds a group to the `Pods' group" do it "adds a group to the `Pods' group" do
group = @project.add_spec_group('JSONKit') group = @project.add_spec_to_group('JSONKit', @project.pods)
@project.pods.child_references.should.include group.uuid @project.pods.child_references.should.include group.uuid
find_object({ find_object({
'isa' => 'PBXGroup', 'isa' => 'PBXGroup',
...@@ -23,7 +23,7 @@ describe 'Pod::Project' do ...@@ -23,7 +23,7 @@ describe 'Pod::Project' do
end end
it "namespaces subspecs in groups" do it "namespaces subspecs in groups" do
group = @project.add_spec_group('JSONKit/Subspec') group = @project.add_spec_to_group('JSONKit/Subspec', @project.pods)
@project.pods.groups.find { |g| g.name == 'JSONKit' }.child_references.should.include group.uuid @project.pods.groups.find { |g| g.name == 'JSONKit' }.child_references.should.include group.uuid
find_object({ find_object({
'isa' => 'PBXGroup', 'isa' => 'PBXGroup',
......
...@@ -230,6 +230,12 @@ describe "A Pod::Specification, in general," do ...@@ -230,6 +230,12 @@ describe "A Pod::Specification, in general," do
@spec.platform = :ios @spec.platform = :ios
@spec.activate_platform(:ios).should == @spec @spec.activate_platform(:ios).should == @spec
end end
it "it handles local sources" do
@spec.activate_platform(:ios)
@spec.source = {:local => '/tmp/local/path'}
@spec.local?.should.be.true
end
end end
describe "A Pod::Specification, hierarchy" do describe "A Pod::Specification, hierarchy" do
...@@ -479,7 +485,7 @@ describe "A Pod::Specification with :local source" do ...@@ -479,7 +485,7 @@ describe "A Pod::Specification with :local source" do
end end
it "it returns the expanded local path" do it "it returns the expanded local path" do
@spec.local_path.should == fixture("integration/JSONKit") @spec.source.should == {:local => fixture("integration/JSONKit")}
end end
end end
......
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