File: rebuild-map.php

package info (click to toggle)
phabricator 0~git20220903-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 76,220 kB
  • sloc: php: 589,219; javascript: 27,980; sql: 19,466; ansic: 3,624; yacc: 2,506; sh: 696; xml: 503; lex: 488; python: 403; cpp: 224; makefile: 150; sed: 66
file content (73 lines) | stat: -rwxr-xr-x 1,789 bytes parent folder | download
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
#!/usr/bin/env php
<?php

$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/support/init/init-script.php';

$args = new PhutilArgumentParser($argv);
$args->setTagline(pht('rebuild the library map file'));
$args->setSynopsis(<<<EOHELP
    **rebuild-map.php** [__options__] __root__
        Rebuild the library map file for a libphutil library.

EOHELP
);

$args->parseStandardArguments();
$args->parse(
  array(
    array(
      'name'      => 'drop-cache',
      'help'      => pht(
        'Drop the symbol cache and rebuild the entire map from scratch.'),
    ),
    array(
      'name'      => 'limit',
      'param'     => 'N',
      'default'   => 8,
      'help'      => pht(
        'Controls the number of symbol mapper subprocesses run at once. '.
        'Defaults to 8.'),
    ),
    array(
      'name'      => 'show',
      'help'      => pht(
        'Print symbol map to stdout instead of writing it to the map file.'),
    ),
    array(
      'name'      => 'ugly',
      'help'      => pht(
        'Use faster but less readable serialization for "--show".'),
    ),
    array(
      'name'      => 'root',
      'wildcard'  => true,
    ),
  ));

$root = $args->getArg('root');
if (count($root) !== 1) {
  throw new Exception(pht('Provide exactly one library root!'));
}
$root = Filesystem::resolvePath(head($root));

$builder = new PhutilLibraryMapBuilder($root);
$builder->setSubprocessLimit($args->getArg('limit'));

if ($args->getArg('drop-cache')) {
  $builder->dropSymbolCache();
}

if ($args->getArg('show')) {
  $library_map = $builder->buildMap();

  if ($args->getArg('ugly')) {
    echo json_encode($library_map);
  } else {
    echo id(new PhutilJSON())->encodeFormatted($library_map);
  }
} else {
  $builder->buildAndWriteMap();
}

exit(0);