Ticket #26 (closed defect: fixed)

Opened 4 years ago

Last modified 12 months ago

Strange behavior with the "dir" property in the PhingTask

Reported by: daniel.kobler@… Owned by: hans
Priority: major Milestone: 2.2.0
Component: Version: 2.2.0RC1
Keywords: Cc:

Description

Hi, I've notice a really strange behavior in the task PhingTask with the dir property.

I've a build.properties with only one property inside :

propel.generator.home = Libraries\propel-1.2.0RC1\generator

And in my build file I try to call an other build like this :

<phing phingfile="build.xml" inheritAll="true" dir="${propel.generator.home}" target="creole">
  <property name="project" value="bookstore"/>
  <property name="project.dir" value="${propel.generator.home}/projects/bookstore"/>
</phing>

When I run my build I get this error statment :

[phing] Error reading project file [wrapped: Cannot fopen C:\MyProject\Libraries\propel-1.2.0RC1\generator\Libraries\prope
l-1.2.0RC1\generator\build.xml. failed to open stream: No such file or directory]

As you can see the propel.generator.home property have been duplicated twice in the final search path. I've browse the source and found that the mistake is located in the PhingTask.php file, line 218. Here is the code :

if ($this->dir !== null) {
    $this->newProject->setBasedir($this->dir);
    if ($savedDir !== null) { // has been set explicitly
        $this->newProject->setInheritedProperty("project.basedir", $this->dir->getAbsolutePath());
    }                                
} else {
    $this->dir = $this->getProject()->getBaseDir();
}

After some tests I've seen that the $this->dir value is correct before the $this->newProject->setBaseDir call but wrong right after. I've checked the setBasedir of the project class, but I don't understand the side effect that cause this problem. Temporary I've solved this by changing the code in the like this :

if ($this->dir !== null) {
    $this->newProject->setBasedir($this->dir);
    // [DK] Correction of a strange bug. I don't understand what's going on, but the dir is changed by the setBasedir call.
    $this->dir = $this->newProject->getBasedir();
    if ($savedDir !== null) { // has been set explicitly
        $this->newProject->setInheritedProperty("project.basedir", $this->dir->getAbsolutePath());
    }                                
} else {
    $this->dir = $this->getProject()->getBaseDir();
}

Hope this will help you guys and thanks again for this great product that is phing !

Attachments

Change History

Changed 4 years ago by hans

  • owner set to hans
  • status changed from new to assigned

Wow, this was a really tricky one to track down. You were right, the problem is related to Project->setBasedir(). What happens when you call Project->setBasedir() is that is calls chdir() with the new path; this chdir() happens so that you can resolve paths relative to your projects base directory. So, of course, this means that when you call getAbsolutePath() on a dir (PhingFile) object created with a relative path, it is going to call getcwd() to resolve it. So, essentially, the call to Project->setBasedir() changed the filesystem cwd out from under the PhingFile (directory) object.

This probably points to a bigger design flaw, but the short fix is probably just to reset the $this->dir value, after calling Project->setBasedir(). I'll think about this a bit more & see if I can figure out a better solution to this problem. Unfortunately, I think we really need to keep the behavior where it calls chdir(), because that fixed a bunch of quirky behavior when trying to resolve relative paths.

Changed 4 years ago by hans

  • status changed from assigned to closed
  • resolution set to fixed

Ok, this should be fixed in branch & trunk as of changeset:78. Please let me know if you still have any errors.

Add/Change #26 (Strange behavior with the "dir" property in the PhingTask)

Author


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


Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.