mirror of
https://github.com/zhigang1992/CocoaPods.git
synced 2026-04-30 10:22:26 +08:00
Don’t copy podspecs to the Pods dir, instead generate a Podfile.lock file, which also lists specs from outside spec repos. Closes #47.
This commit is contained in:
9
examples/AFNetworking iOS Example/Podfile.lock
Normal file
9
examples/AFNetworking iOS Example/Podfile.lock
Normal file
@@ -0,0 +1,9 @@
|
||||
PODS:
|
||||
- AFNetworking (0.7.0):
|
||||
- JSONKit
|
||||
- FormatterKit (0.6.0)
|
||||
- JSONKit (1.4)
|
||||
|
||||
DEPENDENCIES:
|
||||
- AFNetworking (~> 0.7.0)
|
||||
- FormatterKit
|
||||
11
examples/MacRubySample/Podfile.lock
Normal file
11
examples/MacRubySample/Podfile.lock
Normal file
@@ -0,0 +1,11 @@
|
||||
PODS:
|
||||
- ASIHTTPRequest (1.8.1)
|
||||
- CocoaLumberjack (1.2.1)
|
||||
- Kiwi (1.0.0)
|
||||
- SBJson (3.0.4)
|
||||
|
||||
DEPENDENCIES:
|
||||
- ASIHTTPRequest
|
||||
- CocoaLumberjack
|
||||
- Kiwi
|
||||
- SBJson
|
||||
9
examples/SSCatalog/Podfile.lock
Normal file
9
examples/SSCatalog/Podfile.lock
Normal file
@@ -0,0 +1,9 @@
|
||||
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
|
||||
end
|
||||
|
||||
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("' '")}'}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ module Pod
|
||||
@instance = instance
|
||||
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 :verbose?, :verbose
|
||||
alias_method :silent?, :silent
|
||||
@@ -23,7 +23,7 @@ module Pod
|
||||
end
|
||||
|
||||
def project_root
|
||||
Pathname.pwd
|
||||
@project_root ||= Pathname.pwd
|
||||
end
|
||||
|
||||
def project_pods_root
|
||||
|
||||
@@ -36,6 +36,20 @@ module Pod
|
||||
(@specification ? @specification == other.specification : @external_spec_source == other.external_spec_source)
|
||||
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,
|
||||
# this method will return the Specification instance.
|
||||
def specification
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'yaml'
|
||||
|
||||
module Pod
|
||||
class Installer
|
||||
module Shared
|
||||
@@ -5,12 +7,12 @@ module Pod
|
||||
@dependent_specification_sets ||= Resolver.new(@podfile, @definition ? @definition.dependencies : nil).resolve
|
||||
end
|
||||
|
||||
def build_specification_sets
|
||||
dependent_specification_sets.reject(&:only_part_of_other_pod?)
|
||||
def build_specifications
|
||||
dependent_specification_sets.reject(&:only_part_of_other_pod?).map(&:specification)
|
||||
end
|
||||
|
||||
def build_specifications
|
||||
build_specification_sets.map(&:specification)
|
||||
def download_only_specifications
|
||||
dependent_specification_sets.select(&:only_part_of_other_pod?).map(&:specification)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -162,6 +164,10 @@ EOS
|
||||
@podfile = podfile
|
||||
end
|
||||
|
||||
def lock_file
|
||||
config.project_root + 'Podfile.lock'
|
||||
end
|
||||
|
||||
def project
|
||||
return @project if @project
|
||||
@project = Xcodeproj::Project.for_platform(@podfile.platform)
|
||||
@@ -200,12 +206,44 @@ EOS
|
||||
puts " * Writing Xcode project file to `#{projpath}'" if config.verbose?
|
||||
project.save_as(projpath)
|
||||
|
||||
generate_lock_file!
|
||||
|
||||
# Post install hooks run last!
|
||||
targets.each do |target|
|
||||
target.build_specifications.each { |spec| spec.post_install(target) }
|
||||
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.
|
||||
# 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.
|
||||
|
||||
@@ -244,7 +244,7 @@ module Pod
|
||||
end
|
||||
|
||||
def to_s
|
||||
"`#{name}' version `#{version}'"
|
||||
"#{name} (#{version})"
|
||||
end
|
||||
|
||||
def inspect
|
||||
@@ -275,8 +275,6 @@ module Pod
|
||||
|
||||
# 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
|
||||
# pod. Eg:
|
||||
#
|
||||
@@ -287,13 +285,10 @@ module Pod
|
||||
# # post-install
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# TODO Do we really need this now that we don’t install the podspec files anymore?
|
||||
def install!
|
||||
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
|
||||
# the other pod's source.
|
||||
(part_of_specification || self).download_if_necessary!
|
||||
|
||||
@@ -37,7 +37,7 @@ else
|
||||
Pod::Config.instance = nil
|
||||
config.silent = true
|
||||
config.repos_dir = fixture('spec-repos')
|
||||
config.project_pods_root = temporary_directory + 'Pods'
|
||||
config.project_root = temporary_directory
|
||||
end
|
||||
|
||||
after do
|
||||
@@ -54,17 +54,20 @@ else
|
||||
if platform == :ios
|
||||
it "installs a Pod directly from its repo" do
|
||||
url = fixture('integration/sstoolkit').to_s
|
||||
commit = '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b'
|
||||
podfile = Pod::Podfile.new do
|
||||
self.platform :ios
|
||||
dependency 'SSToolkit', :git => url, :commit => '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b'
|
||||
dependency 'SSToolkit', :git => url, :commit => commit
|
||||
end
|
||||
|
||||
# Note that we are *not* using the stubbed SpecHelper::Installer subclass.
|
||||
installer = Pod::Installer.new(podfile)
|
||||
installer.install!
|
||||
|
||||
spec = Pod::Spec.from_file(config.project_pods_root + 'SSToolkit.podspec')
|
||||
spec.version.to_s.should == '0.1.3'
|
||||
YAML.load(installer.lock_file.read).should == {
|
||||
'PODS' => ['SSToolkit (0.1.3)'],
|
||||
'DEPENDENCIES' => ["SSToolkit (from `#{url}', commit `#{commit}')"]
|
||||
}
|
||||
|
||||
Dir.chdir(config.project_pods_root + 'SSToolkit') do
|
||||
`git config --get remote.origin.url`.strip.should == url
|
||||
@@ -72,19 +75,21 @@ else
|
||||
end
|
||||
|
||||
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
|
||||
self.platform :ios
|
||||
# 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
|
||||
|
||||
installer = SpecHelper::Installer.new(podfile)
|
||||
installer.install!
|
||||
|
||||
spec = Pod::Spec.from_file(config.project_pods_root + 'Reachability.podspec')
|
||||
spec.version.to_s.should == '1.2.3'
|
||||
|
||||
(config.project_pods_root + 'ASIHTTPRequest').should.exist
|
||||
YAML.load(installer.lock_file.read).should == {
|
||||
'PODS' => [{ 'Reachability (1.2.3)' => ["ASIHTTPRequest (>= 1.8)"] }],
|
||||
'DOWNLOAD_ONLY' => ["ASIHTTPRequest (1.8.1)"],
|
||||
'DEPENDENCIES' => ["Reachability (from `#{url}')"]
|
||||
}
|
||||
end
|
||||
|
||||
it "installs a library with a podspec defined inline" do
|
||||
@@ -101,9 +106,10 @@ else
|
||||
installer = SpecHelper::Installer.new(podfile)
|
||||
installer.install!
|
||||
|
||||
# TODO do we need the write out the podspec?
|
||||
#spec = Pod::Spec.from_file(config.project_pods_root + 'JSONKit.podspec')
|
||||
#spec.version.to_s.should == '1.2'
|
||||
YAML.load(installer.lock_file.read).should == {
|
||||
'PODS' => ['JSONKit (1.2)'],
|
||||
'DEPENDENCIES' => ["JSONKit (defined in Podfile)"]
|
||||
}
|
||||
|
||||
change_log = (config.project_pods_root + 'JSONKit/CHANGELOG.md').read
|
||||
change_log.should.include '1.2'
|
||||
@@ -131,15 +137,29 @@ if false
|
||||
installer = SpecHelper::Installer.new(spec)
|
||||
installer.install!
|
||||
|
||||
lock_file_contents = {
|
||||
'PODS' => [
|
||||
{ 'ASIHTTPRequest (1.8.1)' => ["Reachability (~> 2.0, >= 2.0.4)"] },
|
||||
{ 'ASIWebPageRequest (1.8.1)' => ["ASIHTTPRequest (= 1.8.1)"] },
|
||||
'JSONKit (1.4)',
|
||||
{ '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 + 'Reachability.podspec').should.exist if platform == :ios
|
||||
(root + 'ASIHTTPRequest.podspec').should.exist
|
||||
(root + 'ASIWebPageRequest.podspec').should.exist
|
||||
(root + 'JSONKit.podspec').should.exist
|
||||
(root + 'SSZipArchive.podspec').should.exist
|
||||
|
||||
(root + 'Pods.xcconfig').read.should == installer.targets.first.xcconfig.to_s
|
||||
|
||||
project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s
|
||||
NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.project.to_hash
|
||||
|
||||
@@ -149,6 +169,7 @@ if false
|
||||
end
|
||||
end
|
||||
|
||||
#if false
|
||||
it "does not activate pods that are only part of other pods" do
|
||||
spec = Pod::Podfile.new do
|
||||
# first ensure that the correct info is available to the specs when they load
|
||||
|
||||
Reference in New Issue
Block a user