Skip to content

Conversation

@ochorocho
Copy link
Contributor

… add method to get installed packages by type

  • Extended installedVersions.php and installed.php with type and install_path
  • Added getInstalledPackagesByType to allow retrieval of of installed packages by a given type

@Seldaek your feedbeack is very welcome :-)

#9648

@ochorocho ochorocho force-pushed the improve-installed-versions-9648 branch from c9d325b to 85fe2a9 Compare February 16, 2021 08:47
@ochorocho
Copy link
Contributor Author

Just had a look whats going on with phpstan issues.
Get 352 errors, even when running it on master

 [ERROR] Found 352 errors     

@ochorocho
Copy link
Contributor Author

@stof can't wrap my head around this phpstan issue. It says Call to an undefined static method. The method is there, and it works locally and in "most" Actions except windows
Any idea what could cause this?

grafik

https://github.com/composer/composer/pull/9699/checks?check_run_id=1912250647

@Seldaek Seldaek added this to the 2.1 milestone Feb 22, 2021
@Seldaek
Copy link
Member

Seldaek commented Feb 24, 2021

@ochorocho sorry for the trouble but could you rebase this on latest master? I merged other things which conflict with your PR.

As for the phpstan error, you can ignore these, it's a quirk of the fact the InstalledVersions file used in CI does not yet contain the new methods until the PR gets merged.

@ochorocho ochorocho force-pushed the improve-installed-versions-9648 branch from 08e200f to f4cbe78 Compare February 25, 2021 09:01
@ochorocho
Copy link
Contributor Author

@Seldaek rebase done :-)

@ochorocho
Copy link
Contributor Author

ochorocho commented Mar 8, 2021

FYI, all packages defined with self.version are missing paths.
Working on a fix right now.

EDIT: Seems like a TYPO3 specific issue. Only relevant for development in the mono repo.

@Seldaek
Copy link
Member

Seldaek commented Mar 16, 2021

FYI, all packages defined with self.version are missing paths.

I am not sure what you mean, if you have more details maybe we can figure out a solution or at least identify the root cause.

@ochorocho
Copy link
Contributor Author

ochorocho commented Mar 16, 2021

FYI, all packages defined with self.version are missing paths.

I am not sure what you mean, if you have more details maybe we can figure out a solution or at least identify the root cause.

install_path was missing for some packages in vendor/composer/InstalledVersions.php.
Checked it again after i applied your suggestion and it seems to work now.

example:

    'typo3/cms-dashboard' => 
    array (
      'dev-requirement' => false,
      'replaced' => 
      array (
        0 => '11.2.x-dev',
        1 => 'dev-master',
      ),
    ),

composer.json of the TYPO3 project https://git.typo3.org/Packages/TYPO3.CMS.git/blob_plain/HEAD:/composer.json
In case i see this appearing again i'll open an seperate issue.

Thank you.

Let me know if you need anything else. :-)

@Seldaek
Copy link
Member

Seldaek commented Mar 16, 2021

Thanks for the fixes. The last thing open is #9699 (review) which definitely needs fixing but then it looks good to me.

'pretty_version' => 'dev-master',
'version' => 'dev-master',
'type' => 'library',
'install_path' => false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string|null is a better type than string|false IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to null

@ochorocho
Copy link
Contributor Author

Thanks for the fixes. The last thing open is #9699 (review) which definitely needs fixing but then it looks good to me.

@Seldaek now using an array containing package name and its path and passing it to generateInstalledVersions.
The root package path is now 'install_path' => '', and metapackage using 'install_path' => NULL,

'pretty_version' => 'dev-master',
'version' => 'dev-master',
'type' => 'library',
'install_path' => false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong

Copy link
Contributor Author

@ochorocho ochorocho Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 'install_path' => '',.

Thank you!

Copy link
Contributor

@stof stof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any tests covering the generation of the install_path key

/**
* Initialize $installed array
*/
public static function __constructStatic() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why __constructStatic ? names prefixed by __ are soft-reserved by PHP for magic methods, and this is not one of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will rename it.

}
}

InstalledVersions::__constructStatic();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ? this is a no-op

} else {
$stringContent = str_replace(array('\\', '\''), array('\\\\', '\\\''), $value);
$folder = $key === 'install_path' ? '__DIR__ . DIRECTORY_SEPARATOR . ' : '';
$lines .= $folder . '\'' . $stringContent . "',\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should still be using var_export to export the string literal, rather than rebuilding it in userland (in an incomplete way)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, i need this to be able to write __DIR__ . DIRECTORY_SEPARATOR . to the PHP file and not the resulting path.
Happy to have any suggestions to avoid using my own method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your generated line is __DIR__ . DIRECTORY_SEPARATOR . followed by a string literal. I'm talking only about the string literal, not about the whole line.

$reference = ($package->getSourceReference() ?: $package->getDistReference()) ?: null;
}

$installPath = $package instanceof RootPackageInterface ? '' : $installPaths[$package->getName()];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong. the relative path from the location of the installed.php file to the root package is not the empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final result in InstalledVersions.php so i reckon the path correct:

self::$installed = array(
    'root' => array(
        'pretty_version' => 'dev-master',
        'version' => 'dev-master',
        'type' => 'library',
        'install_path' => __DIR__ . DIRECTORY_SEPARATOR . '',
        'aliases' => array(
            0 => '2.1.x-dev',
        ),
        'reference' => 'a614587ec91031b99ab23b385838f6d9641c847d',
        'dev-requirement' => true,
        'name' => 'composer/composer',
    ),
   ....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root should have an install_path of __DIR__ . '/../../' for composer, but the result should be dependent on the vendor-dir, so it should really compute the relative path from vendor-dir/composer to getcwd() to find the root install path.

$config = $package->getConfig();
$vendorDir = !empty($config['vendor-dir']) ? $config['vendor-dir'] : 'vendor';
$to = getcwd();
$from = $to . DIRECTORY_SEPARATOR . $vendorDir . DIRECTORY_SEPARATOR . 'composer';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to do your own processing of the vendor-dir config. The $from is the $repoDir that we have in ->write(), i.e. the folder in which we are generating the file. You only need to pass it as an argument in this private method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that hint. Changed it.

@ochorocho
Copy link
Contributor Author

@Seldaek tried to fix testRepositoryWritesInstalledPhp but failed. :-(
The path is confusing me /foo/bar/vendor/woop/woop.

Can you give me any advice to get this test running again?

@ochorocho ochorocho force-pushed the improve-installed-versions-9648 branch from fd6e18f to 6c9b55b Compare April 1, 2021 07:44
@ochorocho
Copy link
Contributor Author

@Seldaek all tests passed now. Branch is up to date with master.

@Seldaek Seldaek force-pushed the improve-installed-versions-9648 branch from 7ea71f2 to 284ec95 Compare May 21, 2021 12:46
@Seldaek
Copy link
Member

Seldaek commented May 21, 2021

@ochorocho thanks for this, I rebased it again and squashed commits to clean up a little then reviewed in depth and did some changes (some of it are kinda unrelated to this PR, just other things I noticed needed tweaking before 2.1 for InstalledVersions while I was poking around). Have a look at my individual commits if you're interested in more details.

I think this is mergeable now, but happy if someone else has a second to review again.

Copy link
Contributor Author

@ochorocho ochorocho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Thank you! :-)

@Seldaek Seldaek merged commit da3d5e3 into composer:master May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants