Re: Depends hierarchy
"Scott Pennington" <[email protected]> Fri, 23 Sep 2011 17:43:05 -0700
| Newsgroups | gmane.comp.windows.dotnet.nant.user |
|---|---|
| Message-ID | <[email protected]> |
follow on below From: Scott Pennington [mailto:[email protected]] Sent: Friday, September 23, 2011 5:34 PM To: [email protected] Subject: [NAnt-users] Depends hierarchy This is information that will hopefully clarify and give some insight into how depends works in NAnt. There is are a few posts out there on the net that talk about the difference between <call target> and <target depends>. What I find that is missing are some subtle nuances when it comes to when to use depends and when it actually has the effect you desire. To review. <call target> will always exercise the Target. <target depends> will only call the targets listed in the depends if it has not already been called. The <target depends> statement is a little misleading though. The more accurate description is: will only call the taget(s) listed if the calling target has not already called it through its depends. A call will break the depends chain. The below example has two starting targets. call.me and let.me. These two are designed to call two targets and those two targets each need to have some global target to be run only once. it is to set properties that they both use. (code reduction). The difference is call.me first calls the child targets where the let.me uses depends to call the child targets. Each child target spec1 and spec2 use depends to call the global target. <project> <target name="call.me"> <echo message="call.me" /> <call target="spec1" /> <call target="spec2" /> </target> <target name="let.me" depends="spec1, spec2"> <echo message="let.me" /> </target> <target name="global"> <echo message="global" /> </target> <target name="spec1" depends="global"> <echo message="spec1" /> </target> <target name="spec2" depends="global"> <echo message="spec2" /> </target> </project> When I exercise call.me I got the following output. You will notice that global was called twice even though I had depends listed for both children. This did not do what I wanted. C:\temp\NAnt>nant -buildfile:test-depends.build call.me NAnt 0.90 (Build 0.90.3780.0; release; 5/8/2010) Copyright (C) 2001-2010 Gerry Shaw http://nant.sourceforge.net Buildfile: file:///C:/temp/NAnt/test-depends.build Target framework: Microsoft .NET Framework 3.5 Target(s) specified: call.me call.me: [echo] call.me global: [echo] global spec1: [echo] spec1 global: [echo] global spec2: [echo] spec2 BUILD SUCCEEDED Total time: 1.4 seconds. When I call let.me I get the blow output. I only get global called once. It is also the very first thing to be called even prior to the let.me target. let.me depends on spec1 spec1 depends on global global does not depend on anything so it is exercised. The call returns to spec 1 no more depends so it is exercised the call returns to let.me it still depends on spec2 spec2 checks to see if global has been called and it has already and then this restriction is fulfilled spec2 is exercised the call returns to let.me no more depends let.me is exercised. C:\temp\NAnt>nant -buildfile:test-depends.build let.me NAnt 0.90 (Build 0.90.3780.0; release; 5/8/2010) Copyright (C) 2001-2010 Gerry Shaw http://nant.sourceforge.net Buildfile: file:///C:/temp/NAnt/test-depends.build Target framework: Microsoft .NET Framework 3.5 Target(s) specified: let.me global: [echo] global spec1: [echo] spec1 spec2: [echo] spec2 let.me: [echo] let.me BUILD SUCCEEDED Total time: 1.2 seconds. I just ran a follow on test to just verify that a <call target> will break the depends chain. I created two more targets spec3 and spec4. let.me depends on spec3 depends on global and then calls spec4 which depends on global. You will notice that global is called twice in the output. <project> <target name="let.me" depends="spec1, spec2,spec3"> <echo message="let.me" /> </target> <target name="global"> <echo message="global" /> </target> <target name="spec1" depends="global"> <echo message="spec1" /> </target> <target name="spec2" depends="global"> <echo message="spec2" /> </target> <target name="spec3" depends="global"> <echo message="spec3" /> <call target="spec4" /> </target> <target name="spec4" depends="global"> <echo message="spec2" /> </target> </project> output C:\temp\NAnt>nant -buildfile:test-depends.build let.me NAnt 0.90 (Build 0.90.3780.0; release; 5/8/2010) Copyright (C) 2001-2010 Gerry Shaw http://nant.sourceforge.net Buildfile: file:///C:/temp/NAnt/test-depends.build Target framework: Microsoft .NET Framework 3.5 Target(s) specified: let.me global: [echo] global spec1: [echo] spec1 spec2: [echo] spec2 spec3: [echo] spec3 global: [echo] global spec4: [echo] spec2 let.me: [echo] let.me BUILD SUCCEEDED Total time: 1.8 seconds. Hope you found this helpful. Scott Scott Pennington Senior Software Engineer Prosper Marketplace, Inc. 111 Sutter Street, 22nd Floor San Francisco CA 94104 www.prosper.com <http://www.prosper.com/> CONFIDENTIALITY STATEMENT: This email message, together with all attachments, is intended only for the individual or entity to which it is addressed and may contain legally privileged or confidential information. Any dissemination, distribution or copying of this communication by persons or entities other than the intended recipient, is strictly prohibited, and may be unlawful. If you have received this communication in error please contact the sender immediately and delete the transmitted material and all copies from your system, or if received in hard copy format, return the material to us via the United States Postal Service. Thank you. ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 _______________________________________________ NAnt-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nant-users