Modify

Ticket #309 (closed defect: fixed)

Opened 3 years ago

Last modified 8 months ago

startdir and 'current directory' not the same when build.xml not in current directory

Reported by: anonymous Owned by: mrook
Priority: major Milestone: 2.5.0
Component: documentation Version: devel
Keywords: Cc:

Description

In the documentation, specifying a project as:

<project ... basedir=".">

(which I believe is the same as leaving 'basedir' unspecified)

is supposed to mean "current directory". I would interpret that to mean "the directory that phing was executed in".

However, when specifying a build.xml file in another directory, the 'current directory' becomes the directory the build file is in, not the directory that phing is executed in. I.e. with a build file of:

/some/path/dir1/build.xml:

<project name="Test" default="main" basedir=".">
    <target name="main">
        <exec command="pwd" passthru="true"/>
        <echo msg="Startdir: ${application.startdir}"/>
    </target>
</project>

If you do:

cd /some/path/dir2
phing -f ../dir1/build.xml main

The output is:

	[exec] Executing command: pwd 2>&1
	[exec] /some/path/dir1
	[echo] Startdir: /some/path/dir2

Which shows that commands are executed in the directory the build.xml file is in *not* the "current path" (as I would define "current path").

Either this is not the correct behavior and the 'current working directory' shouldn't be changed to the directory the build.xml file is in, or the documentation should make it clear that "current directory" means the directory the build.xml file is in, *not* the directory where phing is executed.

---Lawrence

Attachments

Change History

comment:1 in reply to: ↑ description Changed 3 years ago by anonymous

Note:

Specifying basedir as:

<project ... basedir="${application.startdir}">

does not work either. It results in an error message of:

Basedir /some/path/dir1/${application.startdir} does not exist

comment:2 Changed 3 years ago by mrook

  • Owner changed from hans to mrook
  • Status changed from new to assigned
  • Component changed from phing-core to documentation
  • Milestone set to 2.4.0

comment:3 Changed 2 years ago by mrook

  • Milestone changed from 2.4.0RC1 to 2.4.0RC2

comment:4 Changed 2 years ago by mrook

(In [668]) Refs #309 - use getcwd() to resolve basedir attribute

comment:5 Changed 2 years ago by mrook

  • Status changed from assigned to closed
  • Resolution set to fixed

This was not listed correctly in the documentation, and I agree with you that basedir needs to resolved against the current directory. r668 implements this, omitting the basedir attribute sets it to the parent directory of the used build file (original behavior).

comment:6 Changed 13 months ago by mp@…

  • Status changed from closed to reopened
  • Resolution fixed deleted

I think the "old" (pre-r668) behaviour was right.

The basedir attribute defines the project.basedir property and has to be based on the buildfile's location. Think of project.basedir as a reference to the "project root", regardless where a project has been checked out. The buildfile knows its location relative to the project root, so the basedir attribute must be relative to the buildfile.

If you want to perform tasks in the directory phing was started in, application.startdir should be the right property.

Last edited 13 months ago by mp (previous) (diff)

comment:7 Changed 13 months ago by mp

Re-reading the initial report, I have no clear opinion regarding the "correct" cwd.

But with a clear distinction between project.basedir (the "root" of the project the buildfile belongs to, set by the buildfile) and application.startdir (the directory phing was started in) buildfiles can always use the one or other to create absolute references depending on the task at hand.

comment:8 Changed 8 months ago by mp

(In [1128]) Refs #309 - revert changeset [668]

comment:9 Changed 8 months ago by mp

  • Status changed from reopened to closed
  • Resolution set to fixed

Tried to fix this with documentation improvements on the 2.5 branch (might break BC on 2.4, behaviour is like it was on 2.3 and before).

Last edited 8 months ago by mp (previous) (diff)

comment:10 Changed 8 months ago by mp

  • Version changed from 2.3.2 to devel
  • Milestone changed from 2.4.0RC3 to 2.5.0
View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.