You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Kitching Simon <Si...@orange.ch> on 2000/08/18 10:38:28 UTC

RE: if basedir absolute file name then resolving file names cause s duplicate basedirs in resulting string

Yep, I found this one too. 

The following patch to taskdefs/Ant.java fixes the problem (though there may
be better fixes - I'm an ant newbie ;-)

To summarize the problem:

<ant antFile="/home/someuser/build.xml" .... />
or
<ant antFile="${some_dir}/build.xml" .... />

The above ant tasks generate bad antFile paths, because the path is
absolute. Currently,
only relative paths work, eg "antFile="../mybuildfile.cml" works ok.

Index: Ant.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,
v
retrieving revision 1.14
diff -r1.14 Ant.java
178c178
<             antFile = (new File(dir, antFile)).getAbsolutePath();
---
>             antFile = p1.resolveFile(antFile).getAbsolutePath();


> -----Original Message-----
> From:	Barrie Treloar [SMTP:Barrie.Treloar@camtech.com.au]
> Sent:	Friday, August 18, 2000 8:48 AM
> To:	Ant Developers Mailing List
> Subject:	if basedir absolute file name then resolving file names
> causes duplicate basedirs in resulting string
> 
> This has only just started to happen and I can't seem to find the
> reason for it.
> 
> When basedir is an absolute path all resolution of relative paths will
> cause the basedir to be appended twice to the path.
> 
> Does anyone else see this same problem? (from the latest CVS build)
> 
> Barrie
> --
> Barrie Treloar
> ____________________________________________________________________
> 
>   Barrie Treloar                      Phone: +61 8 8303 3300
>   Senior Analyst/Programmer           Fax:   +61 8 8303 4403 
>   Electronic Commerce Division        Email: barrie@camtech.com.au
>   Camtech (SA) Pty Ltd                http://www.camtech.com.au
>  --- Level 8, 10 Pulteney Street, Adelaide SA 5000, Australia. ---
> ____________________________________________________________________
> 

Re: if basedir absolute file name then resolving file names causes duplicate basedirs in resulting string

Posted by Jesse Glick <Je...@netbeans.com>.
Kitching Simon wrote:
> The above ant tasks generate bad antFile paths, because the path is
> absolute. Currently,
> only relative paths work, eg "antFile="../mybuildfile.cml" works ok.

Somewhat related:

I find the semantics of 'dir' vs 'antFile' attributes on the <ant> task
very confusing. The documentation is murky on how it works.

- If you specify only antFile, and give it a build file in a different
directory, what is the subproject's basedir set to? That different
directory, I assume.

- What if the subproject's buildfile says basedir=".." or
basedir="some/sub/dir"? Will it still work?

- If the buildfile is called build.xml, and you give just dir, does it
work the same or differently?

- If you give both, then what?

So attached is a test case. Run the upper script. In *no case* is the
basedir attribute of the lower script honored (it seems to be ignored,
since using both "." and "sub2" have the same effect)--I would expect
all three cases to show sub1/sub2/ as the resolution of "." for the pwd.
The first run (just antFile) runs in the top directory. Passing just dir
runs in sub1, as does passing both dir and antFile. (Passing both did
not work the same in Ant 1.1 BTW--you would still have to qualify
antFile, otherwise it would recurse on the current script!)

My suggested semantics: if both antFile and dir are missing, then the
current script is used; if antFile only is given, it is treated as a
filename for the build script relative to the current script's basedir;
if just dir is given, it is the same as giving antFile with that dir
plus "/build.xml"; passing both antFile and dir is a syntax error. When
the subproject is run, it is given a basedir calculated from the
directory in which that build script is contained, modified/replaced by
its basedir attribute, regardless of where the master script is. This
would make <ant> consistent in behavior with running the commandline
e.g. "ant -buildfile sub1/build.xml" (which prints sub1/sub2 as I
expected). Otherwise build scripts will not in general work when called
from elsewhere, since they may expect their basedir to really be set
where they asked and for files to exist in certain places relative to
themselves.

-Jesse

-- 
Jesse Glick   <ma...@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR