public function is_needed() { if (!file_exists($this->get_name())) { return true; } $latest_prereq = 0; foreach ($this->prerequisites as $prerequisite) { $t = pakeTask::get($prerequisite)->timestamp(); if ($t > $latest_prereq) { $latest_prereq = $t; } } if ($latest_prereq == 0) { return false; } return $this->timestamp() < $latest_prereq; }
public function run($pakefile = null, $options = null, $load_pakefile = true) { if ($pakefile) { pakeApp::$PAKEFILES = array($pakefile); } $this->handle_options($options); if ($load_pakefile) { $this->load_pakefile(); } if ($this->show_tasks) { $this->display_tasks_and_comments(); } else { if ($this->show_prereqs) { $this->display_prerequisites(); } else { $args = $this->opt->get_arguments(); $task = array_shift($args); $options = array(); for ($i = 0, $max = count($args); $i < $max; $i++) { if (0 === strpos($args[$i], '--')) { if (false !== ($pos = strpos($args[$i], '='))) { $key = substr($args[$i], 2, $pos - 2); $value = substr($args[$i], $pos + 1); } else { $key = substr($args[$i], 2); $value = true; } if ('[]' == substr($key, -2)) { if (!isset($options[$key])) { $options[$key] = array(); } $options[$key][] = $value; } else { $options[$key] = $value; } unset($args[$i]); } } $args = array_values($args); $abbrev_options = $this->abbrev(array_keys(pakeTask::get_tasks())); $task = pakeTask::get_full_task_name($task); if (!$task) { $task = 'default'; } if (!array_key_exists($task, $abbrev_options)) { throw new pakeException(sprintf('Task "%s" is not defined.', $task)); } else { if (count($abbrev_options[$task]) > 1) { throw new pakeException(sprintf('Task "%s" is ambiguous (%s).', $task, implode(', ', $abbrev_options[$task]))); } else { return pakeTask::get($abbrev_options[$task][0])->invoke($args, $options); } } } } }
public function timestamp() { $max = 0; foreach ($this->prerequisites as $prerequisite) { $t = pakeTask::get($prerequisite)->timestamp(); if ($t > $max) { $max = $t; } } return $max ? $max : time(); }
protected function initAndRunTask($task_name, $args, $options) { // generating abbreviations $abbreviated_tasks = pakeTask::get_abbreviated_tasknames(); // does requested task correspond to full or abbreviated name? if (!array_key_exists($task_name, $abbreviated_tasks)) { throw new pakeException('Task "' . $task_name . '" is not defined.'); } if (count($abbreviated_tasks[$task_name]) > 1) { throw new pakeException('Task "' . $task_name . '" is ambiguous (' . implode(', ', $abbreviated_tasks[$task_name]) . ').'); } // init and run task $task = pakeTask::get($abbreviated_tasks[$task_name][0]); return $task->invoke($args, $options); }
/** * Builds dependent extensions * * @todo add locking support */ static function run_build_dependencies($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts(@$args[0], @$args[1], $cliopts); $current = $opts['extension']['name']; foreach ($opts['dependencies']['extensions'] as $ext => $source) { // avoid loops if ($ext != $current) { // create a temporary config file to drive the init task // this could be done better in memory... foreach ($source as $type => $def) { break; } $tempconf = array('extension' => array('name' => $ext), 'version' => array('major' => 0, 'minor' => 0, 'release' => 0), $type => $def); $tempconffile = self::getOptionsDir() . "/options-tmp_{$ext}.yaml"; pakeYaml::emitfile($tempconf, $tempconffile); // download remote extension // nb: we can not run the init task here via invoke() because of already_invoked status, // so we use execute(). NB: this is fine as long as init has no prerequisites $task = pakeTask::get('init'); $task->execute(array("tmp_{$ext}"), array_merge($cliopts, array('skip-init' => false, 'skip-init-fetch' => false, 'skip-init-clean' => true))); // copy config file from ext dir to current config dir if (is_file(self::getBuildDir($opts) . "/{$ext}/pake/options-{$ext}.yaml")) { pake_copy(self::getBuildDir($opts) . "/{$ext}/pake/options-{$ext}.yaml", self::getOptionsDir() . "/options-{$ext}.yaml"); } else { throw new pakeException("Missing pake/options.yaml extension in dependent extension {$ext}"); } // finish the init-task $task->execute(array("tmp_{$ext}"), array_merge($cliopts, array('skip-init' => false, 'skip-init-fetch' => true, 'skip-init-clean' => false))); pake_remove($tempconffile, ''); // and build it. Here again we cannot use 'invoke', but we know 'build' has prerequisites // so we execute them one by one $task = pakeTask::get('build'); foreach ($task->get_prerequisites() as $pretask) { $pretask = pakeTask::get($pretask); $pretask->execute(array($ext), array_merge($opts, array('skip-init' => true))); } $task->execute(array($ext), array_merge($opts, array('skip-init' => true))); } } }
protected function initAndRunTask($task_name, $args, $options) { $task_name = pakeTask::taskname_from_abbreviation($task_name); return pakeTask::get($task_name)->invoke($args, $options); }
public function run($pakefile = null, $options = null, $load_pakefile = true) { if ($pakefile) { pakeApp::$PAKEFILES = array($pakefile); } $this->handle_options($options); if ($load_pakefile) { $this->load_pakefile(); } if ($this->show_tasks) { $this->display_tasks_and_comments(); } else { if ($this->show_prereqs) { $this->display_prerequisites(); } else { $args = $this->opt->get_arguments(); $task = array_shift($args); $abbrev_options = $this->abbrev(array_keys(pakeTask::get_tasks())); $task = pakeTask::get_full_task_name($task); if (!$task) { $task = 'default'; } if (!array_key_exists($task, $abbrev_options)) { throw new pakeException(sprintf('Task "%s" is not defined.', $task)); } else { if (count($abbrev_options[$task]) > 1) { throw new pakeException(sprintf('Task "%s" is ambiguous (%s).', $task, implode(', ', $abbrev_options[$task]))); } else { return pakeTask::get($abbrev_options[$task][0])->invoke($args); } } } } }