Commit de99b446 authored by Eloy Duran's avatar Eloy Duran

Don’t copy podspecs to the Pods dir, instead generate a Podfile.lock file, which…

Don’t copy podspecs to the Pods dir, instead generate a Podfile.lock file, which also lists specs from outside spec repos. Closes #47.
parent 5467b1f4
PODS:
- AFNetworking (0.7.0):
- JSONKit
- FormatterKit (0.6.0)
- JSONKit (1.4)
DEPENDENCIES:
- AFNetworking (~> 0.7.0)
- FormatterKit
PODS:
- ASIHTTPRequest (1.8.1)
- CocoaLumberjack (1.2.1)
- Kiwi (1.0.0)
- SBJson (3.0.4)
DEPENDENCIES:
- ASIHTTPRequest
- CocoaLumberjack
- Kiwi
- SBJson
PODS:
- AFNetworking (0.7.0):
- JSONKit
- JSONKit (1.4)
- SSToolkit (0.1.3)
DEPENDENCIES:
- AFNetworking
- SSToolkit (defined in Podfile)
...@@ -16,7 +16,7 @@ module Pod ...@@ -16,7 +16,7 @@ module Pod
end end
def save_as(pathname) def save_as(pathname)
puts "==> Generating BridgeSupport metadata file" unless config.silent? puts "==> Generating BridgeSupport metadata file at `#{pathname}'" unless config.silent?
gen_bridge_metadata %{-c "#{search_paths.join(' ')}" -o '#{pathname}' '#{headers.join("' '")}'} gen_bridge_metadata %{-c "#{search_paths.join(' ')}" -o '#{pathname}' '#{headers.join("' '")}'}
end end
end end
......
...@@ -10,7 +10,7 @@ module Pod ...@@ -10,7 +10,7 @@ module Pod
@instance = instance @instance = instance
end end
attr_accessor :repos_dir, :project_pods_root, :rootspec, :clean, :verbose, :silent attr_accessor :repos_dir, :project_root, :project_pods_root, :rootspec, :clean, :verbose, :silent
alias_method :clean?, :clean alias_method :clean?, :clean
alias_method :verbose?, :verbose alias_method :verbose?, :verbose
alias_method :silent?, :silent alias_method :silent?, :silent
...@@ -23,7 +23,7 @@ module Pod ...@@ -23,7 +23,7 @@ module Pod
end end
def project_root def project_root
Pathname.pwd @project_root ||= Pathname.pwd
end end
def project_pods_root def project_pods_root
......
...@@ -36,6 +36,20 @@ module Pod ...@@ -36,6 +36,20 @@ module Pod
(@specification ? @specification == other.specification : @external_spec_source == other.external_spec_source) (@specification ? @specification == other.specification : @external_spec_source == other.external_spec_source)
end end
def to_s
version = ''
if source = @external_spec_source
version << "from `#{source[:git] || source[:podspec]}'"
version << ", commit `#{source[:commit]}'" if source[:commit]
version << ", tag `#{source[:tag]}'" if source[:tag]
elsif @inline_podspec
version << "defined in Podfile"
elsif @version_requirements != Gem::Requirement.default
version << @version_requirements.to_s
end
version.empty? ? @name : "#{@name} (#{version})"
end
# In case this dependency was defined with either a repo url, :podspec, or block, # In case this dependency was defined with either a repo url, :podspec, or block,
# this method will return the Specification instance. # this method will return the Specification instance.
def specification def specification
......
require 'yaml'
module Pod module Pod
class Installer class Installer
module Shared module Shared
...@@ -5,12 +7,12 @@ module Pod ...@@ -5,12 +7,12 @@ module Pod
@dependent_specification_sets ||= Resolver.new(@podfile, @definition ? @definition.dependencies : nil).resolve @dependent_specification_sets ||= Resolver.new(@podfile, @definition ? @definition.dependencies : nil).resolve
end end
def build_specification_sets def build_specifications
dependent_specification_sets.reject(&:only_part_of_other_pod?) dependent_specification_sets.reject(&:only_part_of_other_pod?).map(&:specification)
end end
def build_specifications def download_only_specifications
build_specification_sets.map(&:specification) dependent_specification_sets.select(&:only_part_of_other_pod?).map(&:specification)
end end
end end
...@@ -162,6 +164,10 @@ EOS ...@@ -162,6 +164,10 @@ EOS
@podfile = podfile @podfile = podfile
end end
def lock_file
config.project_root + 'Podfile.lock'
end
def project def project
return @project if @project return @project if @project
@project = Xcodeproj::Project.for_platform(@podfile.platform) @project = Xcodeproj::Project.for_platform(@podfile.platform)
...@@ -200,12 +206,44 @@ EOS ...@@ -200,12 +206,44 @@ EOS
puts " * Writing Xcode project file to `#{projpath}'" if config.verbose? puts " * Writing Xcode project file to `#{projpath}'" if config.verbose?
project.save_as(projpath) project.save_as(projpath)
generate_lock_file!
# Post install hooks run last! # Post install hooks run last!
targets.each do |target| targets.each do |target|
target.build_specifications.each { |spec| spec.post_install(target) } target.build_specifications.each { |spec| spec.post_install(target) }
end end
end end
def generate_lock_file!
lock_file.open('w') do |file|
file.puts "PODS:"
pods = build_specifications.map do |spec|
[spec.to_s, spec.dependencies.map(&:to_s).sort]
end.sort_by(&:first).each do |name, deps|
if deps.empty?
file.puts " - #{name}"
else
file.puts " - #{name}:"
deps.each { |dep| file.puts " - #{dep}" }
end
end
unless download_only_specifications.empty?
file.puts
file.puts "DOWNLOAD_ONLY:"
download_only_specifications.map(&:to_s).sort.each do |name|
file.puts " - #{name}"
end
end
file.puts
file.puts "DEPENDENCIES:"
@podfile.dependencies.map(&:to_s).sort.each do |dep|
file.puts " - #{dep}"
end
end
end
# For now this assumes just one pods target, i.e. only libPods.a. # For now this assumes just one pods target, i.e. only libPods.a.
# Not sure yet if we should try to be smart with apps that have multiple # Not sure yet if we should try to be smart with apps that have multiple
# targets and try to map pod targets to those app targets. # targets and try to map pod targets to those app targets.
......
...@@ -244,7 +244,7 @@ module Pod ...@@ -244,7 +244,7 @@ module Pod
end end
def to_s def to_s
"`#{name}' version `#{version}'" "#{name} (#{version})"
end end
def inspect def inspect
...@@ -275,8 +275,6 @@ module Pod ...@@ -275,8 +275,6 @@ module Pod
# Install and download hooks # Install and download hooks
# Places the activated specification in the project's pods directory.
#
# Override this if you need to perform work before or after activating the # Override this if you need to perform work before or after activating the
# pod. Eg: # pod. Eg:
# #
...@@ -287,13 +285,10 @@ module Pod ...@@ -287,13 +285,10 @@ module Pod
# # post-install # # post-install
# end # end
# end # end
#
# TODO Do we really need this now that we don’t install the podspec files anymore?
def install! def install!
puts "==> Installing: #{self}" unless config.silent? puts "==> Installing: #{self}" unless config.silent?
if defined_in_file && !(config.project_pods_root + defined_in_file.basename).exist?
config.project_pods_root.mkpath
FileUtils.cp(defined_in_file, config.project_pods_root)
end
# In case this spec is part of another pod's source, we need to dowload # In case this spec is part of another pod's source, we need to dowload
# the other pod's source. # the other pod's source.
(part_of_specification || self).download_if_necessary! (part_of_specification || self).download_if_necessary!
......
...@@ -37,7 +37,7 @@ else ...@@ -37,7 +37,7 @@ else
Pod::Config.instance = nil Pod::Config.instance = nil
config.silent = true config.silent = true
config.repos_dir = fixture('spec-repos') config.repos_dir = fixture('spec-repos')
config.project_pods_root = temporary_directory + 'Pods' config.project_root = temporary_directory
end end
after do after do
...@@ -54,17 +54,20 @@ else ...@@ -54,17 +54,20 @@ else
if platform == :ios if platform == :ios
it "installs a Pod directly from its repo" do it "installs a Pod directly from its repo" do
url = fixture('integration/sstoolkit').to_s url = fixture('integration/sstoolkit').to_s
commit = '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b'
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform :ios self.platform :ios
dependency 'SSToolkit', :git => url, :commit => '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b' dependency 'SSToolkit', :git => url, :commit => commit
end end
# Note that we are *not* using the stubbed SpecHelper::Installer subclass. # Note that we are *not* using the stubbed SpecHelper::Installer subclass.
installer = Pod::Installer.new(podfile) installer = Pod::Installer.new(podfile)
installer.install! installer.install!
spec = Pod::Spec.from_file(config.project_pods_root + 'SSToolkit.podspec') YAML.load(installer.lock_file.read).should == {
spec.version.to_s.should == '0.1.3' 'PODS' => ['SSToolkit (0.1.3)'],
'DEPENDENCIES' => ["SSToolkit (from `#{url}', commit `#{commit}')"]
}
Dir.chdir(config.project_pods_root + 'SSToolkit') do Dir.chdir(config.project_pods_root + 'SSToolkit') do
`git config --get remote.origin.url`.strip.should == url `git config --get remote.origin.url`.strip.should == url
...@@ -72,19 +75,21 @@ else ...@@ -72,19 +75,21 @@ else
end end
it "installs a library with a podspec outside of the repo" do it "installs a library with a podspec outside of the repo" do
url = 'https://raw.github.com/gist/1349824/3ec6aa60c19113573fc48eac19d0fafd6a69e033/Reachability.podspec'
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform :ios self.platform :ios
# TODO use a local file instead of http? # TODO use a local file instead of http?
dependency 'Reachability', :podspec => 'https://raw.github.com/gist/1349824/3ec6aa60c19113573fc48eac19d0fafd6a69e033/Reachability.podspec' dependency 'Reachability', :podspec => url
end end
installer = SpecHelper::Installer.new(podfile) installer = SpecHelper::Installer.new(podfile)
installer.install! installer.install!
spec = Pod::Spec.from_file(config.project_pods_root + 'Reachability.podspec') YAML.load(installer.lock_file.read).should == {
spec.version.to_s.should == '1.2.3' 'PODS' => [{ 'Reachability (1.2.3)' => ["ASIHTTPRequest (>= 1.8)"] }],
'DOWNLOAD_ONLY' => ["ASIHTTPRequest (1.8.1)"],
(config.project_pods_root + 'ASIHTTPRequest').should.exist 'DEPENDENCIES' => ["Reachability (from `#{url}')"]
}
end end
it "installs a library with a podspec defined inline" do it "installs a library with a podspec defined inline" do
...@@ -101,9 +106,10 @@ else ...@@ -101,9 +106,10 @@ else
installer = SpecHelper::Installer.new(podfile) installer = SpecHelper::Installer.new(podfile)
installer.install! installer.install!
# TODO do we need the write out the podspec? YAML.load(installer.lock_file.read).should == {
#spec = Pod::Spec.from_file(config.project_pods_root + 'JSONKit.podspec') 'PODS' => ['JSONKit (1.2)'],
#spec.version.to_s.should == '1.2' 'DEPENDENCIES' => ["JSONKit (defined in Podfile)"]
}
change_log = (config.project_pods_root + 'JSONKit/CHANGELOG.md').read change_log = (config.project_pods_root + 'JSONKit/CHANGELOG.md').read
change_log.should.include '1.2' change_log.should.include '1.2'
...@@ -131,15 +137,29 @@ if false ...@@ -131,15 +137,29 @@ if false
installer = SpecHelper::Installer.new(spec) installer = SpecHelper::Installer.new(spec)
installer.install! installer.install!
root = config.project_pods_root lock_file_contents = {
(root + 'Reachability.podspec').should.exist if platform == :ios 'PODS' => [
(root + 'ASIHTTPRequest.podspec').should.exist { 'ASIHTTPRequest (1.8.1)' => ["Reachability (~> 2.0, >= 2.0.4)"] },
(root + 'ASIWebPageRequest.podspec').should.exist { 'ASIWebPageRequest (1.8.1)' => ["ASIHTTPRequest (= 1.8.1)"] },
(root + 'JSONKit.podspec').should.exist 'JSONKit (1.4)',
(root + 'SSZipArchive.podspec').should.exist { 'Reachability (2.0.4)' => ["ASIHTTPRequest (>= 1.8)"] },
'SSZipArchive (0.1.1)',
],
'DEPENDENCIES' => [
"ASIWebPageRequest (>= 1.8.1)",
"JSONKit (>= 1.0)",
"SSZipArchive (< 2)",
]
}
unless platform == :ios
# No Reachability is required by ASIHTTPRequest on OSX
lock_file_contents['PODS'].delete_at(3)
lock_file_contents['PODS'][0] = 'ASIHTTPRequest (1.8.1)'
end
YAML.load(installer.lock_file.read).should == lock_file_contents
root = config.project_pods_root
(root + 'Pods.xcconfig').read.should == installer.targets.first.xcconfig.to_s (root + 'Pods.xcconfig').read.should == installer.targets.first.xcconfig.to_s
project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s
NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.project.to_hash NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.project.to_hash
...@@ -149,6 +169,7 @@ if false ...@@ -149,6 +169,7 @@ if false
end end
end end
#if false
it "does not activate pods that are only part of other pods" do it "does not activate pods that are only part of other pods" do
spec = Pod::Podfile.new do spec = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load # first ensure that the correct info is available to the specs when they load
......
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