Commit 7a1b2ad6 authored by Samuel Giddins's avatar Samuel Giddins

[InstallationOptions] Refactor to make automatic delegation opt-in

parent eb59c774
......@@ -113,7 +113,7 @@ module Pod
verify_no_static_framework_transitive_dependencies
verify_framework_usage
generate_pods_project
integrate_user_project if integrate_targets?
integrate_user_project if installation_options.integrate_targets?
perform_post_install_actions
end
......@@ -324,7 +324,7 @@ module Pod
end
@pod_installers ||= []
pod_installer = PodSourceInstaller.new(sandbox, specs_by_platform, can_cache: clean?)
pod_installer = PodSourceInstaller.new(sandbox, specs_by_platform, can_cache: installation_options.clean?)
@pod_installers << pod_installer
pod_installer
end
......@@ -346,7 +346,7 @@ module Pod
# @todo Why the @pod_installers might be empty?
#
def clean_pod_sources
return unless clean?
return unless installation_options.clean?
return unless @pod_installers
@pod_installers.each(&:clean!)
end
......@@ -368,7 +368,7 @@ module Pod
# @todo Why the @pod_installers might be empty?
#
def lock_pod_sources
return unless lock_pod_sources?
return unless installation_options.lock_pod_sources?
return unless @pod_installers
@pod_installers.each do |installer|
pod_target = pod_targets.find { |target| target.pod_name == installer.name }
......@@ -712,7 +712,7 @@ module Pod
pods_project.development_pods.remove_from_project if pods_project.development_pods.empty?
pods_project.sort(:groups_position => :below)
pods_project.recreate_user_schemes(false)
if deterministic_uuids?
if installation_options.deterministic_uuids?
UI.message('- Generating deterministic UUIDs') { pods_project.predictabilize_uuids }
end
pods_project.save
......
......@@ -60,7 +60,7 @@ module Pod
validate_podfile!
validate_lockfile_version!
@result = AnalysisResult.new
if integrate_targets?
if installation_options.integrate_targets?
@result.target_inspections = inspect_targets_to_integrate
else
verify_platforms_specified!
......@@ -252,7 +252,7 @@ module Pod
target = AggregateTarget.new(target_definition, sandbox)
target.host_requires_frameworks |= target_definition.uses_frameworks?
if integrate_targets?
if installation_options.integrate_targets?
target_inspection = result.target_inspections[target_definition]
raise "missing inspection: #{target_definition.name}" unless target_inspection
target.user_project = target_inspection.project
......@@ -285,7 +285,7 @@ module Pod
# @return [Array<PodTarget>]
#
def generate_pod_targets(specs_by_target)
if deduplicate_targets?
if installation_options.deduplicate_targets?
dedupe_cache = {}
all_specs = specs_by_target.flat_map do |target_definition, dependent_specs|
......@@ -380,7 +380,7 @@ module Pod
def generate_pod_target(target_definitions, pod_specs)
pod_target = PodTarget.new(pod_specs, target_definitions, sandbox)
if integrate_targets?
if installation_options.integrate_targets?
target_inspections = result.target_inspections.select { |t, _| target_definitions.include?(t) }.values
pod_target.user_build_configurations = target_inspections.map(&:build_configurations).reduce({}, &:merge)
pod_target.archs = target_inspections.flat_map(&:archs).compact.uniq.sort
......@@ -465,7 +465,7 @@ module Pod
else
source = ExternalSources.from_dependency(dependency, podfile.defined_in_file)
end
source.can_cache = clean?
source.can_cache = installation_options.clean?
source.fetch(sandbox)
end
......@@ -654,7 +654,7 @@ module Pod
# @return [void]
#
def verify_platforms_specified!
unless integrate_targets?
unless installation_options.integrate_targets?
podfile.target_definition_list.each do |target_definition|
if !target_definition.empty? && target_definition.platform.nil?
raise Informative, 'It is necessary to specify the platform in the Podfile if not integrating.'
......
......@@ -14,7 +14,7 @@ module Pod
def self.option(name, default, boolean: true)
name = name.to_s
raise 'existing' if defaults.key?(name)
raise ArgumentError, "The #{name} option is already defined" if defaults.key?(name)
defaults[name] = default
attr_accessor name
alias_method "#{name}?", name if boolean
......@@ -47,18 +47,19 @@ module Pod
module Mixin
def Mixin.included(mod)
mod.send(:attr_accessor, :installation_options)
def mod.delegate_installation_options(&blk)
define_method(:installation_options) do
@installation_options ||= InstallationOptions.from_podfile(instance_eval(&blk))
end
end
end
def respond_to_missing?(name, *args)
def mod.delegate_installation_option_attributes!
define_method(:respond_to_missing?) do |name, *args|
installation_options.respond_to?(name, *args) || super
end
def method_missing(name, *args, &blk)
define_method(:method_missing) do |name, *args, &blk|
if installation_options.respond_to?(name)
installation_options.send(name, *args, &blk)
else
......@@ -68,4 +69,6 @@ module Pod
end
end
end
end
end
end
......@@ -247,7 +247,7 @@ module Pod
end
it 'generates the integration library appropriately if the installation will not integrate' do
@analyzer.integrate_targets = false
@analyzer.installation_options.integrate_targets = false
target = @analyzer.analyze.targets.first
target.client_root.should == config.installation_root
......@@ -721,7 +721,7 @@ module Pod
downloader.expects(:fetch)
downloader.expects(:can_cache=).with(false).once
@analyzer.clean = false
@analyzer.installation_options.clean = false
@analyzer.send(:fetch_external_sources)
end
......
......@@ -52,7 +52,7 @@ module Pod
podfile = generate_podfile
lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile)
@installer.integrate_targets = false
@installer.installation_options.integrate_targets = false
end
#-------------------------------------------------------------------------#
......@@ -150,13 +150,13 @@ module Pod
end
it 'integrates the user targets if the corresponding config is set' do
@installer.integrate_targets = true
@installer.installation_options.integrate_targets = true
@installer.expects(:integrate_user_project)
@installer.install!
end
it "doesn't integrates the user targets if the corresponding config is not set" do
@installer.integrate_targets = false
@installer.installation_options.integrate_targets = false
@installer.expects(:integrate_user_project).never
@installer.install!
end
......@@ -245,7 +245,7 @@ module Pod
lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile)
@installer.integrate_targets = false
@installer.installation_options.integrate_targets = false
@installer.install!
target = @installer.aggregate_targets.first
......@@ -279,7 +279,7 @@ module Pod
lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile)
@installer.integrate_targets = false
@installer.installation_options.integrate_targets = false
should.raise(Informative) { @installer.install! }.message.should.match /conflict.*monkey/
end
......@@ -364,7 +364,7 @@ module Pod
lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile)
@installer.integrate_targets = false
@installer.installation_options.integrate_targets = false
should.raise(Informative) { @installer.install! }.message.should.match /use_frameworks/
end
end
......@@ -543,7 +543,7 @@ module Pod
describe '#clean' do
it 'it cleans only if the config instructs to do it' do
@installer.clean = false
@installer.installation_options.clean = false
@installer.send(:clean_pod_sources)
Installer::PodSourceInstaller.any_instance.expects(:install!).never
end
......@@ -562,14 +562,14 @@ module Pod
end
it "creates build configurations for all of the user's targets" do
@installer.integrate_targets = true
@installer.installation_options.integrate_targets = true
@installer.send(:analyze)
@installer.send(:prepare_pods_project)
@installer.pods_project.build_configurations.map(&:name).sort.should == ['App Store', 'Debug', 'Release', 'Test']
end
it 'sets STRIP_INSTALLED_PRODUCT to NO for all configurations for the whole project' do
@installer.integrate_targets = true
@installer.installation_options.integrate_targets = true
@installer.send(:analyze)
@installer.send(:prepare_pods_project)
@installer.pods_project.build_settings('Debug')['STRIP_INSTALLED_PRODUCT'].should == 'NO'
......@@ -925,7 +925,7 @@ module Pod
platform :ios
end
@installer = Installer.new(config.sandbox, podfile)
@installer.integrate_targets = false
@installer.installation_options.integrate_targets = false
end
it 'runs the pre install hooks' do
......
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