/**
  * Rebuild the resource map for a resource source.
  *
  * @param CelerityPhysicalResources Resource source to rebuild.
  * @return void
  */
 private function rebuildResources(CelerityPhysicalResources $resources)
 {
     $this->log(pht('Rebuilding resource source "%s" (%s)...', $resources->getName(), get_class($resources)));
     $binary_map = $this->rebuildBinaryResources($resources);
     $this->log(pht('Found %d binary resources.', new PhutilNumber(count($binary_map))));
     $xformer = id(new CelerityResourceTransformer())->setMinify(false)->setRawURIMap(ipull($binary_map, 'uri'));
     $text_map = $this->rebuildTextResources($resources, $xformer);
     $this->log(pht('Found %d text resources.', new PhutilNumber(count($text_map))));
     $resource_graph = array();
     $requires_map = array();
     $symbol_map = array();
     foreach ($text_map as $name => $info) {
         if (isset($info['provides'])) {
             $symbol_map[$info['provides']] = $info['hash'];
             // We only need to check for cycles and add this to the requires map
             // if it actually requires anything.
             if (!empty($info['requires'])) {
                 $resource_graph[$info['provides']] = $info['requires'];
                 $requires_map[$info['hash']] = $info['requires'];
             }
         }
     }
     $this->detectGraphCycles($resource_graph);
     $name_map = ipull($binary_map, 'hash') + ipull($text_map, 'hash');
     $hash_map = array_flip($name_map);
     $package_map = $this->rebuildPackages($resources, $symbol_map, $hash_map);
     $this->log(pht('Found %d packages.', new PhutilNumber(count($package_map))));
     $component_map = array();
     foreach ($package_map as $package_name => $package_info) {
         foreach ($package_info['symbols'] as $symbol) {
             $component_map[$symbol] = $package_name;
         }
     }
     $name_map = $this->mergeNameMaps(array(array(pht('Binary'), ipull($binary_map, 'hash')), array(pht('Text'), ipull($text_map, 'hash')), array(pht('Package'), ipull($package_map, 'hash'))));
     $package_map = ipull($package_map, 'symbols');
     ksort($name_map);
     ksort($symbol_map);
     ksort($requires_map);
     ksort($package_map);
     $map_content = $this->formatMapContent(array('names' => $name_map, 'symbols' => $symbol_map, 'requires' => $requires_map, 'packages' => $package_map));
     $map_path = $resources->getPathToMap();
     $this->log(pht('Writing map "%s".', Filesystem::readablePath($map_path)));
     Filesystem::writeFile($map_path, $map_content);
 }
 /**
  * Rebuild the resource map for a resource source.
  *
  * @param CelerityPhysicalResources Resource source to rebuild.
  * @return void
  */
 private function rebuildResources(CelerityPhysicalResources $resources)
 {
     $this->log(pht('Rebuilding resource source "%s" (%s)...', $resources->getName(), get_class($resources)));
     id(new CelerityResourceMapGenerator($resources))->setDebug(true)->generate()->write();
 }