Compare commits
No commits in common. "master" and "v2.8.1" have entirely different histories.
|
@ -4,27 +4,20 @@ use Exception;
|
|||
|
||||
class TaskmanArtefact
|
||||
{
|
||||
private \taskman\TaskmanTask $task;
|
||||
private string $path;
|
||||
private array $sources_fn = array();
|
||||
private array $sources_spec = array();
|
||||
private iterable $sources = array();
|
||||
private array $sources_changed = array();
|
||||
private array $sources_changed_fn = array();
|
||||
private array $sources_affected = array();
|
||||
private array $sources_newer = array();
|
||||
|
||||
function __construct(\taskman\TaskmanTask $task, string $path, array $sources_spec)
|
||||
function __construct(string $path, array $sources_spec)
|
||||
{
|
||||
$this->task = $task;
|
||||
$this->path = $path;
|
||||
$this->sources_spec = $sources_spec;
|
||||
}
|
||||
|
||||
function getTask() : \taskman\TaskmanTask
|
||||
{
|
||||
return $this->task;
|
||||
}
|
||||
|
||||
function getPath() : string
|
||||
{
|
||||
return $this->path;
|
||||
|
@ -43,7 +36,6 @@ class TaskmanArtefact
|
|||
if(isset($this->sources_fn[$idx]))
|
||||
{
|
||||
$fn = $this->sources_fn[$idx];
|
||||
\taskman\log(2, "Task '{$this->task->getName()}' artefact '{$this->path}' resolving sources at $idx\n");
|
||||
$sources = $fn();
|
||||
$this->sources[$idx] = $sources;
|
||||
return $sources;
|
||||
|
@ -70,7 +62,6 @@ class TaskmanArtefact
|
|||
if(isset($this->sources_changed_fn[$idx]))
|
||||
{
|
||||
$fn = $this->sources_changed_fn[$idx];
|
||||
\taskman\log(2, "Task '{$this->task->getName()}' artefact '{$this->path}' resolving changed sources at $idx\n");
|
||||
$changed = $fn();
|
||||
$this->sources_changed[$idx] = $changed;
|
||||
return $changed;
|
||||
|
@ -79,31 +70,23 @@ class TaskmanArtefact
|
|||
return array();
|
||||
}
|
||||
|
||||
//obsolete
|
||||
function isSourcesNewer(int $idx) : bool
|
||||
{
|
||||
return $this->isSourcesAffected($idx);
|
||||
return isset($this->sources_newer[$idx]) && $this->sources_newer[$idx];
|
||||
}
|
||||
|
||||
function isSourcesAffected(int $idx) : bool
|
||||
function getNewerSourcesIndices() : array
|
||||
{
|
||||
return isset($this->sources_affected[$idx]) && $this->sources_affected[$idx];
|
||||
}
|
||||
|
||||
function getAffectedSourcesIndices() : array
|
||||
{
|
||||
return array_keys($this->sources_affected);
|
||||
return array_keys($this->sources_newer);
|
||||
}
|
||||
|
||||
function isStale() : bool
|
||||
{
|
||||
return count($this->sources_affected) > 0;
|
||||
return count($this->sources_newer) > 0;
|
||||
}
|
||||
|
||||
function initSources()
|
||||
function initSources(?\taskman\TaskmanFileChanges $file_changes)
|
||||
{
|
||||
$file_changes = $this->task->getFileChanges();
|
||||
|
||||
$all_src_specs = $this->getSourcesSpec();
|
||||
//let's process a convenience special case
|
||||
if(count($all_src_specs) > 0 && !is_array($all_src_specs[0]))
|
||||
|
@ -151,16 +134,14 @@ class TaskmanArtefact
|
|||
}
|
||||
}
|
||||
|
||||
function checkAffectedSources() : bool
|
||||
function checkNewerSources(?\taskman\TaskmanFileChanges $file_changes) : bool
|
||||
{
|
||||
$file_changes = $this->task->getFileChanges();
|
||||
|
||||
foreach($this->getSourcesSpec() as $src_idx => $src_spec)
|
||||
{
|
||||
$sources = $file_changes != null ? $this->getChangedSources($src_idx) : $this->getSources($src_idx);
|
||||
if(is_stale($this->getPath(), $sources))
|
||||
{
|
||||
$this->sources_affected[$src_idx] = true;
|
||||
$this->sources_newer[$src_idx] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,14 +202,6 @@ function _process_argv(array &$argv)
|
|||
{
|
||||
$TASKMAN_LOG_LEVEL = -1;
|
||||
}
|
||||
else if($v == '-l')
|
||||
{
|
||||
if(!isset($argv[$i+1]))
|
||||
throw new \taskman\TaskmanException("Log level is missing");
|
||||
|
||||
$TASKMAN_LOG_LEVEL = intval($argv[$i+1]);
|
||||
++$i;
|
||||
}
|
||||
else if($v == '-O')
|
||||
{
|
||||
$TASKMAN_NO_DEPS = true;
|
||||
|
|
|
@ -130,7 +130,7 @@ class TaskmanTask
|
|||
if(is_array($specs))
|
||||
{
|
||||
foreach($specs as $dst => $src_spec)
|
||||
$artefacts[] = new artefact\TaskmanArtefact($this, $dst, $src_spec);
|
||||
$artefacts[] = new artefact\TaskmanArtefact($dst, $src_spec);
|
||||
}
|
||||
|
||||
return $artefacts;
|
||||
|
@ -266,18 +266,20 @@ class TaskmanTask
|
|||
|
||||
private function _checkIfArtefactsStale() : bool
|
||||
{
|
||||
$file_changes = $this->getFileChanges();
|
||||
|
||||
$stale_found = false;
|
||||
|
||||
foreach($this->getArtefacts() as $artefact)
|
||||
{
|
||||
$artefact->initSources();
|
||||
$artefact->initSources($file_changes);
|
||||
|
||||
if(!$stale_found && $artefact->checkAffectedSources())
|
||||
if(!$stale_found && $artefact->checkNewerSources($file_changes))
|
||||
$stale_found = true;
|
||||
|
||||
if($artefact->isStale())
|
||||
{
|
||||
log(0, "Task '{$this->name}' artefact '{$artefact->getPath()}' (sources at ".implode(',', $artefact->getAffectedSourcesIndices()).") is stale\n");
|
||||
log(0, "Task '{$this->name}' artefact '{$artefact->getPath()}' (sources at ".implode(',', $artefact->getNewerSourcesIndices()).") is stale\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,8 +324,6 @@ class TaskmanFileChanges
|
|||
$changed = array();
|
||||
|
||||
$base_dir = dirname($_SERVER['PHP_SELF']);
|
||||
//for debug
|
||||
//var_dump($decoded);
|
||||
|
||||
foreach($decoded as $items)
|
||||
{
|
||||
|
@ -347,11 +347,7 @@ class TaskmanFileChanges
|
|||
if($status == 'Changed')
|
||||
$changed[$file] = self::Changed;
|
||||
else if($status == 'Created')
|
||||
{
|
||||
//let's status for files which were modified and then created
|
||||
if(isset($changed[$file]) && $changed[$file] !== self::Changed)
|
||||
$changed[$file] = self::Created;
|
||||
}
|
||||
$changed[$file] = self::Created;
|
||||
else if($status == 'Renamed')
|
||||
$changed[$file] = self::Renamed;
|
||||
else if($status == 'Deleted')
|
||||
|
@ -369,31 +365,6 @@ class TaskmanFileChanges
|
|||
$this->changed = $changed;
|
||||
}
|
||||
|
||||
function getStatus(string $file) : ?int
|
||||
{
|
||||
return isset($this->changed[$file]) ? $this->changed[$file] : null;
|
||||
}
|
||||
|
||||
function isChanged(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Changed;
|
||||
}
|
||||
|
||||
function isCreated(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Created;
|
||||
}
|
||||
|
||||
function isDeleted(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Deleted;
|
||||
}
|
||||
|
||||
function isRenamed(string $file) : bool
|
||||
{
|
||||
return $this->getStatus($file) == self::Renamed;
|
||||
}
|
||||
|
||||
function isEmpty() : bool
|
||||
{
|
||||
return count($this->changed) == 0;
|
||||
|
|
Loading…
Reference in New Issue