Compare commits

..

No commits in common. "master" and "v2.8.0" have entirely different histories.

3 changed files with 23 additions and 76 deletions

View File

@ -4,27 +4,20 @@ use Exception;
class TaskmanArtefact class TaskmanArtefact
{ {
private \taskman\TaskmanTask $task;
private string $path; private string $path;
private array $sources_fn = array(); private array $sources_fn = array();
private array $sources_spec = array(); private array $sources_spec = array();
private iterable $sources = array(); private iterable $sources = array();
private array $sources_changed = array(); private array $sources_changed = array();
private array $sources_changed_fn = 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->path = $path;
$this->sources_spec = $sources_spec; $this->sources_spec = $sources_spec;
} }
function getTask() : \taskman\TaskmanTask
{
return $this->task;
}
function getPath() : string function getPath() : string
{ {
return $this->path; return $this->path;
@ -43,7 +36,6 @@ class TaskmanArtefact
if(isset($this->sources_fn[$idx])) if(isset($this->sources_fn[$idx]))
{ {
$fn = $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(); $sources = $fn();
$this->sources[$idx] = $sources; $this->sources[$idx] = $sources;
return $sources; return $sources;
@ -70,7 +62,6 @@ class TaskmanArtefact
if(isset($this->sources_changed_fn[$idx])) if(isset($this->sources_changed_fn[$idx]))
{ {
$fn = $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(); $changed = $fn();
$this->sources_changed[$idx] = $changed; $this->sources_changed[$idx] = $changed;
return $changed; return $changed;
@ -79,31 +70,23 @@ class TaskmanArtefact
return array(); return array();
} }
//obsolete
function isSourcesNewer(int $idx) : bool 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]; return array_keys($this->sources_newer);
}
function getAffectedSourcesIndices() : array
{
return array_keys($this->sources_affected);
} }
function isStale() : bool 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(); $all_src_specs = $this->getSourcesSpec();
//let's process a convenience special case //let's process a convenience special case
if(count($all_src_specs) > 0 && !is_array($all_src_specs[0])) 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) foreach($this->getSourcesSpec() as $src_idx => $src_spec)
{ {
$sources = $file_changes != null ? $this->getChangedSources($src_idx) : $this->getSources($src_idx); $sources = $file_changes != null ? $this->getChangedSources($src_idx) : $this->getSources($src_idx);
if(is_stale($this->getPath(), $sources)) if(is_stale($this->getPath(), $sources))
{ {
$this->sources_affected[$src_idx] = true; $this->sources_newer[$src_idx] = true;
return true; return true;
} }
} }

View File

@ -202,14 +202,6 @@ function _process_argv(array &$argv)
{ {
$TASKMAN_LOG_LEVEL = -1; $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') else if($v == '-O')
{ {
$TASKMAN_NO_DEPS = true; $TASKMAN_NO_DEPS = true;

View File

@ -130,7 +130,7 @@ class TaskmanTask
if(is_array($specs)) if(is_array($specs))
{ {
foreach($specs as $dst => $src_spec) foreach($specs as $dst => $src_spec)
$artefacts[] = new artefact\TaskmanArtefact($this, $dst, $src_spec); $artefacts[] = new artefact\TaskmanArtefact($dst, $src_spec);
} }
return $artefacts; return $artefacts;
@ -266,18 +266,20 @@ class TaskmanTask
private function _checkIfArtefactsStale() : bool private function _checkIfArtefactsStale() : bool
{ {
$file_changes = $this->getFileChanges();
$stale_found = false; $stale_found = false;
foreach($this->getArtefacts() as $artefact) 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; $stale_found = true;
if($artefact->isStale()) 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(); $changed = array();
$base_dir = dirname($_SERVER['PHP_SELF']); $base_dir = dirname($_SERVER['PHP_SELF']);
//for debug
//var_dump($decoded);
foreach($decoded as $items) foreach($decoded as $items)
{ {
@ -347,11 +347,7 @@ class TaskmanFileChanges
if($status == 'Changed') if($status == 'Changed')
$changed[$file] = self::Changed; $changed[$file] = self::Changed;
else if($status == 'Created') else if($status == 'Created')
{ $changed[$file] = self::Created;
//let's status for files which were modified and then created
if(isset($changed[$file]) && $changed[$file] !== self::Changed)
$changed[$file] = self::Created;
}
else if($status == 'Renamed') else if($status == 'Renamed')
$changed[$file] = self::Renamed; $changed[$file] = self::Renamed;
else if($status == 'Deleted') else if($status == 'Deleted')
@ -369,31 +365,6 @@ class TaskmanFileChanges
$this->changed = $changed; $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 function isEmpty() : bool
{ {
return count($this->changed) == 0; return count($this->changed) == 0;
@ -503,11 +474,14 @@ function main(
$tasks = $hints; $tasks = $hints;
else else
{ {
$similars = ''; printf("ERROR! Task %s not found\n", $tasks[0]);
if($hints) if($hints)
$similars .= "\nSimilar tasks: " . implode(', ', $hints) . "."; {
printf("Similar tasks:\n");
throw new Exception("Task '{$tasks[0]}' not found. $similars"); foreach($hints as $hint)
printf(" %s\n", $hint);
}
exit(1);
} }
} }