Skip to content

Commit

Permalink
Compile the provider overrides early so config caching works
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Apr 20, 2013
1 parent e8d8188 commit 9dd582b
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions plugins/kernel_v2/config/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def initialize

# Internal state
@__compiled_provider_configs = {}
@__compiled_provider_overrides = {}
@__defined_vm_keys = []
@__defined_vms = {}
@__finalized = false
@__networks = {}
@__providers = {}
@__provider_overrides = {}
@__synced_folders = {}
end

Expand Down Expand Up @@ -80,6 +80,14 @@ def merge(other)
new_providers[key] += blocks
end

# Merge the provider overrides by appending them...
other_overrides = other.instance_variable_get(:@__provider_overrides)
new_overrides = @__provider_overrides.dup
other_overrides.each do |key, blocks|
new_overrides[key] ||= []
new_overrides[key] += blocks
end

# Merge synced folders.
other_folders = other.instance_variable_get(:@__synced_folders)
new_folders = @__synced_folders.dup
Expand All @@ -91,6 +99,7 @@ def merge(other)
result.instance_variable_set(:@__defined_vm_keys, new_defined_vm_keys)
result.instance_variable_set(:@__defined_vms, new_defined_vms)
result.instance_variable_set(:@__providers, new_providers)
result.instance_variable_set(:@__provider_overrides, new_overrides)
result.instance_variable_set(:@__synced_folders, new_folders)
end
end
Expand Down Expand Up @@ -165,7 +174,17 @@ def network(type, options=nil)
def provider(name, &block)
name = name.to_sym
@__providers[name] ||= []
@__providers[name] << block if block_given?
@__provider_overrides[name] ||= []

if block_given?
@__providers[name] << block if block_given?

# If this block takes two arguments, then we curry it and store
# the configuration override for use later.
if block.arity == 2
@__provider_overrides[name] << block.curry[Vagrant::Config::V2::DummyConfig.new]
end
end
end

def provision(name, options=nil, &block)
Expand Down Expand Up @@ -223,23 +242,15 @@ def finalize!

# Load it up
config = config_class.new
overrides = []

blocks.each do |b|
b.call(config, Vagrant::Config::V2::DummyConfig.new)

# If the block takes two arguments, then we store the second
# one away for overrides later.
if b.arity == 2
overrides << b.curry[Vagrant::Config::V2::DummyConfig.new]
end
end

config.finalize!

# Store it for retrieval later
@__compiled_provider_configs[name] = config
@__compiled_provider_overrides[name] = overrides
end

# Flag that we finalized
Expand Down Expand Up @@ -274,7 +285,7 @@ def get_provider_config(name)
# @param [Symbol] name Name of the provider
# @return [Array<Proc>]
def get_provider_overrides(name)
(@__compiled_provider_overrides[name] || []).map do |p|
(@__provider_overrides[name] || []).map do |p|
["2", p]
end
end
Expand Down

0 comments on commit 9dd582b

Please sign in to comment.