We were getting strange dependency cycles because our class structure
mirrored our scope structure.  We can't change the scope structure
without switching from a dynamically scoped language to a lexically scoped
language, which is too big of a change to make right now.  Instead,
I'm changing the resource graph so that all classes default to just
having an edge to the 'main' graph.

This will be a behaviour change for many, in that you were getting
automatic dependencies from this old behaviour, but it will bring
consistency.

Signed-off-by: Luke Kanies <[email protected]>
---
 lib/puppet/parser/compiler.rb |    6 +++++-
 spec/unit/parser/compiler.rb  |   23 +++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 826e85a..2eb9438 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -39,7 +39,11 @@ class Puppet::Parser::Compiler
         # And in the resource graph.  At some point, this might supercede
         # the global resource table, but the table is a lot faster
         # so it makes sense to maintain for now.
-        @catalog.add_edge(scope.resource, resource)
+        if resource.type.to_s.downcase == "class" and main = 
@catalog.resource(:class, :main)
+            @catalog.add_edge(main, resource)
+        else
+            @catalog.add_edge(scope.resource, resource)
+        end
     end
 
     # Do we use nodes found in the code, vs. the external node sources?
diff --git a/spec/unit/parser/compiler.rb b/spec/unit/parser/compiler.rb
index ed439e1..2459978 100755
--- a/spec/unit/parser/compiler.rb
+++ b/spec/unit/parser/compiler.rb
@@ -269,6 +269,29 @@ describe Puppet::Parser::Compiler do
             lambda { @compiler.add_resource(@scope, file2) }.should 
raise_error(Puppet::Resource::Catalog::DuplicateResourceError)
         end
 
+        it "should add an edge from the scope resource to the added resource" 
do
+            resource = stub "noconflict", :ref => "File[yay]"
+            @compiler.add_resource(@scope, resource)
+
+            @compiler.catalog.should be_edge(@scope.resource, resource)
+        end
+
+        it "should add edges from the class resources to the main class" do
+            main = CompilerTestResource.new(:class, :main)
+            @compiler.add_resource(@scope, main)
+            resource = CompilerTestResource.new(:class, "foo")
+            @compiler.add_resource(@scope, resource)
+
+            @compiler.catalog.should be_edge(main, resource)
+        end
+
+        it "should just add edges to the scope resource for the class 
resources when no main class can be found" do
+            resource = CompilerTestResource.new(:class, "foo")
+            @compiler.add_resource(@scope, resource)
+
+            @compiler.catalog.should be_edge(@scope.resource, resource)
+        end
+
         it "should have a method for looking up resources" do
             resource = stub 'resource', :ref => "Yay[foo]"
             @compiler.add_resource(@scope, resource)
-- 
1.6.1


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to