Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 233 lines (191 sloc) 7.349 kb
4a709b8 @alloy Make building a iOS lib work again.
alloy authored
1 require 'colored'
2
bb50005 @alloy Move installation code into Installer class.
alloy authored
3 module Pod
4 class Installer
eae99b2 @alloy Rename Pod::Project::Integrator to Pod::Installer::UserProjectIntegrator...
alloy authored
5 autoload :TargetInstaller, 'cocoapods/installer/target_installer'
6 autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator'
ef9ac10 @alloy Move Specification#install! to the installer and move TargetInstaller to...
alloy authored
7
5b5abd6 @alloy + begin of integration spec
alloy authored
8 include Config::Mixin
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
9
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
10 attr_reader :sandbox
5b5abd6 @alloy + begin of integration spec
alloy authored
11
d51f5a0 @alloy Make UserProjectIntegrator work again.
alloy authored
12 def initialize(podfile)
13 @podfile = podfile
e2819ac @lukeredpath TargetInstaller no longer needs access to #build_specifications
lukeredpath authored
14 # FIXME: pass this into the installer as a parameter
4b42a18 @lukeredpath Configured Guard for auto-running specs.
lukeredpath authored
15 @sandbox = Sandbox.new(config.project_pods_root)
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
16 @resolver = Resolver.new(@podfile, @sandbox)
10b7d02 @fabiopelosin [config.ios?] Temporary support for pod spec lint.
fabiopelosin authored
17 # TODO: remove in 0.7 (legacy support for config.ios? and config.osx?)
18 config.podfile = podfile
bb50005 @alloy Move installation code into Installer class.
alloy authored
19 end
20
de99b44 @alloy Don’t copy podspecs to the Pods dir, instead generate a Podfile.lock fil...
alloy authored
21 def lock_file
22 config.project_root + 'Podfile.lock'
23 end
24
ed6862f @nolanw ProjectTemplate is really a module
nolanw authored
25 def project
26 return @project if @project
cb05af4 @alloy Make platform specific build settings specs work again.
alloy authored
27 @project = Pod::Project.new
04843c3 @alloy Make specs green.
alloy authored
28 activated_pods.each do |pod|
e08a67a @nolanw Template maintains its project
nolanw authored
29 # Add all source files to the project grouped by pod
04843c3 @alloy Make specs green.
alloy authored
30 group = @project.add_pod_group(pod.name)
31 pod.source_files.each do |path|
7b46404 @alloy Fix Xcode project generation and a few more specs.
alloy authored
32 group.files.new('path' => path.to_s)
10befd8 @alloy Generate copy resources scripts for each target.
alloy authored
33 end
34 end
e08a67a @nolanw Template maintains its project
nolanw authored
35 # Add a group to hold all the target support files
ed6862f @nolanw ProjectTemplate is really a module
nolanw authored
36 @project.main_group.groups.new('name' => 'Targets Support Files')
37 @project
985e4fc @alloy Make the integration spec, which creates a project with multiple targets...
alloy authored
38 end
39
cf662d1 @alloy Disambiguate the use of the word ‘target’.
alloy authored
40 def target_installers
41 @target_installers ||= @podfile.target_definitions.values.map do |definition|
6b68f52 @alloy Don’t create a target if its definition, in the Podfile, is empty (no de...
alloy authored
42 TargetInstaller.new(@podfile, project, definition) unless definition.empty?
43 end.compact
3f4ed2a @alloy Generate BridgeSupport if Specification#generate_bridge_support is used.
alloy authored
44 end
45
2f29463 @alloy Remove Specification#install! and perform that work from Installer.
alloy authored
46 def install_dependencies!
04843c3 @alloy Make specs green.
alloy authored
47 activated_pods.each do |pod|
48 marker = config.verbose ? "\n-> ".green : ''
421ddf8 @alloy Check wether or not a pod and its docs should be installed _before_ it's...
alloy authored
49
04843c3 @alloy Make specs green.
alloy authored
50 unless should_install = !pod.exists? && !pod.specification.local?
51 puts marker + "Using #{pod}" unless config.silent?
52 else
4a709b8 @alloy Make building a iOS lib work again.
alloy authored
53 puts marker + "Installing #{pod.specification}".green unless config.silent?
7ddf922 @lukeredpath Get this working again as it was before.
lukeredpath authored
54
04843c3 @alloy Make specs green.
alloy authored
55 downloader = Downloader.for_pod(pod)
56 downloader.download
98c972e @fabiopelosin [#149] Improved documentation generation
fabiopelosin authored
57
04843c3 @alloy Make specs green.
alloy authored
58 if config.clean
59 downloader.clean
60 pod.clean
a5d34c8 @alloy Add a --force-doc option and add `appledoc` install note to README.
alloy authored
61 end
04843c3 @alloy Make specs green.
alloy authored
62 end
d2f5a70 @fabiopelosin Major documentation refactoring
fabiopelosin authored
63
3341638 @fabiopelosin [Config#doc] Renamed to generate_docs
fabiopelosin authored
64 if (should_install && config.generate_docs?) || config.force_doc?
fcc94b6 @fabiopelosin [Installer] Don't generate documenation if already installed
fabiopelosin authored
65 doc_generator = Generator::Documentation.new(pod)
66 if doc_generator.already_installed?
67 puts "Using Existing Documentation for #{pod.specification}".green if config.verbose?
68 else
69 puts "Installing Documentation for #{pod.specification}".green if config.verbose?
70 doc_generator.generate(config.doc_install?)
71 end
2f29463 @alloy Remove Specification#install! and perform that work from Installer.
alloy authored
72 end
73 end
74 end
75
71fc2bb @alloy Small cleanup
alloy authored
76 def install!
a751ba2 @lukeredpath Some minor clean-up and refactoring.
lukeredpath authored
77 @sandbox.prepare_for_install
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
78
fba4810 @alloy Rename puts_title to print_title.
alloy authored
79 print_title "Resolving dependencies of: #{@podfile.defined_in_file}"
c7187f7 @fabiopelosin [colors] fix for broken build
fabiopelosin authored
80 specs_by_target
3b83f2a @fabiopelosin [colors] Added colors to install
fabiopelosin authored
81
fba4810 @alloy Rename puts_title to print_title.
alloy authored
82 print_title "Installing dependencies"
04843c3 @alloy Make specs green.
alloy authored
83 install_dependencies!
d1c6f44 @alloy Allow a user to define a post install hook in the Podfile, which allows ...
alloy authored
84
04843c3 @alloy Make specs green.
alloy authored
85 pods = activated_pods
fba4810 @alloy Rename puts_title to print_title.
alloy authored
86 print_title("Generating support files\n", false)
cf662d1 @alloy Disambiguate the use of the word ‘target’.
alloy authored
87 target_installers.each do |target_installer|
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
88 pods_for_target = activated_pods_by_target[target_installer.target_definition]
89 target_installer.install!(pods_for_target, @sandbox)
644e419 @alloy Generate separate xcconfig files for each target.
alloy authored
90 end
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
91
5514192 @lukeredpath Use pods to generate lockfile.
lukeredpath authored
92 generate_lock_file!(pods)
274fef8 @siuying Instead of generate a dummy source file for each target, generate one in...
siuying authored
93 generate_dummy_source
de99b44 @alloy Don’t copy podspecs to the Pods dir, instead generate a Podfile.lock fil...
alloy authored
94
ef9ac10 @alloy Move Specification#install! to the installer and move TargetInstaller to...
alloy authored
95 puts "* Running post install hooks" if config.verbose?
d1c6f44 @alloy Allow a user to define a post install hook in the Podfile, which allows ...
alloy authored
96 # Post install hooks run _before_ saving of project, so that they can alter it before saving.
a751ba2 @lukeredpath Some minor clean-up and refactoring.
lukeredpath authored
97 run_post_install_hooks
98
3b83f2a @fabiopelosin [colors] Added colors to install
fabiopelosin authored
99 puts "* Writing Xcode project file to `#{@sandbox.project_path}'\n\n" if config.verbose?
a751ba2 @lukeredpath Some minor clean-up and refactoring.
lukeredpath authored
100 project.save_as(@sandbox.project_path)
07fad45 @alloy Refactor Pod::Project::Integrator for upcoming work.
alloy authored
101
dc5b15a @alloy Make all not-disabled specs green again. Also introduces the `pod instal...
alloy authored
102 UserProjectIntegrator.new(@podfile).integrate! if config.integrate_targets?
a751ba2 @lukeredpath Some minor clean-up and refactoring.
lukeredpath authored
103 end
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
104
a751ba2 @lukeredpath Some minor clean-up and refactoring.
lukeredpath authored
105 def run_post_install_hooks
106 # we loop over target installers instead of pods, because we yield the target installer
107 # to the spec post install hook.
cf662d1 @alloy Disambiguate the use of the word ‘target’.
alloy authored
108 target_installers.each do |target_installer|
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
109 activated_specifications_for_target(target_installer.target_definition).each do |spec|
fde621d @lukeredpath My earlier Resolver/TargetInstaller refactoring broke the handling of ta...
lukeredpath authored
110 spec.post_install(target_installer)
111 end
193572d @alloy Generate a prefix header for each target and remove the files from disk ...
alloy authored
112 end
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
113
d1c6f44 @alloy Allow a user to define a post install hook in the Podfile, which allows ...
alloy authored
114 @podfile.post_install!(self)
bb50005 @alloy Move installation code into Installer class.
alloy authored
115 end
193572d @alloy Generate a prefix header for each target and remove the files from disk ...
alloy authored
116
5514192 @lukeredpath Use pods to generate lockfile.
lukeredpath authored
117 def generate_lock_file!(pods)
de99b44 @alloy Don’t copy podspecs to the Pods dir, instead generate a Podfile.lock fil...
alloy authored
118 lock_file.open('w') do |file|
119 file.puts "PODS:"
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
120
121 # Get list of [name, dependencies] pairs.
122 activated_pods = pods.map do |pod|
4a709b8 @alloy Make building a iOS lib work again.
alloy authored
123 [pod.specification.to_s, pod.dependencies.map(&:to_s).sort]
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
124 end.uniq
125
126 # Merge dependencies of ios and osx version of the same pod.
127 tmp = {}
128 activated_pods.each do |name, deps|
129 if tmp[name]
130 tmp[name].concat(deps).uniq!
131 else
132 tmp[name] = deps
133 end
134 end
135 activated_pods = tmp
136
137 # Sort by name and print
138 activated_pods.sort_by(&:first).each do |name, deps|
de99b44 @alloy Don’t copy podspecs to the Pods dir, instead generate a Podfile.lock fil...
alloy authored
139 if deps.empty?
140 file.puts " - #{name}"
141 else
142 file.puts " - #{name}:"
143 deps.each { |dep| file.puts " - #{dep}" }
144 end
145 end
146
147 unless download_only_specifications.empty?
148 file.puts
149 file.puts "DOWNLOAD_ONLY:"
150 download_only_specifications.map(&:to_s).sort.each do |name|
151 file.puts " - #{name}"
152 end
153 end
154
155 file.puts
156 file.puts "DEPENDENCIES:"
157 @podfile.dependencies.map(&:to_s).sort.each do |dep|
158 file.puts " - #{dep}"
159 end
160 end
161 end
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
162
274fef8 @siuying Instead of generate a dummy source file for each target, generate one in...
siuying authored
163 def generate_dummy_source
164 filename = "PodsDummy.m"
165 pathname = Pathname.new(sandbox.root + filename)
166 Generator::DummySource.new.save_as(pathname)
167
168 project_file = project.files.new('path' => filename)
169 project.group("Targets Support Files") << project_file
170
171 target_installers.each do |target_installer|
172 target_installer.target.source_build_phases.first << project_file
173 end
174 end
175
c7187f7 @fabiopelosin [colors] fix for broken build
fabiopelosin authored
176 def specs_by_target
177 @specs_by_target ||= @resolver.resolve
178 end
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
179
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
180 # @return [Array<Specification>] All dependencies that have been resolved.
b09aaeb @alloy Contain the cached sets in the Resolver itself.
alloy authored
181 def dependency_specifications
c7187f7 @fabiopelosin [colors] fix for broken build
fabiopelosin authored
182 specs_by_target.values.flatten
e2819ac @lukeredpath TargetInstaller no longer needs access to #build_specifications
lukeredpath authored
183 end
184
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
185 # @return [Array<LocalPod>] A list of LocalPod instances for each
186 # dependency that is not a download-only one.
04843c3 @alloy Make specs green.
alloy authored
187 def activated_pods
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
188 activated_pods_by_target.values.flatten
189 end
190
191 def activated_pods_by_target
192 result = {}
193 specs_by_target.each do |target_definition, specs|
194 result[target_definition] = specs.map do |spec|
195 LocalPod.new(spec, @sandbox, target_definition.platform) if activated_spec?(spec)
196 end.compact
04843c3 @alloy Make specs green.
alloy authored
197 end
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
198 result
04843c3 @alloy Make specs green.
alloy authored
199 end
200
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
201 # @return [Array<Specification>] A list of specifications for each
202 # dependency that is not a download-only
203 # one.
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
204 def activated_specifications
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
205 dependency_specifications.select { |spec| activated_spec?(spec) }
e2819ac @lukeredpath TargetInstaller no longer needs access to #build_specifications
lukeredpath authored
206 end
8c2adaf @alloy No longer cache Specification::Set in the Set class, but in a Context.
alloy authored
207
208 def activated_specifications_for_target(target_definition)
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
209 specs_by_target[target_definition].select { |spec| activated_spec?(spec) }
fde621d @lukeredpath My earlier Resolver/TargetInstaller refactoring broke the handling of ta...
lukeredpath authored
210 end
e2819ac @lukeredpath TargetInstaller no longer needs access to #build_specifications
lukeredpath authored
211
212 def download_only_specifications
b09aaeb @alloy Contain the cached sets in the Resolver itself.
alloy authored
213 dependency_specifications - activated_specifications
e2819ac @lukeredpath TargetInstaller no longer needs access to #build_specifications
lukeredpath authored
214 end
3b83f2a @fabiopelosin [colors] Added colors to install
fabiopelosin authored
215
216 private
217
56d0b4b @alloy And successfully build a OS X static library from a mixed platform Podfi...
alloy authored
218 def activated_spec?(spec)
219 # Don't activate specs which are only wrappers of subspecs, or share
220 # source with another pod but aren't activated themselves.
221 !spec.wrapper? && !@resolver.cached_sets[spec.name].only_part_of_other_pod?
222 end
223
fba4810 @alloy Rename puts_title to print_title.
alloy authored
224 def print_title(title, only_verbose = true)
225 if config.verbose?
226 puts "\n" + title.yellow
227 elsif !config.silent? && !only_verbose
3b83f2a @fabiopelosin [colors] Added colors to install
fabiopelosin authored
228 puts title
229 end
230 end
bb50005 @alloy Move installation code into Installer class.
alloy authored
231 end
232 end
Something went wrong with that request. Please try again.