diff options
author | Markus Roberts <Markus@reality.com> | 2010-06-10 22:51:12 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | ccc869ea48397235d7ba2a5695424eee4923cb9d (patch) | |
tree | ffd534b345923f62733e4e48cc3e36377fa059fe /lib/puppet/util/autoload.rb | |
parent | 7c6b8836453b2b1e8679923f98854be3b0022edd (diff) | |
download | puppet-ccc869ea48397235d7ba2a5695424eee4923cb9d.tar.gz puppet-ccc869ea48397235d7ba2a5695424eee4923cb9d.tar.xz puppet-ccc869ea48397235d7ba2a5695424eee4923cb9d.zip |
Part 2 of fix for #1175 (functions in environments)
Jesse and I are shooting for the minimal viable fix here, with the idea that
a great deal of refactoring is needed but isn't appropriate at this time. The
changes in this commit are:
* Index the function-holding modules by environment
* We need to know the "current environment" when we're defining a function so
we can attach it to the proper module, and this information isn't dynamically
available when user-defined functions are being created (we're being called by
user written code that doesn't "know" about environments) so we cheat and
stash the value in Puppet::Node::Environment
* since we must do this anyway, it turns out to be cleaner & safer to do the
same when we are evaluating a functon. This is the main change from the prior
version of this patch.
* Add a special *root* environment for the built in functions, and extend all
scopes with it.
* Index the function characteristics (name, type, docstring, etc.) by environment
* Make the autoloader environment aware, so that it uses the modulepath for the
specified environment rather than the default
* Turn off caching of the modulepath since it potentially changes for each node
* Tweak tests that weren't environment aware
Diffstat (limited to 'lib/puppet/util/autoload.rb')
-rw-r--r-- | lib/puppet/util/autoload.rb | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index 7358618f9..4a687bf34 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -73,12 +73,12 @@ class Puppet::Util::Autoload # Load a single plugin by name. We use 'load' here so we can reload a # given plugin. - def load(name) + def load(name,env=nil) return false if named_file_missing?(name) path = name.to_s + ".rb" - searchpath.each do |dir| + searchpath(env).each do |dir| file = File.join(dir, path) next unless file_exist?(file) begin @@ -130,25 +130,22 @@ class Puppet::Util::Autoload end # The list of directories to search through for loadable plugins. - # We have to hard-code the ttl because this library is used by - # so many other classes it's hard to get the load-order such that - # the defaults load before this. - cached_attr(:searchpath, :ttl => 15) do - search_directories.collect { |d| File.join(d, @path) }.find_all { |d| FileTest.directory?(d) } + def searchpath(env=nil) + search_directories(env).collect { |d| File.join(d, @path) }.find_all { |d| FileTest.directory?(d) } end - def module_directories + def module_directories(env=nil) # We have to require this late in the process because otherwise we might have # load order issues. require 'puppet/node/environment' - Puppet::Node::Environment.new.modulepath.collect do |dir| + Puppet::Node::Environment.new(env).modulepath.collect do |dir| Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f| File.join(dir, f) } end.flatten.collect { |d| [File.join(d, "plugins"), File.join(d, "lib")] }.flatten.find_all do |d| FileTest.directory?(d) end end - def search_directories(dummy_argument=:work_arround_for_ruby_GC_bug) - [module_directories, Puppet[:libdir].split(File::PATH_SEPARATOR), $:].flatten + def search_directories(env=nil) + [module_directories(env), Puppet[:libdir].split(File::PATH_SEPARATOR), $:].flatten end end |