1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-29 17:00:58 +01:00
phorge-arcanist/scripts/update_compat_info.php
epriestley 8e0e07664a [Wilds] Remove libphutil
Summary:
Ref T13098. Historically, Phabricator was split into three parts:

  - Phabricator, the server.
  - Arcanist, the client.
  - libphutil, libraries shared between the client and server.

One imagined use case for this was that `libphutil` might become a general-purpose library that other projects would use.

However, this didn't really happen, and it seems unlikely to at this point: Phabricator has become a relatively more sophisticated application platform; we didn't end up seeing or encouraging much custom development; what custom development there is basically embraces all of Phabricator since there are huge advantages to doing so; and a general "open source is awful" sort of factor here in the sense that open source users often don't have goals well aligned to our goals.

Turning "arc" into a client platform and building package management solidify us in this direction of being a standalone platform, not a standalone utility library.

Phabricator also depends on `arcanist/`. If it didn't, there would be a small advantage to saying "shared code + client for client, shared code + server for server", but there's no such distinction and it seems unlikely that one will ever exist. Even if it did, I think this has little value.

Nowadays, I think this separation has no advantages for us and one significant cost: it makes installing `arcanist` more difficult for end-users.

This will need some more finesssing (Phabricator will need some changes for compatibility, and a lot of stuff that still says "libphutil" or "phutil" may eventually want to say "arcanist"), and some stuff (like xhpast) is probably straight-up broken right now and needs some tweaking, but I don't anticipate any major issues here. There was never anything particularly magical about libphutil as a separate standalone library.

Test Plan: Ran `arc`, it gets about as far as it did before.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13098

Differential Revision: https://secure.phabricator.com/D19688
2018-09-21 16:38:53 -07:00

140 lines
3.6 KiB
PHP
Executable file

#!/usr/bin/env php
<?php
require_once dirname(__FILE__).'/__init_script__.php';
$target = 'resources/php_compat_info.json';
echo phutil_console_format(
"%s\n",
pht(
'Purpose: Updates %s used by %s.',
$target,
'ArcanistXHPASTLinter'));
// PHP CompatInfo is installed via Composer.
//
// You should symlink the Composer vendor directory to
// libphutil/externals/includes/vendor`.
require_once 'vendor/autoload.php';
$output = array();
$output['@'.'generated'] = true;
$output['params'] = array();
$output['functions'] = array();
$output['classes'] = array();
$output['interfaces'] = array();
$output['constants'] = array();
/**
* Transform compatibility info into a slightly different format.
*
* The data returned by PHP CompatInfo is slightly odd in that null data is
* represented by an empty string.
*
* @param map<string, string>
* @return map<string, string | null>
*/
function parse_compat_info(array $compat) {
return array(
'ext.name' => $compat['ext.name'],
'ext.min' => nonempty($compat['ext.min'], null),
'ext.max' => nonempty($compat['ext.max'], null),
'php.min' => nonempty($compat['php.min'], null),
'php.max' => nonempty($compat['php.max'], null),
);
}
$client = new \Bartlett\Reflect\Client();
$api = $client->api('reference');
foreach ($api->dir() as $extension) {
$result = $api->show(
$extension->name,
false,
false,
false,
true,
true,
true,
true,
true);
foreach ($result['constants'] as $constant => $compat) {
$output['constants'][$constant] = parse_compat_info($compat);
}
foreach ($result['functions'] as $function => $compat) {
$output['functions'][$function] = parse_compat_info($compat);
if (idx($compat, 'parameters')) {
$output['params'][$function] = explode(', ', $compat['parameters']);
}
}
foreach ($result['classes'] as $class => $compat) {
$output['classes'][$class] = parse_compat_info($compat);
}
foreach ($result['interfaces'] as $interface => $compat) {
$output['interfaces'][$interface] = parse_compat_info($compat);
}
foreach ($result['methods'] as $class => $methods) {
$output['methods'][$class] = array();
foreach ($methods as $method => $compat) {
$output['methods'][$class][$method] = parse_compat_info($compat);
}
}
foreach ($result['static methods'] as $class => $methods) {
$output['static_methods'][$class] = array();
foreach ($methods as $method => $compat) {
$output['static_methods'][$class][$method] = parse_compat_info($compat);
}
}
}
ksort($output['params']);
ksort($output['functions']);
ksort($output['classes']);
ksort($output['interfaces']);
ksort($output['constants']);
// Grepped from PHP Manual.
// TODO: Can we get this from PHP CompatInfo?
// See https://github.com/llaville/php-compat-info/issues/185.
$output['functions_windows'] = array(
'apache_child_terminate' => false,
'chroot' => false,
'getrusage' => false,
'imagecreatefromxpm' => false,
'lchgrp' => false,
'lchown' => false,
'nl_langinfo' => false,
'strptime' => false,
'sys_getloadavg' => false,
'checkdnsrr' => '5.3.0',
'dns_get_record' => '5.3.0',
'fnmatch' => '5.3.0',
'getmxrr' => '5.3.0',
'getopt' => '5.3.0',
'imagecolorclosesthwb' => '5.3.0',
'inet_ntop' => '5.3.0',
'inet_pton' => '5.3.0',
'link' => '5.3.0',
'linkinfo' => '5.3.0',
'readlink' => '5.3.0',
'socket_create_pair' => '5.3.0',
'stream_socket_pair' => '5.3.0',
'symlink' => '5.3.0',
'time_nanosleep' => '5.3.0',
'time_sleep_until' => '5.3.0',
);
Filesystem::writeFile(
phutil_get_library_root('phutil').'/../'.$target,
id(new PhutilJSON())->encodeFormatted($output));
echo pht('Done.')."\n";