Please disregard the first patch. I accidently attached my first attempt at a fix which wasn't quite correct. Here's the correct patch that actually matches what I described below. Sorry for the mixup.

Pepijn

On 14/6/2010 10:50, Pepijn Van Eeckhoudt wrote:
Could you guys review this patch? This seems to solve both cases. I'll
attach it to the relvant issue if this is considered a good fix.

The patch adds a defined? method to Project. The post condition of
Project.project then becomes that Project.defined? will return true. A
project is considered defined if it's definition has been executed. What
is not guaranteed is that the definition of each sub project has been
executed. AFAICT this shouldn't be a problem and is most likely what we
want in the first place.

Pepijn
Index: lib/buildr/core/project.rb
===================================================================
--- lib/buildr/core/project.rb  (revision 946877)
+++ lib/buildr/core/project.rb  (revision )
@@ -224,6 +224,11 @@
           # Enhance the project using the definition block.
           project.enhance { project.instance_exec project, &block } if block
 
+          # Mark the project as defined
+          project.enhance do |project|
+            project.send :defined
+          end
+
           # Top-level project? Invoke the project definition. Sub-project? We 
don't invoke
           # the project definiton yet (allow project calls to establish order 
of evaluation),
           # but must do so before the parent project's definition is done.
@@ -254,7 +259,7 @@
         end
         project ||= @projects[name] # Not found in scope.
         raise "No such project #{name}" unless project
-        project.invoke
+        project.invoke unless project.defined?
         project
       end
 
@@ -598,8 +603,16 @@
       @calledback ||= {}
     end
 
+    def defined?
+      @defined
+    end
+
   protected
+    def defined
+      @defined = true
+    end
-
+    
+
     # :call-seq:
     #   base_dir = dir
     #
Index: spec/core/project_spec.rb
===================================================================
--- spec/core/project_spec.rb   (revision 919303)
+++ spec/core/project_spec.rb   (revision )
@@ -83,8 +83,18 @@
     Buildr.define('foo') { define('bar') { project('baz:bar') } }
     lambda { project('foo') }.should raise_error(RuntimeError, /Circular 
dependency/)
   end
+
+  it 'should handle non-circular dependencies' do
+    Buildr.define "root" do
+      define "child" do
+        puts project('root')._('foo.resource')
-end
+      end
+    end
 
+    lambda { project('root') }.should_not raise_error
+  end
+end
+
 describe Project, ' property' do
   it 'should be set if passed as argument' do
     define 'foo', 'version'=>'1.1'

Reply via email to