1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/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(Array $package) {
if (!isset($package['pretty_version'])
|| empty($package['pretty_version'])
|| strpos($package['pretty_version'], '-')
) {
return false;
}
return true;
}
// Clean"pretty_version"
function getVersion(Array $package) {
return ltrim($package['pretty_version'], 'v');
}
// 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'])
&& isValid($installed['root'])) {
$main = $installed['root']['name'];
printf("php-composer(%s) = %s\n", $installed['root']['name'], getVersion($installed['root']));
}
if (isset($installed['versions'])) foreach($installed['versions'] as $name => $v) {
if ($name !== $main && isValid($v)) {
printf("bundled(php-composer(%s)) = %s\n", $name, getVersion($v));
}
}
}
// 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));
}
|