mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
Add cycle detection to celerity mapper
Summary: create CelerityResourceGraph, which extends AbstractDirectedGraph. since we've done a bunch of work already to load the resource graph into memory CelerityResourceGraph simply stores a copy and makes loadEdges work off that stored copy. Test Plan: made phabricator-prefab require herald-rule-editor ~/code/phabricator> ./scripts/celerity_mapper.php webroot Finding static resources... Processing 154 files.......................................................................................................................................................... [2011-11-22 11:28:29] EXCEPTION: (Exception) Cycle detected in resource graph: phabricator-prefab => herald-rule-editor => phabricator-prefab at [/Users/btrahan/Dropbox/code/phabricator/scripts/celerity_mapper.php:173] fixed phabricator-prefab requiring herald-rule-editor. re-ran celerity_mapper and no errors! Reviewers: epriestley Reviewed By: epriestley CC: aran, btrahan, epriestley Differential Revision: 1132
This commit is contained in:
parent
ec8dbfd05f
commit
0795cd4baa
4 changed files with 79 additions and 1 deletions
|
@ -130,7 +130,7 @@ foreach ($files as $path => $hash) {
|
|||
echo "\n";
|
||||
|
||||
$runtime_map = array();
|
||||
|
||||
$resource_graph = array();
|
||||
$hash_map = array();
|
||||
|
||||
$parser = new PhutilDocblockParser();
|
||||
|
@ -168,6 +168,8 @@ foreach ($file_map as $path => $info) {
|
|||
|
||||
$hash_map[$provides] = $info['hash'];
|
||||
|
||||
$resource_graph[$provides] = $requires;
|
||||
|
||||
$runtime_map[$provides] = array(
|
||||
'uri' => $uri,
|
||||
'type' => $type,
|
||||
|
@ -176,6 +178,20 @@ foreach ($file_map as $path => $info) {
|
|||
);
|
||||
}
|
||||
|
||||
$celerity_resource_graph = new CelerityResourceGraph();
|
||||
$celerity_resource_graph->addNodes($resource_graph);
|
||||
$celerity_resource_graph->setResourceGraph($resource_graph);
|
||||
$celerity_resource_graph->loadGraph();
|
||||
|
||||
foreach ($resource_graph as $provides => $requires) {
|
||||
$cycle = $celerity_resource_graph->detectCycles($provides);
|
||||
if ($cycle) {
|
||||
throw new Exception(
|
||||
"Cycle detected in resource graph: ". implode($cycle, " => ")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$package_map = array();
|
||||
foreach ($package_spec as $name => $package) {
|
||||
$hashes = array();
|
||||
|
|
|
@ -83,6 +83,7 @@ phutil_register_library_map(array(
|
|||
'AphrontWriteGuard' => 'aphront/writeguard',
|
||||
'CelerityAPI' => 'infrastructure/celerity/api',
|
||||
'CelerityResourceController' => 'infrastructure/celerity/controller',
|
||||
'CelerityResourceGraph' => 'infrastructure/celerity/graph',
|
||||
'CelerityResourceMap' => 'infrastructure/celerity/map',
|
||||
'CelerityStaticResourceResponse' => 'infrastructure/celerity/response',
|
||||
'ConduitAPIMethod' => 'applications/conduit/method/base',
|
||||
|
@ -813,6 +814,7 @@ phutil_register_library_map(array(
|
|||
'AphrontTypeaheadTemplateView' => 'AphrontView',
|
||||
'AphrontWebpageResponse' => 'AphrontResponse',
|
||||
'CelerityResourceController' => 'AphrontController',
|
||||
'CelerityResourceGraph' => 'AbstractDirectedGraph',
|
||||
'ConduitAPI_arcanist_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_arcanist_projectinfo_Method' => 'ConduitAPI_arcanist_Method',
|
||||
'ConduitAPI_conduit_connect_Method' => 'ConduitAPIMethod',
|
||||
|
|
47
src/infrastructure/celerity/graph/CelerityResourceGraph.php
Normal file
47
src/infrastructure/celerity/graph/CelerityResourceGraph.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class CelerityResourceGraph extends AbstractDirectedGraph {
|
||||
|
||||
private $resourceGraph = array();
|
||||
private $graphSet = false;
|
||||
|
||||
protected function loadEdges(array $nodes) {
|
||||
if (!$this->graphSet) {
|
||||
throw new Exception(
|
||||
"Call setResourceGraph before loading the graph!"
|
||||
);
|
||||
}
|
||||
|
||||
$graph = $this->getResourceGraph();
|
||||
$edges = array();
|
||||
foreach ($nodes as $node) {
|
||||
$edges[$node] = idx($graph, $node, array());
|
||||
}
|
||||
return $edges;
|
||||
}
|
||||
|
||||
final public function setResourceGraph(array $graph) {
|
||||
$this->resourceGraph = $graph;
|
||||
$this->graphSet = true;
|
||||
}
|
||||
|
||||
private function getResourceGraph() {
|
||||
return $this->resourceGraph;
|
||||
}
|
||||
}
|
13
src/infrastructure/celerity/graph/__init__.php
Normal file
13
src/infrastructure/celerity/graph/__init__.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
phutil_require_module('phutil', 'utils/abstractgraph');
|
||||
|
||||
|
||||
phutil_require_source('CelerityResourceGraph.php');
|
Loading…
Reference in a new issue