You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Sol Kindle <ki...@hotpop.com> on 2006/06/20 19:38:42 UTC
NEWBIE: Dir-attribute/script problem
Hey now,
This is my first Ant project (so please bear with me). My goal here is
to have a single Ant file to build all of my sub-projects.
I am having some trouble getting a third party Ant project (call it
"foo") to run as a subproject to my "top-level" build project. The Foo
build runs just fine when Ant is run directly on it (in it's sub-dir),
but fails to run a jython script when called from my "top-level" build
file. Here's the failure output...
Buildfile: build.xml
foo:
bar:
[script] Traceback (innermost last):
[script] File "<string>", line 9, in ?
[script] ImportError: no module named buildUtil
BUILD FAILED
It fails because the script in the "bar" target cannot find cannot find
the buildUtil.py file. But the buildUtil.py file is located in the same
directory as the Foo build.xml file (see Directory Layout below)
I had thought that "dir" attribute of the "ant" task would change the
current directory context for scripts as well as the build.txt file.
It seems to me as if the "dir" attribute of the "ant" task in my
top-level build file does not change the working dir for the jyhon
script. Does this make sense?
Any suggestions? Thank you in advance.
-Sol
My build.xml target to build 3rd party project
===============================
<target name="foo" description="builds the foo project">
<ant dir="./foo/buildscripts" target="bar"></ant>
</target>
Directory Layout
===========
./build.xml #my top-level build file
./foo/buildscripts/build.xml #3rd party build file
./foo/buildscripts/buildUtil.py #jython script
./foo/buildscripts/lib/pyLib.zip #jython library
3rd Party Target (from ./foo/buildscripts/build.xml)
===========
<target name="bar" description="Does something">
<script language="jython"><![CDATA[
import sys
# make the python standard library avialable
sys.path.append("lib/pyLib.zip")
sys.path.append(".")
# import re
import os
from buildUtil import *
3rdPartyFunction()
]]></script>
</target>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: NEWBIE: Dir-attribute/script problem
Posted by "Alexey N. Solofnenko" <A....@mdl.com>.
I got that problem too, but my solution maybe too low level. In Jython
import folders are hard coded and read only, so I wrote my own launcher
that understood -M option and a special Java property and put them into
PySystemState.path list (for example, state.path.append(new
PyString(path));). I needed extra path directories to be specified on
command line. I [currently] have no idea whether it is possible to
access the state from the script itself.
- Alexey.
Sol Kindle wrote:
> Hey now,
>
> This is my first Ant project (so please bear with me). My goal here
> is to have a single Ant file to build all of my sub-projects.
> I am having some trouble getting a third party Ant project (call it
> "foo") to run as a subproject to my "top-level" build project. The
> Foo build runs just fine when Ant is run directly on it (in it's
> sub-dir), but fails to run a jython script when called from my
> "top-level" build file. Here's the failure output...
>
> Buildfile: build.xml
> foo:
> bar:
> [script] Traceback (innermost last):
> [script] File "<string>", line 9, in ?
> [script] ImportError: no module named buildUtil
> BUILD FAILED
>
> It fails because the script in the "bar" target cannot find cannot
> find the buildUtil.py file. But the buildUtil.py file is located in
> the same directory as the Foo build.xml file (see Directory Layout below)
>
> I had thought that "dir" attribute of the "ant" task would change the
> current directory context for scripts as well as the build.txt file.
> It seems to me as if the "dir" attribute of the "ant" task in my
> top-level build file does not change the working dir for the jyhon
> script. Does this make sense?
>
> Any suggestions? Thank you in advance.
>
> -Sol
>
>
> My build.xml target to build 3rd party project
> ===============================
> <target name="foo" description="builds the foo project">
> <ant dir="./foo/buildscripts" target="bar"></ant>
> </target>
>
> Directory Layout
> ===========
> ./build.xml #my top-level build file
> ./foo/buildscripts/build.xml #3rd party build file
> ./foo/buildscripts/buildUtil.py #jython script
> ./foo/buildscripts/lib/pyLib.zip #jython library
>
>
> 3rd Party Target (from ./foo/buildscripts/build.xml)
> ===========
> <target name="bar" description="Does something">
> <script language="jython"><![CDATA[
> import sys
> # make the python standard library avialable
> sys.path.append("lib/pyLib.zip")
> sys.path.append(".")
>
> # import re
> import os
> from buildUtil import *
>
> 3rdPartyFunction()
> ]]></script>
> </target>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
Re: NEWBIE: Dir-attribute/script problem
Posted by kindsol <ki...@hotpop.com>.
Thanks, DD!
I had to use project.resolveFile(), but that got it going!
yes!
-Sol
On Jun 20, 2006, at 12:52 PM, Dominique Devienne wrote:
>> I have never used p.resolveFile() and am having a hard time finding
>> documentation on it. Is it Ant api or python?
>
> Ant API. org.apache.tools.ant.Project#resolveFile(String), returns
> File or String, I don't recall. --DD
>
>> Would you use it directly inside <script>? Would you use it for
>> the sys.path.append() calls? If so, how?
>
> Yes, I think. <script> binds the current project to the p variable
> using BSF, so your script can very easily use this call. Lookup the
> archives for p.resolveFile, and you should find examples. --DD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: NEWBIE: Dir-attribute/script problem
Posted by Dominique Devienne <dd...@gmail.com>.
> I have never used p.resolveFile() and am having a hard time finding
> documentation on it. Is it Ant api or python?
Ant API. org.apache.tools.ant.Project#resolveFile(String), returns
File or String, I don't recall. --DD
> Would you use it directly inside <script>? Would you use it for
> the sys.path.append() calls? If so, how?
Yes, I think. <script> binds the current project to the p variable
using BSF, so your script can very easily use this call. Lookup the
archives for p.resolveFile, and you should find examples. --DD
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: NEWBIE: Dir-attribute/script problem
Posted by kindsol <ki...@hotpop.com>.
Thank a bunch for the reply!
I have never used p.resolveFile() and am having a hard time finding
documentation on it. Is it Ant api or python?
Would you use it directly inside <script>? Would you use it for
the sys.path.append() calls? If so, how?
>> <target name="bar" description="Does something">
>> <script language="jython"><![CDATA[
>> import sys
>> # make the python standard library avialable
>> sys.path.append("lib/pyLib.zip")
>> sys.path.append(".")
>>
>> # import re
>> import os
>> from buildUtil import *
>>
>> 3rdPartyFunction()
>> ]]></script>
>> </target>
Thanks again!
Sorry for my ignorance.
-Sol
On Jun 20, 2006, at 10:47 AM, Dominique Devienne wrote:
> The 'cwd' is never changed. What changes in the project's basedir,
> based on the various attributes that <ant> accepts. See the table in
> <ant>'s documentation for details.
>
> Personally, I always use <subant> instead of <ant>, to avoid messing
> up the 'basedir'. You probably also want to use
> p.resolveFile(relative_filename) within your script to translate
> relative_filename to an abs. path relative to the project's basedir,
> rather than 'cwd', which can be different depending where you call the
> build from.
>
> Leaving the 'basedir' alone, combined with p.resolveFile() should do
> the trick. --DD
>
> On 6/20/06, Sol Kindle <ki...@hotpop.com> wrote:
>> Hey now,
>>
>> This is my first Ant project (so please bear with me). My goal
>> here is
>> to have a single Ant file to build all of my sub-projects.
>>
>> I am having some trouble getting a third party Ant project (call it
>> "foo") to run as a subproject to my "top-level" build project.
>> The Foo
>> build runs just fine when Ant is run directly on it (in it's sub-
>> dir),
>> but fails to run a jython script when called from my "top-level"
>> build
>> file. Here's the failure output...
>>
>> Buildfile: build.xml
>> foo:
>> bar:
>> [script] Traceback (innermost last):
>> [script] File "<string>", line 9, in ?
>> [script] ImportError: no module named buildUtil
>> BUILD FAILED
>>
>> It fails because the script in the "bar" target cannot find cannot
>> find
>> the buildUtil.py file. But the buildUtil.py file is located in
>> the same
>> directory as the Foo build.xml file (see Directory Layout below)
>>
>> I had thought that "dir" attribute of the "ant" task would change the
>> current directory context for scripts as well as the build.txt file.
>> It seems to me as if the "dir" attribute of the "ant" task in my
>> top-level build file does not change the working dir for the jyhon
>> script. Does this make sense?
>>
>> Any suggestions? Thank you in advance.
>>
>> -Sol
>>
>>
>> My build.xml target to build 3rd party project
>> ===============================
>> <target name="foo" description="builds the foo project">
>> <ant dir="./foo/buildscripts" target="bar"></ant>
>> </target>
>>
>>
>> Directory Layout
>> ===========
>> ./build.xml #my top-level build file
>> ./foo/buildscripts/build.xml #3rd party build file
>> ./foo/buildscripts/buildUtil.py #jython script
>> ./foo/buildscripts/lib/pyLib.zip #jython library
>>
>>
>> 3rd Party Target (from ./foo/buildscripts/build.xml)
>> ===========
>> <target name="bar" description="Does something">
>> <script language="jython"><![CDATA[
>> import sys
>> # make the python standard library avialable
>> sys.path.append("lib/pyLib.zip")
>> sys.path.append(".")
>>
>> # import re
>> import os
>> from buildUtil import *
>>
>> 3rdPartyFunction()
>> ]]></script>
>> </target>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: NEWBIE: Dir-attribute/script problem
Posted by Dominique Devienne <dd...@gmail.com>.
The 'cwd' is never changed. What changes in the project's basedir,
based on the various attributes that <ant> accepts. See the table in
<ant>'s documentation for details.
Personally, I always use <subant> instead of <ant>, to avoid messing
up the 'basedir'. You probably also want to use
p.resolveFile(relative_filename) within your script to translate
relative_filename to an abs. path relative to the project's basedir,
rather than 'cwd', which can be different depending where you call the
build from.
Leaving the 'basedir' alone, combined with p.resolveFile() should do
the trick. --DD
On 6/20/06, Sol Kindle <ki...@hotpop.com> wrote:
> Hey now,
>
> This is my first Ant project (so please bear with me). My goal here is
> to have a single Ant file to build all of my sub-projects.
>
> I am having some trouble getting a third party Ant project (call it
> "foo") to run as a subproject to my "top-level" build project. The Foo
> build runs just fine when Ant is run directly on it (in it's sub-dir),
> but fails to run a jython script when called from my "top-level" build
> file. Here's the failure output...
>
> Buildfile: build.xml
> foo:
> bar:
> [script] Traceback (innermost last):
> [script] File "<string>", line 9, in ?
> [script] ImportError: no module named buildUtil
> BUILD FAILED
>
> It fails because the script in the "bar" target cannot find cannot find
> the buildUtil.py file. But the buildUtil.py file is located in the same
> directory as the Foo build.xml file (see Directory Layout below)
>
> I had thought that "dir" attribute of the "ant" task would change the
> current directory context for scripts as well as the build.txt file.
> It seems to me as if the "dir" attribute of the "ant" task in my
> top-level build file does not change the working dir for the jyhon
> script. Does this make sense?
>
> Any suggestions? Thank you in advance.
>
> -Sol
>
>
> My build.xml target to build 3rd party project
> ===============================
> <target name="foo" description="builds the foo project">
> <ant dir="./foo/buildscripts" target="bar"></ant>
> </target>
>
>
> Directory Layout
> ===========
> ./build.xml #my top-level build file
> ./foo/buildscripts/build.xml #3rd party build file
> ./foo/buildscripts/buildUtil.py #jython script
> ./foo/buildscripts/lib/pyLib.zip #jython library
>
>
> 3rd Party Target (from ./foo/buildscripts/build.xml)
> ===========
> <target name="bar" description="Does something">
> <script language="jython"><![CDATA[
> import sys
> # make the python standard library avialable
> sys.path.append("lib/pyLib.zip")
> sys.path.append(".")
>
> # import re
> import os
> from buildUtil import *
>
> 3rdPartyFunction()
> ]]></script>
> </target>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org