pyrus / Pyrus_Developer

Developer tools for building PEAR compatible packages
7 stars 7 forks source link

Tasks are ignored with pyrus make #6

Closed boenrobot closed 12 years ago

boenrobot commented 13 years ago

In my package, I have a custom package.xml file, which defines some replace tasks. Although pyrus make does read, validate this file and everything, the generated package.xml removes all tasks:replace. Looking at the source, it seems the make command disregards the file list completely https://github.com/pyrus/Pyrus_Developer/blob/master/src/Pyrus/Developer/PackageFile/PEAR2SVN.php#L63

It would be great if tasks could be preserved.

saltybeagle commented 13 years ago

The make command is used to generate the package.xml, and any customizations inside a previous package.xml file will likely be ignored.

If you'd like to modify the contents of the generated package.xml, you can do so in a packagexmlsetup.php file.

More info here: http://pear.php.net/manual/en/pyrus.commands.make.php

If you have custom tasks, you can place them within a customtask directory, and Pyrus will automatically recognize them.

boenrobot commented 13 years ago

The API docs on the $package variable's interface are... well... lacking.

Trying to find my way around with the source, starting with https://github.com/pyrus/Pyrus/blob/master/src/Pyrus/PackageFile/v2.php I end up lost at https://github.com/pyrus/Pyrus/blob/master/src/Pyrus/PackageFile/v2/Files/File.php

How am I supposed to create a common replace task for a file, or better yet - get the task from the original package.xml file and alter it into the new package.xml?

\Pyrus\Task\Replace doesn't exactly make sense... I mean...

<?php
$package->files['tests/configuration.xml']['tasks:replace']
    = \Pyrus\Task\Replace(
        $package, \Pyrus\Task\Common::PACKAGEANDINSTALL,
        'where do I get $xml from?',
        array('type' => 'pear-config', 'from' => '../src', 'to' => 'php_dir'),
        'I realize the purpose of $lastversion, but does it even make sense
        in this context? What do I use here?'
);
?>

Assuming I've gotten the above right (minus the $xml and $lastversion)... how do I add multiple replace tasks? Do another such set? If so, that's very counter intuitive. If not... I'm back to square 1.

I'm not holding my breath for a "sure", but I'll ask anyway... any chance of somehow allowing the export of $package as a string or DOMDocument, and allow it to later be parsed (and validated of course) from a string or DOMDocument? Maybe it's just me, but I feel much more comfortable/confident/whatever dealing with the XML file itself (though DOM), than with APIs like that.

edit: Oh... __toString() in $package. Nice. But how do I import the changed version?

saltybeagle commented 13 years ago

Right now, the best way to understand the API is to use the tests. I think coverage is around 80% right now, so most everything you need to do should have some related tests. I found an example:

<?php
$pf->files['foobar'] = array(
    'attribs' => array('role' => 'php'),
    'tasks:replace' => array('attribs' =>
                             array('from' => '@blah@', 'to' => 'version', 'type' => 'package-info'))
);
boenrobot commented 13 years ago

I tried to do

$package->files['tests/configuration.xml']['tasks:replace'] = array(
    'attribs' => array(
        'from' => '../src', 'to' => 'php_dir', 'type' => 'pear-config'
    )
);

I had previously misspelled the "tests" directory to "test", and I rightfully got a notice that this had no effect. With this, I didn't had a notice AND there doesn't seem an effect in the generated package.xml.

edit: Trying to debug this, when I do

var_dump($package->files['tests/configuration.xml']);

I get

object(PEAR2\Pyrus\PackageFile\v2\Files\File)#264 (4) {
  ["pkg":protected]=>
  object(PEAR2\Pyrus\Developer\PackageFile\v2)#259 (14) {
    ["rootAttributes"]=>
    array(5) {
      ["version"]=>
      string(3) "2.1"
      ["xmlns"]=>
      string(35) "http://pear.php.net/dtd/package-2.1"
      ["xmlns:tasks"]=>
      string(33) "http://pear.php.net/dtd/tasks-1.0"
      ["xmlns:xsi"]=>
      string(41) "http://www.w3.org/2001/XMLSchema-instance"
      ["xsi:schemaLocation"]=>
      string(162) "http://pear.php.net/dtd/tasks-1.0
     http://pear.php.net/dtd/tasks-1.0.xsd
     http://pear.php.net/dtd/package-2.1
     http://pear.php.net/dtd/package-2.1.xsd"
    }
...

The file does exist, it's not misspelled, and var_dump()-ing the $package->files shows it as a member. Yet for some reason I'm lead back to the package.xml root.

boenrobot commented 12 years ago

OK. Figured it. It seems the API is less robust (actually, "predictable" might be a better word) than what I gave it credit for. The example you showed worked... and that's the ONLY kind of assignment that works.

To work around this limitation, I resorted to code like:

$srcDirTask = array(
    'tasks:replace' => array(
        array(
            'attribs' => array(
                'from' => '../src',
                'to' => 'php_dir',
                'type' => 'pear-config'
            )
        )
    )
);
$package->files['tests/configuration.xml'] = array_merge_recursive(
    $package->files['tests/configuration.xml']->getArrayCopy(), $srcDirTask
);
//Other files that need $srcDirTask

(another fun bit... storing $package->files['tests/configuration.xml'] and working with it fails with a "calling method on non-object" error; only explicit calls like above worked)

Anyway... Thank you for your assistance.