map-exts.php 2.14 KiB
#!/usr/bin/env php
<?php
error_reporting(-1);
$argv = $_SERVER['argv'];
array_shift($argv);
echo "php_packages:";
foreach($argv as $version) {
    fputs(STDERR, "\nProcessing PHP ${version}\n");
    exec("apt-get install -yq php${version}-cli");
    exec("apt-cache search ^php${version}- | awk '/^php${version}-/&&!/-dbg/{print$1}'", $packages, $error);
    if ($error) {
        die("code: $error");
    $lines = [];
    exec("apt-cache show " . implode(" ", $packages) . " | egrep '^(Package|Provides):'", $lines, $error);
    if ($error) {
        die("code: $error");
    $map = [];
    $package = null;
    foreach ($lines as $line) {
        [$header, $content] = explode(': ', $line, 2);
        switch ($header) {
            case 'Package':
                $package = $content;
                break;
            case 'Provides':
                if (!$package) {
                    fputs(STDERR, "ignoring Provides without Package: $line\n");
                    continue 2;
                $thispackage = $package;
                $package = null;
                if (strpos($thispackage, "php${version}-") !== 0) {
                    continue 2;
                $matches = [];
                preg_match_all("/\\bphp(?:\\Q${version}\\E)?\\-([^ ,]+)/", $content, $matches, PREG_PATTERN_ORDER);
                if (!$matches) {
                    continue 2;
                $exts = array_unique($matches[1]);
                if (!$exts) {
                    continue 2;
                foreach ($exts as $ext) {
                    $map[$ext] = $thispackage;
                break;
            default:
                fputs(STDERR, "ignoring: $line\n");
    $builtins = [];
    exec("php${version} -n -m | egrep -v '^(\\[|$)'", $builtins, $error);
    if ($error) {
        die("code: $error");
    foreach($builtins as $builtin) {
        $map[strtolower($builtin)] = 'builtin';
7172737475767778
ksort($map); printf(" \"%s\":\n", $version); foreach ($map as $ext => $package) { printf(" %s: %s\n", $ext, $package); } }