Commit 2a673e23 authored by Marius Rackwitz's avatar Marius Rackwitz

[TargetInspector] Inject the #installation_root via the constructor

Instead of refering to the global configuration
parent 5abe739a
...@@ -651,7 +651,8 @@ module Pod ...@@ -651,7 +651,8 @@ module Pod
inspection_result = {} inspection_result = {}
UI.section 'Inspecting targets to integrate' do UI.section 'Inspecting targets to integrate' do
podfile.target_definition_list.each do |target_definition| podfile.target_definition_list.each do |target_definition|
results = TargetInspector.new(target_definition).inspect! inspector = TargetInspector.new(target_definition, config.installation_root)
results = inspector.inspect!
inspection_result[target_definition] = results inspection_result[target_definition] = results
UI.message('Using `ARCHS` setting to build architectures of ' \ UI.message('Using `ARCHS` setting to build architectures of ' \
"target `#{target_definition.label}`: (`#{results.archs.join('`, `')}`)") "target `#{target_definition.label}`: (`#{results.archs.join('`, `')}`)")
......
...@@ -2,19 +2,25 @@ module Pod ...@@ -2,19 +2,25 @@ module Pod
class Installer class Installer
class Analyzer class Analyzer
class TargetInspector class TargetInspector
include Config::Mixin
# @return [TargetDefinition] the target definition to inspect # @return [TargetDefinition] the target definition to inspect
# #
attr_accessor :target_definition attr_accessor :target_definition
# @return [Pathname] the root of the CocoaPods installation where the
# Podfile is located
attr_accessor :installation_root
# Initialize a new instance # Initialize a new instance
# #
# @param [TargetDefinition] target_definition # @param [TargetDefinition] target_definition
# the target definition # @see #target_definition
#
# @param [Pathname] installation_root
# @see #installation_root
# #
def initialize(target_definition) def initialize(target_definition, installation_root)
@target_definition = target_definition @target_definition = target_definition
@installation_root = installation_root
end end
# Inspect the #target_definition # Inspect the #target_definition
...@@ -51,7 +57,7 @@ module Pod ...@@ -51,7 +57,7 @@ module Pod
# #
def compute_project_path def compute_project_path
if target_definition.user_project_path if target_definition.user_project_path
path = config.installation_root + target_definition.user_project_path path = installation_root + target_definition.user_project_path
path = "#{path}.xcodeproj" unless File.extname(path) == '.xcodeproj' path = "#{path}.xcodeproj" unless File.extname(path) == '.xcodeproj'
path = Pathname.new(path) path = Pathname.new(path)
unless path.exist? unless path.exist?
...@@ -59,7 +65,7 @@ module Pod ...@@ -59,7 +65,7 @@ module Pod
"`#{path}` for the target `#{target_definition.label}`." "`#{path}` for the target `#{target_definition.label}`."
end end
else else
xcodeprojs = config.installation_root.children.select { |e| e.fnmatch('*.xcodeproj') } xcodeprojs = installation_root.children.select { |e| e.fnmatch('*.xcodeproj') }
if xcodeprojs.size == 1 if xcodeprojs.size == 1
path = xcodeprojs.first path = xcodeprojs.first
else else
......
...@@ -11,7 +11,8 @@ module Pod ...@@ -11,7 +11,8 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
target_definition.user_project_path = 'SampleProject/SampleProject' target_definition.user_project_path = 'SampleProject/SampleProject'
path = TargetInspector.new(target_definition).send(:compute_project_path) target_inspector = TargetInspector.new(target_definition, config.installation_root)
path = target_inspector.send(:compute_project_path)
path.to_s.should.include 'SampleProject/SampleProject.xcodeproj' path.to_s.should.include 'SampleProject/SampleProject.xcodeproj'
end end
...@@ -19,7 +20,8 @@ module Pod ...@@ -19,7 +20,8 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
target_definition.user_project_path = 'Test' target_definition.user_project_path = 'Test'
e = lambda { TargetInspector.new(target_definition).send(:compute_project_path) }.should.raise Informative target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_project_path) }.should.raise Informative
e.message.should.match /Unable to find/ e.message.should.match /Unable to find/
end end
...@@ -27,14 +29,16 @@ module Pod ...@@ -27,14 +29,16 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
config.installation_root = config.installation_root + 'SampleProject' config.installation_root = config.installation_root + 'SampleProject'
path = TargetInspector.new(target_definition).send(:compute_project_path) target_inspector = TargetInspector.new(target_definition, config.installation_root)
path = target_inspector.send(:compute_project_path)
path.to_s.should.include 'SampleProject/SampleProject.xcodeproj' path.to_s.should.include 'SampleProject/SampleProject.xcodeproj'
end end
it 'raise if there is no project and none specified in the target definition' do it 'raise if there is no project and none specified in the target definition' do
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
e = lambda { TargetInspector.new(target_definition).send(:compute_project_path) }.should.raise Informative target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_project_path) }.should.raise Informative
e.message.should.match /Could not.*select.*project/ e.message.should.match /Could not.*select.*project/
end end
...@@ -44,7 +48,8 @@ module Pod ...@@ -44,7 +48,8 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
config.installation_root = config.installation_root + 'Project[With]Special{chars}in*path?' config.installation_root = config.installation_root + 'Project[With]Special{chars}in*path?'
path = TargetInspector.new(target_definition).send(:compute_project_path) target_inspector = TargetInspector.new(target_definition, config.installation_root)
path = target_inspector.send(:compute_project_path)
path.to_s.should.include 'Project[With]Special{chars}in*path?/Project[With]Special{chars}in*path?.xcodeproj' path.to_s.should.include 'Project[With]Special{chars}in*path?/Project[With]Special{chars}in*path?.xcodeproj'
end end
end end
...@@ -59,7 +64,8 @@ module Pod ...@@ -59,7 +64,8 @@ module Pod
user_project.new_target(:application, 'FirstTarget', :ios) user_project.new_target(:application, 'FirstTarget', :ios)
user_project.new_target(:application, 'UserTarget', :ios) user_project.new_target(:application, 'UserTarget', :ios)
targets = TargetInspector.new(target_definition).send(:compute_targets, user_project) target_inspector = TargetInspector.new(target_definition, config.installation_root)
targets = target_inspector.send(:compute_targets, user_project)
targets.map(&:name).should == ['UserTarget'] targets.map(&:name).should == ['UserTarget']
end end
...@@ -68,7 +74,8 @@ module Pod ...@@ -68,7 +74,8 @@ module Pod
target_definition.link_with = ['UserTarget'] target_definition.link_with = ['UserTarget']
user_project = Xcodeproj::Project.new('path') user_project = Xcodeproj::Project.new('path')
e = lambda { TargetInspector.new(target_definition).send(:compute_targets, user_project) }.should.raise Informative target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_targets, user_project) }.should.raise Informative
e.message.should.match /Unable to find the targets/ e.message.should.match /Unable to find the targets/
end end
...@@ -78,14 +85,17 @@ module Pod ...@@ -78,14 +85,17 @@ module Pod
user_project.new_target(:application, 'FirstTarget', :ios) user_project.new_target(:application, 'FirstTarget', :ios)
user_project.new_target(:application, 'UserTarget', :ios) user_project.new_target(:application, 'UserTarget', :ios)
targets = TargetInspector.new(target_definition).send(:compute_targets, user_project) target_inspector = TargetInspector.new(target_definition, config.installation_root)
targets = target_inspector.send(:compute_targets, user_project)
targets.map(&:name).should == ['UserTarget'] targets.map(&:name).should == ['UserTarget']
end end
it 'raises if the name of the target definition does not match any file' do it 'raises if the name of the target definition does not match any file' do
target_definition = Podfile::TargetDefinition.new('UserTarget', nil) target_definition = Podfile::TargetDefinition.new('UserTarget', nil)
user_project = Xcodeproj::Project.new('path') user_project = Xcodeproj::Project.new('path')
e = lambda { TargetInspector.new(target_definition).send(:compute_targets, user_project) }.should.raise Informative
target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_targets, user_project) }.should.raise Informative
e.message.should.match /Unable to find a target named/ e.message.should.match /Unable to find a target named/
end end
...@@ -96,14 +106,17 @@ module Pod ...@@ -96,14 +106,17 @@ module Pod
user_project.new_target(:application, 'FirstTarget', :ios) user_project.new_target(:application, 'FirstTarget', :ios)
user_project.new_target(:application, 'UserTarget', :ios) user_project.new_target(:application, 'UserTarget', :ios)
targets = TargetInspector.new(target_definition).send(:compute_targets, user_project) target_inspector = TargetInspector.new(target_definition, config.installation_root)
targets = target_inspector.send(:compute_targets, user_project)
targets.map(&:name).should == ['FirstTarget'] targets.map(&:name).should == ['FirstTarget']
end end
it 'raises if the default target definition cannot be linked because there are no user targets' do it 'raises if the default target definition cannot be linked because there are no user targets' do
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
user_project = Xcodeproj::Project.new('path') user_project = Xcodeproj::Project.new('path')
e = lambda { TargetInspector.new(target_definition).send(:compute_targets, user_project) }.should.raise Informative
target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_targets, user_project) }.should.raise Informative
e.message.should.match /Unable to find a target/ e.message.should.match /Unable to find a target/
end end
end end
...@@ -121,7 +134,8 @@ module Pod ...@@ -121,7 +134,8 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target] user_targets = [target]
configurations = TargetInspector.new(target_definition).send(:compute_build_configurations, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
configurations = target_inspector.send(:compute_build_configurations, user_targets)
configurations.should == { configurations.should == {
'Debug' => :debug, 'Debug' => :debug,
'Release' => :release, 'Release' => :release,
...@@ -134,7 +148,8 @@ module Pod ...@@ -134,7 +148,8 @@ module Pod
target_definition.build_configurations = { 'AppStore' => :release } target_definition.build_configurations = { 'AppStore' => :release }
user_targets = [] user_targets = []
configurations = TargetInspector.new(target_definition).send(:compute_build_configurations, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
configurations = target_inspector.send(:compute_build_configurations, user_targets)
configurations.should == { 'AppStore' => :release } configurations.should == { 'AppStore' => :release }
end end
end end
...@@ -151,7 +166,8 @@ module Pod ...@@ -151,7 +166,8 @@ module Pod
target_definition.set_platform(:ios, '4.0') target_definition.set_platform(:ios, '4.0')
user_targets = [target] user_targets = [target]
archs = TargetInspector.new(target_definition).send(:compute_archs, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
archs = target_inspector.send(:compute_archs, user_targets)
archs.should == %w(armv7) archs.should == %w(armv7)
end end
...@@ -166,7 +182,8 @@ module Pod ...@@ -166,7 +182,8 @@ module Pod
target_definition.set_platform(:ios, '4.0') target_definition.set_platform(:ios, '4.0')
user_targets = [targeta, targetb] user_targets = [targeta, targetb]
archs = TargetInspector.new(target_definition).send(:compute_archs, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
archs = target_inspector.send(:compute_archs, user_targets)
archs.should == %w(armv7) archs.should == %w(armv7)
end end
...@@ -179,7 +196,8 @@ module Pod ...@@ -179,7 +196,8 @@ module Pod
target_definition.set_platform(:ios, '4.0') target_definition.set_platform(:ios, '4.0')
user_targets = [target] user_targets = [target]
archs = TargetInspector.new(target_definition).send(:compute_archs, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
archs = target_inspector.send(:compute_archs, user_targets)
archs.uniq.sort.should == %w(armv7 i386) archs.uniq.sort.should == %w(armv7 i386)
end end
...@@ -194,7 +212,8 @@ module Pod ...@@ -194,7 +212,8 @@ module Pod
target_definition.set_platform(:ios, '4.0') target_definition.set_platform(:ios, '4.0')
user_targets = [target_a, target_b] user_targets = [target_a, target_b]
archs = TargetInspector.new(target_definition).send(:compute_archs, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
archs = target_inspector.send(:compute_archs, user_targets)
archs.uniq.sort.should == %w(armv7 armv7s i386) archs.uniq.sort.should == %w(armv7 armv7s i386)
end end
end end
...@@ -207,7 +226,8 @@ module Pod ...@@ -207,7 +226,8 @@ module Pod
target_definition.set_platform(:ios, '4.0') target_definition.set_platform(:ios, '4.0')
user_targets = [] user_targets = []
platforms = TargetInspector.new(target_definition).send(:compute_platform, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
platforms = target_inspector.send(:compute_platform, user_targets)
platforms.should == Platform.new(:ios, '4.0') platforms.should == Platform.new(:ios, '4.0')
end end
...@@ -220,7 +240,8 @@ module Pod ...@@ -220,7 +240,8 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target] user_targets = [target]
platforms = TargetInspector.new(target_definition).send(:compute_platform, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
platforms = target_inspector.send(:compute_platform, user_targets)
platforms.should == Platform.new(:ios, '4.0') platforms.should == Platform.new(:ios, '4.0')
end end
...@@ -238,7 +259,8 @@ module Pod ...@@ -238,7 +259,8 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target1, target2] user_targets = [target1, target2]
platforms = TargetInspector.new(target_definition).send(:compute_platform, user_targets) target_inspector = TargetInspector.new(target_definition, config.installation_root)
platforms = target_inspector.send(:compute_platform, user_targets)
platforms.should == Platform.new(:ios, '4.0') platforms.should == Platform.new(:ios, '4.0')
end end
...@@ -254,7 +276,9 @@ module Pod ...@@ -254,7 +276,9 @@ module Pod
target_definition = Podfile::TargetDefinition.new(:default, nil) target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target1, target2] user_targets = [target1, target2]
e = lambda { TargetInspector.new(target_definition).send(:compute_platform, user_targets) }.should.raise Informative
target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_platform, user_targets) }.should.raise Informative
e.message.should.match /Targets with different platforms/ e.message.should.match /Targets with different platforms/
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