1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-24 21:48:21 +01:00
phorge-phorge/src/applications/harbormaster/engine/HarbormasterBuildGraph.php
James Rhodes cad41ea294 Implement build simulation; convert Harbormaster to be purely dependency based
Summary:
Depends on D9806.  This implements the build simulator, which is used to calculate the order of build steps in the plan editor.  This includes a migration script to convert existing plans from sequential based to dependency based, and then drops the sequence column.

Because build plans are now dependency based, the grippable and re-order behaviour has been removed.

Test Plan: Tested the migration, saw the dependencies appear correctly.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9847
2014-07-31 11:39:49 +10:00

60 lines
1.3 KiB
PHP

<?php
/**
* Directed graph representing a build plan
*/
final class HarbormasterBuildGraph extends AbstractDirectedGraph {
private $stepMap;
public static function determineDependencyExecution(
HarbormasterBuildPlan $plan) {
$steps = id(new HarbormasterBuildStepQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withBuildPlanPHIDs(array($plan->getPHID()))
->execute();
$steps_by_phid = mpull($steps, null, 'getPHID');
$step_phids = mpull($steps, 'getPHID');
if (count($steps) === 0) {
return array();
}
$graph = id(new HarbormasterBuildGraph($steps_by_phid))
->addNodes($step_phids);
$raw_results =
$graph->getBestEffortTopographicallySortedNodes();
$results = array();
foreach ($raw_results as $node) {
$results[] = array(
'node' => $steps_by_phid[$node['node']],
'depth' => $node['depth'],
'cycle' => $node['cycle']);
}
return $results;
}
public function __construct($step_map) {
$this->stepMap = $step_map;
}
protected function loadEdges(array $nodes) {
$map = array();
foreach ($nodes as $node) {
$deps = $this->stepMap[$node]->getDetail('dependsOn', array());
$map[$node] = array();
foreach ($deps as $dep) {
$map[$node][] = $dep;
}
}
return $map;
}
}