diff options
author | Remi Collet <remi@remirepo.net> | 2024-10-11 10:05:12 +0200 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2024-10-11 10:05:12 +0200 |
commit | 6a0be7a4761e60b718a8776009b6a2a9b87a283b (patch) | |
tree | 778ae5427bb1c1d6cc8767dabda603b0968be59d /composer.prov |
new projectv0.1.0
Diffstat (limited to 'composer.prov')
-rwxr-xr-x | composer.prov | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/composer.prov b/composer.prov new file mode 100755 index 0000000..d866711 --- /dev/null +++ b/composer.prov @@ -0,0 +1,57 @@ +#!/usr/bin/php +<?php +/* + Use this script to generate bundled provides, e.g.: + ./composer.prov vendor/composer/installed.php + + Copyright (C) 2024 Remi Collet <remi@fedoraproject.org>. + + SPDX-3.0-License-Identifier: GPL-2.0-or-later + + This program is free software. + For more information on the license, see COPYING or + <https://www.gnu.org/licenses/gpl-2.0.en.html>. + For more information on free software, see + <https://www.gnu.org/philosophy/free-sw.en.html>. +*/ + +// Check if composer "pretty_version" is usable in RPM +function isValid($version) { + if (empty($version) + || strpos($version, '-') + ) { + return false; + } + return true; +} + +// Parse an installed.php file +function run($file) { + fputs(STDERR, "Search bundled libraries installed, parsing $file\n"); + $installed = include $file; + $main = false; + if (isset($installed['root']['name']) + && isset($installed['root']['pretty_version']) + && isValid($installed['root']['pretty_version'])) { + + $main = $installed['root']['name']; + printf("php-composer(%s) = %s\n", $installed['root']['name'], $installed['root']['pretty_version']); + } + if (isset($installed['versions'])) foreach($installed['versions'] as $name => $v) { + if ($name !== $main + && isset($v['pretty_version']) + && isValid($v['pretty_version'])) { + printf("bundled(php-composer(%s)) = %s\n", $name, $v['pretty_version']); + } + } +} + +// From command line argument, manual usage +if (isset($_SERVER['argv'][1])) { + run($_SERVER['argv'][1]); + +// From input lines, rpmbuild usage +} else while($f = fgets(STDIN)) { + run(trim($f)); +} + |