Exemplo n.º 1
0
 /** 
  * returns a target project file that can make $name
  */
 public function handle($project, $file)
 {
     $deps = $this->dependency($project, $file);
     $recipe = $this->recipe($project, $file);
     $def = new TargetDefinition(array('name' => $file->name(), 'type' => TARGET));
     if (is_array($deps)) {
         foreach ($deps as $dep) {
             $def->add_dependency($dep);
         }
     }
     $def->add_recipe($recipe);
     return ProjectFile::create($project, $def);
 }
Exemplo n.º 2
0
 public function update_file($file)
 {
     $file = $this->handle($file);
     if ($file == NULL) {
         return true;
     }
     if (!$this->mutex->acquire()) {
         return false;
     }
     // let the plugins handle the file, if needed
     $name = $file->name();
     // check if it is a new file not registered in the project
     if (!isset($this->files[$name])) {
         $this->files[$name] = ProjectFile::create($this, $file);
     } else {
         $old = $this->files[$name];
         // check if two files are the same type, if not, delete the old
         if ($old->type() != $file->type()) {
             $this->mutex->release();
             if (!$this->remove_file_without_remake($name, false)) {
                 return false;
             }
             return $this->update_file($file);
         }
         // check if two files are the same
         if ($old->equal($this->project_path, $file)) {
             $this->mutex->release();
             return true;
         }
         // copy to the project
         $old->copy($this->project_path, $file);
     }
     // this file has been changed, project needs to be remade
     $this->modified = true;
     $this->save_project();
     $this->mutex->release();
     $this->remake(array($name));
     return true;
 }
Exemplo n.º 3
0
 private function construct(&$files)
 {
     // the root node
     $this->nodes = array();
     $this->intermediate_files = array();
     $this->errors = array();
     foreach ($files as $name => $file) {
         $this->files[$name] =& $file;
     }
     $this->files = $files;
     $filenames = array_keys($files);
     $no_rules = array();
     foreach ($this->files as $name => $file) {
         if (!$file->makable()) {
             $default = $this->default_rule($file);
             //					wiki_debug("default $name", $default);
             if ($default === NULL) {
                 $this->add_error($name, "undefined");
             } else {
                 $file = $default;
                 $this->files[$name] = $file;
             }
         }
         $this->nodes[$name] = new MakeNode($name, $file->is_target());
     }
     // link nodes reversly with dependency, i.e, if one node changed,
     // which other nodes need to be upated
     while ((list($name, $node) = each($this->nodes)) != false) {
         $deps = $this->files[$name]->dependency();
         if ($deps) {
             foreach ($deps as $dep) {
                 if (!isset($this->nodes[$dep])) {
                     $missing = ProjectFile::create($this->project, new TargetDefinition(array('name' => $dep, 'type' => TARGET)));
                     $default = $this->default_rule($missing);
                     //					wiki_debug("default $dep", $default);
                     if ($default == NULL) {
                         $this->add_error($name, array('dependency' => $dep));
                         continue;
                     }
                     $this->intermediate_files[] = $dep;
                     $this->files[$dep] = $default;
                     $dep_node = new MakeNode($dep, true);
                     $this->nodes[$dep] = $dep_node;
                 } else {
                     $dep_node = $this->nodes[$dep];
                 }
                 $dep_node->link($node);
             }
         }
     }
     foreach ($this->nodes as $node) {
         $node->find_affected($this->errors);
     }
     // find those which are affected by the error nodes
     $errors = array_intersect(array_keys($this->errors), array_keys($this->nodes));
     foreach ($errors as $name) {
         $this->nodes[$name]->mark_invalid($this->errors);
     }
     $invalid = array_keys($this->errors);
     // drop the invalid nodes
     $nodes = array();
     // relink valid nodes
     foreach ($this->nodes as $name => $node) {
         if ($node->valid) {
             $nodes[$name] = new MakeNode($name, $node->is_target());
         }
     }
     foreach ($nodes as $name => $node) {
         $deps = array_diff($this->files[$name]->dependency(), $invalid);
         foreach ($deps as $dep) {
             $nodes[$dep]->link($node);
         }
     }
     $this->nodes = $nodes;
 }