'help' => 'Drop the symbol cache and rebuild the entire map from '.
'scratch.',
),
+ array(
+ 'name' => 'limit',
+ 'param' => 'N',
+ 'default' => 8,
+ 'help' => 'Controls the number of symbol mapper subprocesses run '.
+ 'at once. Defaults to 8.',
+ ),
array(
'name' => 'root',
'wildcard' => true,
$builder = new PhutilLibraryMapBuilder($root);
$builder->setQuiet($args->getArg('quiet'));
+$builder->setSubprocessLimit($args->getArg('limit'));
if ($args->getArg('drop-cache')) {
$builder->dropSymbolCache();
private $root;
private $quiet;
+ private $subprocessLimit = 8;
const LIBRARY_MAP_VERSION_KEY = '__library_version__';
const LIBRARY_MAP_VERSION = 2;
* Control status output. Use --quiet to set this.
*
* @param bool If true, don't show status output.
- * @return this
+ * @return this
*
* @task map
*/
}
+ /**
+ * Control subprocess parallelism limit. Use --limit to set this.
+ *
+ * @param int Maximum number of subprocesses to run in parallel.
+ * @return this
+ *
+ * @task map
+ */
+ public function setSubprocessLimit($limit) {
+ $this->subprocessLimit = $limit;
+ return $this;
+ }
+
+
/**
* Build or rebuild the library map.
*
// Run the analyzer on any files which need analysis.
if ($futures) {
- $this->log("Analyzing ".number_format(count($futures))." files");
- foreach (Futures($futures)->limit(8) as $file => $future) {
+ $limit = $this->subprocessLimit;
+ $count = number_format(count($futures));
+
+ $this->log("Analyzing {$count} files with {$limit} subprocesses...\n");
+
+ foreach (Futures($futures)->limit($limit) as $file => $future) {
$this->log(".");
$symbol_map[$file] = $future->resolveJSON();
}
* @task source
*/
private function buildLibraryMap(array $symbol_map) {
- $library_map = array();
+ $library_map = array(
+ 'class' => array(),
+ 'function' => array(),
+ 'xmap' => array(),
+ );
// Detect duplicate symbols within the library.
foreach ($symbol_map as $file => $info) {
$library_map[$lib_type][$symbol] = $file;
}
}
+ $library_map['xmap'] += $info['xmap'];
+ }
+
+ // Simplify the common case (one parent) to make the file a little easier
+ // to deal with.
+ foreach ($library_map['xmap'] as $class => $extends) {
+ if (count($extends) == 1) {
+ $library_map['xmap'][$class] = reset($extends);
+ }
}
// Sort the map so it is relatively stable across changes.
- foreach ($library_map as $lib_type => $symbols) {
+ foreach ($library_map as $key => $symbols) {
ksort($symbols);
- $library_map[$lib_type] = $symbols;
+ $library_map[$key] = $symbols;
}
ksort($library_map);
$have = array(); // For symbols we declare.
$need = array(); // For symbols we use.
+$xmap = array(); // For extended classes and implemented interfaces.
// -( Functions )-------------------------------------------------------------
// This is "class X ... { ... }".
$classes = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
foreach ($classes as $class) {
- $class_name = $class->getChildByIndex(1);
+ $class_name = $class->getChildByIndex(1)->getConcreteString();
$extends = $class->getChildByIndex(2);
foreach ($extends->selectDescendantsOfType('n_CLASS_NAME') as $parent) {
$need[] = array(
'type' => 'class',
'symbol' => $parent,
);
+
+ // Track all 'extends' in the extension map.
+ $xmap[$class_name][] = $parent->getConcreteString();
}
}
// This is "class X ... { ... }".
$classes = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
foreach ($classes as $class) {
+ $class_name = $class->getChildByIndex(1)->getConcreteString();
$implements = $class->getChildByIndex(3);
$interfaces = $implements->selectDescendantsOfType('n_CLASS_NAME');
foreach ($interfaces as $interface) {
'type' => 'interface',
'symbol' => $interface,
);
+
+ // Track 'class ... implements' in the extension map.
+ $xmap[$class_name][] = $interface->getConcreteString();
}
}
// This is "interface X ... { ... }".
$interfaces = $root->selectDescendantsOfType('n_INTERFACE_DECLARATION');
foreach ($interfaces as $interface) {
- $interface_name = $interface->getChildByIndex(1);
+ $interface_name = $interface->getChildByIndex(1)->getConcreteString();
$extends = $interface->getChildByIndex(2);
foreach ($extends->selectDescendantsOfType('n_CLASS_NAME') as $parent) {
'type' => 'interface',
'symbol' => $parent,
);
+
+ // Track 'interface ... implements' in the extension map.
+ $xmap[$interface_name][] = $parent->getConcreteString();
}
}
$result = array(
'have' => $declared_symbols,
'need' => $required_symbols,
+ 'xmap' => $xmap,
);