File: update_compat_info.php

package info (click to toggle)
phabricator 0~git20190207-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 71,728 kB
  • sloc: php: 552,244; sql: 16,997; ansic: 3,619; yacc: 2,503; sh: 754; xml: 519; lex: 488; cpp: 221; python: 186; makefile: 177; sed: 66
file content (140 lines) | stat: -rwxr-xr-x 3,736 bytes parent folder | download | duplicates (2)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/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";