Added support for the targetbasename context function.
<?php
if(!defined("METAL_BUILD_INCLUDED"))
{
define("METAL_BUILD_INCLUDED",1);
/*
* metal_build.php
*
* @(#) $Header: /opt2/mlemos/cvs/metal/metal/metal_build.php,v 1.47 2004/08/22 00:50:55 mlemos Exp $
*
*/
class metal_build_class extends metal_base_class
{
var $targets=array();
var $building_target="";
var $build_trigger="";
var $defaults=array();
var $template_actions=array();
var $build_targets=array();
Function Setup(&$compiler,&$code,&$attributes)
{
$elements=$code->structure[$attributes->path]["Elements"];
for($element=0;$element<$elements;$element++)
{
$element_path=$attributes->path.",$element";
$build_data=$code->structure[$element_path];
if(GetType($build_data)=="array")
{
switch($build_data["Tag"])
{
case "templateaction":
Unset($name);
Unset($template_action);
$action_elements=$code->structure[$element_path]["Elements"];
for($action_element=0;$action_element<$action_elements;$action_element++)
{
$action_element_path=$element_path.",$action_element";
$data=$code->structure[$action_element_path];
if(GetType($data)=="array")
{
switch($data["Tag"])
{
case "name":
if(IsSet($name))
{
$compiler->SetElementError($attributes->file,$action_element_path,"it was specified the build template action name more than once");
return(0);
}
if(!$compiler->GetValidData($attributes->file,$action_element_path,$name,"it was not specified a valid build template action name"))
return(0);
if(IsSet($this->template_actions[$name]))
{
$compiler->SetElementError($attributes->file,$action_element_path,"it was specified the name of an already defined build template action");
return(0);
}
break;
case "action":
if(IsSet($template_action))
{
$compiler->SetElementError($attributes->file,$action_element_path,"it was specified the build template action more than once");
return(0);
}
$compiler->CopyEmptyContext($attributes,$template_action);
$template_action->path=$action_element_path;
break;
default:
$compiler->SetElementError($attributes->file,$action_element_path,$data["Tag"]." is not a supported build object template action attribute");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($attributes->file,$data,$action_element_path))
return(0);
}
}
if(!IsSet($name))
{
$compiler->SetElementError($attributes->file,$attributes->path,"it was not specified the build template action name");
return(0);
}
$compiler->CopyEmptyContext($template_action,$this->template_actions[$name]);
break;
case "target":
case "filestarget":
$target=array("Dependencies"=>array(),"Sources"=>array(),"Arguments"=>array());
Unset($name);
$target_elements=$code->structure[$element_path]["Elements"];
for($target_element=0;$target_element<$target_elements;$target_element++)
{
$target_element_path=$element_path.",$target_element";
$data=$code->structure[$target_element_path];
if(GetType($data)=="array")
{
switch($data["Tag"])
{
case "name":
if(IsSet($name))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the build target name more than once");
return(0);
}
if(!$compiler->GetValidData($attributes->file,$target_element_path,$name,"it was not specified a valid build target name"))
return(0);
if(IsSet($this->targets[$name]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the name of an already defined build target");
return(0);
}
break;
case "dependency":
case "targetdependency":
if(!$compiler->GetValidData($attributes->file,$target_element_path,$dependency,"it was not specified a valid build target dependency"))
return(0);
if(IsSet($targets["Dependencies"][$dependency]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the same build target dependency more than once");
return(0);
}
$compiler->CopyEmptyContext($attributes,$dependency_context);
$dependency_context->path=$target_element_path;
$target["Dependencies"][$dependency]=array(
"Context"=>$dependency_context,
"Target"=>!strcmp($data["Tag"],"targetdependency"),
"FilesTarget"=>0
);
break;
case "source":
$compiler->CopyEmptyContext($attributes,$source_context);
$source_context->path=$target_element_path;
$values=$optional_types=array();
$required_types=array(
"name"=>"DATA",
"file"=>"DATA"
);
if(!$compiler->GetOptionalArgumentValues($source_context,$values,$required_types,$optional_types,"build","Setup",1))
return(0);
if(IsSet($targets["Sources"][$values["name"]]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the same build target source name more than once");
return(0);
}
$include_path=$compiler->GetIncludePath($values["file"]);
if(IsSet($targets["Dependencies"][$include_path.$values["file"]]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the same build target dependency file more than once");
return(0);
}
$compiler->CopyEmptyContext($attributes,$dependency_context);
$dependency_context->path=$target_element_path;
$target["Sources"][$values["name"]]=$values["file"];
$target["Dependencies"][$include_path.$values["file"]]=array(
"Context"=>$dependency_context,
"Target"=>0,
"FilesTarget"=>0
);
break;
case "templateaction":
if(IsSet($target["TemplateAction"]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the build target template action more than once");
return(0);
}
if(!$compiler->GetValidData($attributes->file,$target_element_path,$target["TemplateAction"],"it was not specified a valid build target template action"))
return(0);
if(!IsSet($this->template_actions[$target["TemplateAction"]]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified a build target template action (\"".$target["TemplateAction"]."\") tha was not defined");
return(0);
}
break;
case "action":
if(IsSet($target["Action"]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the build target action more than once");
return(0);
}
$compiler->CopyEmptyContext($attributes,$target["Action"]);
$target["Action"]->path=$target_element_path;
break;
case "templateuptodateaction":
if(IsSet($target["TemplateUptoDateAction"]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the build target template upto date action more than once");
return(0);
}
if(!$compiler->GetValidData($attributes->file,$target_element_path,$target["TemplateUptoDateAction"],"it was not specified a valid build target template upto date action"))
return(0);
if(!IsSet($this->template_actions[$target["TemplateUptoDateAction"]]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified a build target template action (\"".$target["TemplateUptoDateAction"]."\") tha was not defined");
return(0);
}
break;
case "uptodateaction":
if(IsSet($target["UptoDateAction"]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the build target upto date action more than once");
return(0);
}
$compiler->CopyEmptyContext($attributes,$target["UptoDateAction"]);
$target["UptoDateAction"]->path=$target_element_path;
break;
case "argument":
$values=array();
$required_types=array(
"name"=>"DATA"
);
$optional_types=array(
"value"=>"CONTEXT",
"default"=>"CONTEXT"
);
$compiler->CopyEmptyContext($attributes,$argument_attributes);
$argument_attributes->path=$target_element_path;
if(!$compiler->GetOptionalArgumentValues($argument_attributes,$values,$required_types,$optional_types,"build",$build_data["Tag"],1))
return(0);
if(IsSet($target["Arguments"][$values["name"]]))
{
$compiler->SetElementError($attributes->file,$target_element_path,"it was specified the same build target argument name more than once");
return(0);
}
$target["Arguments"][$values["name"]]=array();
if(IsSet($values["value"]))
$compiler->CopyEmptyContext($values["value"],$target["Arguments"][$values["name"]]["value"]);
if(IsSet($values["default"]))
$compiler->CopyEmptyContext($values["default"],$target["Arguments"][$values["name"]]["default"]);
break;
default:
$compiler->SetElementError($attributes->file,$target_element_path,$data["Tag"]." is not a supported build object target attribute");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($attributes->file,$data,$target_element_path))
return(0);
}
}
if(!IsSet($name))
{
$compiler->SetElementError($attributes->file,$attributes->path,"it was not specified the build target name");
return(0);
}
if(!strcmp($build_data["Tag"],"filestarget")
&& file_exists($name))
{
if(!$this->ReadListFile($compiler,$attributes,$name,$files_list))
return(0);
for($dependencies=array(),$file=0;$file<count($files_list);$file++)
{
if(!strcmp($files_list[$file]["Type"],"DEPENDENCY"))
$compiler->CopyEmptyContext($attributes,$dependencies[$files_list[$file]["Name"]]);
}
for($dependency=0,Reset($target["Dependencies"]);$dependency<count($target["Dependencies"]);Next($target["Dependencies"]),$dependency++)
{
$file_name=Key($target["Dependencies"]);
if(!$target["Dependencies"][$file_name]["Target"]
&& !IsSet($dependencies[$file_name])
&& file_exists($file_name))
{
$compiler->SetElementError($attributes->file,$element_path,"it was specified a dependency (\"$file_name\") that is not listed in the generated files target file (\"$name\")");
return(0);
}
}
for($dependency=0,Reset($dependencies);$dependency<count($dependencies);Next($dependencies),$dependency++)
{
$file_name=Key($dependencies);
$target["Dependencies"][$file_name]=array(
"Context"=>$dependencies[$file_name],
"Target"=>0,
"FilesTarget"=>1
);
}
}
$this->targets[$name]=$target;
break;
case "targetlanguage":
case "bindings":
if(!$compiler->GetValidData($attributes->file,$element_path,$this->defaults[$build_data["Tag"]],"it was not specified a valid build object ".$build_data["Tag"]." argument"))
return(0);
break;
default:
$compiler->SetElementError($attributes->file,$element_path,$build_data["Tag"]." is not a supported build object attribute");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($attributes->file,$build_data,$element_path))
return(0);
}
}
return(1);
}
Function ExecuteTargetAction(&$compiler,&$action_context,$target,$build_trigger)
{
$functions=array(
"targetaction",
"targetname",
"targetbasename",
"targetargument",
"source",
"buildtrigger"
);
if(!$compiler->AddContextFunctions($action_context,$this->object_name,$functions,$level))
return(0);
$previous_target=$this->building_target;
$this->building_target=$target;
$previous_build_trigger=$this->build_trigger;
$this->build_trigger=$build_trigger;
$success=$compiler->GetOutputData($action_context->file,$action_context->path,$context->result,"it was not defined a valid build target template action",1);
$this->build_trigger=$previous_build_trigger;
$this->building_target=$previous_target;
return($compiler->RemoveContextFunctions($action_context,$this->object_name,$level) && $success);
}
Function BuildTarget(&$compiler,&$context,$target,&$target_built)
{
$target_built=(file_exists($target) ? filemtime($target) : 0);
$dependency_built=0;
$dependency_name="";
if(IsSet($this->targets[$target]))
{
$build_target_level=count($this->build_targets);
$this->build_targets[$build_target_level]=$target;
if(IsSet($this->targets[$target]["Dependencies"]))
{
$dependencies=$this->targets[$target]["Dependencies"];
for($dependency=0,Reset($dependencies);$dependency<count($dependencies);Next($dependencies),$dependency++)
{
$target_name=Key($dependencies);
if($dependencies[$target_name]["FilesTarget"]
&& !file_exists($target_name)
&& !IsSet($this->targets[$target_name]))
continue;
if(!$this->BuildTarget($compiler,$dependencies[$target_name]["Context"],$target_name,$built))
return(0);
if($dependency_built<$built)
{
$dependency_built=$built;
$dependency_name=$target_name;
}
}
}
}
else
{
if(!file_exists($target))
{
$compiler->SetElementError($context->file,$context->path,"it was not possible to determine how to build target \"$target\"");
return(0);
}
}
if($target_built==0
|| $dependency_built>$target_built)
{
if(IsSet($this->targets[$target]["Action"])
|| IsSet($this->targets[$target]["TemplateAction"]))
{
if(IsSet($this->targets[$target]["TemplateAction"]))
$compiler->CopyEmptyContext($this->template_actions[$this->targets[$target]["TemplateAction"]],$action_context);
else
$compiler->CopyEmptyContext($this->targets[$target]["Action"],$action_context);
if(!$this->ExecuteTargetAction($compiler,$action_context,$target,($target_built==0 ? $target : $dependency_name)))
return(0);
$target_built=(file_exists($target) ? filemtime($target) : time());
}
}
else
{
if(IsSet($this->targets[$target]["UptoDateAction"])
|| IsSet($this->targets[$target]["TemplateUptoDateAction"]))
{
if(IsSet($this->targets[$target]["TemplateUptoDateAction"]))
$action_context=$this->template_actions[$this->targets[$target]["TemplateUptoDateAction"]];
else
$action_context=$this->targets[$target]["UptoDateAction"];
if(!$this->ExecuteTargetAction($compiler,$action_context,$target,$target))
return(0);
}
}
if(IsSet($this->targets[$target]))
Unset($this->build_targets[$build_target_level]);
return(1);
}
Function ReadListFile(&$compiler,&$context,$file,&$files_list)
{
if(!($list_file=fopen($file,"r")))
{
$compiler->SetElementError($context->file,$context->path,"it was not possible to open the list file \"$file\"");
return(0);
}
if(function_exists("set_file_buffer"))
set_file_buffer($list_file,0);
$serialized_list=fread($list_file,filesize($file));
$closed=fclose($list_file);
if(!$serialized_list
|| !$closed)
{
$compiler->SetElementError($context->file,$context->path,"it was not possible to read the list file \"$file\"");
return(0);
}
$files_list=unserialize($serialized_list);
if(GetType($files_list)!="array")
{
$compiler->SetElementError($context->file,$context->path,"it was not specified a valid list file \"$file\"");
return(0);
}
return(1);
}
Function ListGenerated(&$compiler,&$code,&$context,&$files)
{
$elements=$code->structure[$context->path]["Elements"];
for($element=0;$element<$elements;$element++)
{
$element_path=$context->path.",$element";
$data=$code->structure[$element_path];
if(GetType($data)=="array")
{
switch($data["Tag"])
{
case "list":
if(!$compiler->GetValidData($context->file,$element_path,$list,"it was not specified a valid build generated list argument"))
return(0);
if(IsSet($files[$list]))
{
if($files[$list])
{
$compiler->SetElementError($context->file,$element_path,"file \"$list\" was requested to be explicitly removed more then once in build generated list");
return(0);
}
}
else
{
if(file_exists($list))
{
$compiler->CopyEmptyContext($context,$list_context);
$list_context->path=$element_path;
if(!$this->ReadListFile($compiler,$list_context,$list,$files_list))
return(0);
for($file=0;$file<count($files_list);$file++)
{
$name=$files_list[$file]["Name"];
if($files_list[$file]["Type"]=="GENERATED"
&& !IsSet($files[$name]))
{
if(file_exists($name)
&& !unlink($name))
{
$compiler->SetElementError($context->file,$element_path,"it was not possible to remove the file \"$name\" in build generated");
return(0);
}
$files[$name]=0;
}
}
if(!unlink($list))
{
$compiler->SetElementError($context->file,$element_path,"it was not possible to remove the file \"$list\" in build generated");
return(0);
}
}
}
$files[$list]=1;
break;
default:
$compiler->SetElementError($context->file,$element_path,$data["Tag"]." is not a supported build generated argument");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($context->file,$data,$element_path))
return(0);
}
}
return(1);
}
Function Execute(&$compiler,&$code,$function,&$context,&$arguments_code,&$arguments)
{
switch($function)
{
case "build":
if(!$compiler->GetValidData($context->file,$context->path,$target,"it was not specified a valid build target name"))
return(0);
if(!strcmp($target,""))
{
if(count($this->targets)==0)
{
$compiler->SetElementError($context->file,$context->path,"it was not defined any target to build");
return(0);
}
Reset($this->targets);
$target=Key($this->targets);
}
if(!$this->BuildTarget($compiler,$context,$target,$latest_build))
return(0);
break;
case "compile":
$valid_arguments=array(
"output"=>array(
"Argument"=>"Output",
"Required"=>1
),
"input"=>array(
"Argument"=>"Input",
"Required"=>1
),
"bindings"=>array(
"Argument"=>"Bindings",
"Required"=>1
),
"targetlanguage"=>array(
"Argument"=>"TargetLanguage",
"Required"=>1
),
"cachedirectory"=>array(
"Argument"=>"CacheDirectory",
"Required"=>0
),
"cacheparsedfiles"=>array(
"Argument"=>"CacheParsedFiles",
"Required"=>0
),
"insertincludepath"=>array(
"Argument"=>"InsertIncludePath",
"Required"=>0,
"Multiple"=>1
),
"arguments"=>array(
"Required"=>0
)
);
$default_arguments=array(
"bindings"=>$compiler->bindings_file,
"targetlanguage"=>$compiler->language["name"]
);
$compile_arguments=array(
);
$compiler_arguments=array();
$elements=$code->structure[$context->path]["Elements"];
for($element=0;$element<$elements;$element++)
{
$element_path=$context->path.",$element";
$data=$code->structure[$element_path];
if(GetType($data)=="array")
{
if(IsSet($valid_arguments[$data["Tag"]]))
{
if(IsSet($valid_arguments[$data["Tag"]]["Argument"]))
{
$argument_name=$valid_arguments[$data["Tag"]]["Argument"];
if(IsSet($compile_arguments[$argument_name])
&& !IsSet($valid_arguments[$data["Tag"]]["Multiple"]))
{
$compiler->SetElementError($context->file,$element_path,"it was specified the build compile ".$data["Tag"]." argument more than once");
return(0);
}
if(!$compiler->GetValidData($context->file,$element_path,$value,"it was not specified a valid build compile ".$data["Tag"]." argument"))
return(0);
if(IsSet($valid_arguments[$data["Tag"]]["Multiple"]))
$compile_arguments[$argument_name][]=$value;
else
$compile_arguments[$argument_name]=$value;
}
else
{
switch($data["Tag"])
{
case "arguments":
$arguments_elements=$code->structure[$element_path]["Elements"];
for($arguments_element=0;$arguments_element<$arguments_elements;$arguments_element++)
{
$arguments_element_path=$element_path.",$arguments_element";
$arguments_data=$code->structure[$arguments_element_path];
if(GetType($arguments_data)=="array")
{
if(!$compiler->GetValidData($context->file,$arguments_element_path,$argument_value,"it was not specified a valid build compile ".$data["Tag"]." argument value"))
return(0);
if(IsSet($compiler_arguments[$arguments_data["Tag"]]))
{
$compiler->SetElementError($context->file,$arguments_element_path,"it was specified the build compile ".$arguments_data["Tag"]." argument more than once");
return(0);
}
$compiler_arguments[$arguments_data["Tag"]]=$argument_value;
}
else
{
if(!$compiler->CheckWhiteSpace($context->file,$arguments_data,$arguments_element_path))
return(0);
}
}
break;
default:
$compiler->SetElementError($context->file,$element_path,"it was specified the build compile ".$data["Tag"]." argument but it is not yet implemented");
return(0);
}
}
}
else
{
$compiler->SetElementError($context->file,$element_path,$data["Tag"]." is not a supported build compile argument");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($context->file,$data,$element_path))
return(0);
}
}
for($argument=0,Reset($valid_arguments);$argument<count($valid_arguments);Next($valid_arguments),$argument++)
{
$name=Key($valid_arguments);
if($valid_arguments[$name]["Required"]
&& !IsSet($compile_arguments[$valid_arguments[$name]["Argument"]]))
{
if(IsSet($this->defaults[$name]))
$compile_arguments[$valid_arguments[$name]["Argument"]]=$this->defaults[$name];
else
{
if(IsSet($default_arguments[$name]))
$compile_arguments[$valid_arguments[$name]["Argument"]]=$default_arguments[$name];
else
{
$compiler->SetElementError($context->file,$context->path,"it was not specified the build compile $name argument");
return(0);
}
}
}
}
$compiler->CreateClassObject($build_compiler,"metal_compiler_class");
$build_compiler->cache_directory=$compiler->cache_directory;
$build_compiler->cache_parsed_files=$compiler->cache_parsed_files;
$build_compiler->simplified_xml=$compiler->simplified_xml;
$build_compiler->fail_on_non_simplified_xml=$compiler->fail_on_non_simplified_xml;
$build_compiler->include_path=$compiler->include_path;
$build_compiler->arguments=$compiler_arguments;
if(!$build_compiler->Compile($compile_arguments,$context->result))
{
$compiler->SetError($build_compiler->error_file,$build_compiler->error_line,$build_compiler->error_column,$build_compiler->error_byte_index,$build_compiler->error);
return(0);
}
break;
case "listfiles":
Unset($list);
$skip_white_space=1;
$elements=$arguments_code->structure[$arguments->path]["Elements"];
for($element=0;$element<$elements;$element++)
{
$element_path=$arguments->path.",$element";
$data=$arguments_code->structure[$element_path];
if(GetType($data)=="array")
{
switch($data["Tag"])
{
case "list":
if(IsSet($list))
{
$compiler->SetElementError($arguments->file,$element_path,"it was specified the build list files list argument more than once");
return(0);
}
if(!$compiler->GetValidData($arguments->file,$element_path,$list,"it was not specified a valid build list files list argument"))
return(0);
break;
case "skipwhitespace":
if(!$compiler->GetValidData($arguments->file,$element_path,$skip_white_space,"it was not specified a valid build list files skipwhitespace option"))
return(0);
if(strcmp($skip_white_space,"1")
&& strcmp($skip_white_space,"0"))
{
$compiler->SetElementError($arguments->file,$element_path,"it was not specified a valid boolean build list files skipwhitespace option value");
return(0);
}
$skip_white_space=intval($skip_white_space);
break;
default:
$compiler->SetElementError($arguments->file,$element_path,$data["Tag"]." is not a supported build list files argument");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($arguments->file,$data,$element_path))
return(0);
}
}
if(!IsSet($list))
{
$compiler->SetElementError($arguments->file,$element_path,"it was not specified the build list files list argument");
return(0);
}
if(!$compiler->GetOutputData($context->file,$context->path,$result,"invalid build result",$skip_white_space))
return(0);
for($got=$files=array(),$part=0;$part<count($result);$part++)
{
if(!strcmp($result[$part]["Type"],"FILE"))
{
$serialized=serialize($result[$part]["Data"]);
if(!IsSet($got[$serialized]))
{
$files[]=$result[$part]["Data"];
$got[$serialized]=1;
}
}
else
$context->result[]=$result[$part];
}
if(!$compiler->CreateContextOutputDirectory(dirname($list),$context,"it was not possible to create the directory for the files list file \"".dirname($list)."\""))
return(0);
if(($files_file=fopen($list,"w")))
{
if(function_exists("set_file_buffer"))
set_file_buffer($files_file,0);
$written=fwrite($files_file,serialize($files));
$closed=fclose($files_file);
if($written
&& $closed)
$error="";
else
$error="it was not possible to write to the build list files list output file";
}
else
$error="it was not possible to open the build list files list output file";
if(strcmp($error,""))
{
$compiler->SetElementError($context->file,$context->path,$error);
return(0);
}
$context->result[]=array(
"Data"=>array(
"Name"=>$list,
"Type"=>"GENERATED"
),
"Type"=>"FILE"
);
break;
case "mergefiles":
$files=0;
$elements=$code->structure[$context->path]["Elements"];
for($got=array(),$pending_data="",$element=0;$element<$elements;$element++)
{
$element_path=$context->path.",$element";
$data=$code->structure[$element_path];
if(GetType($data)=="array")
{
switch($data["Tag"])
{
case "list":
case "target":
if(!$compiler->GetValidData($context->file,$element_path,$files_filename,"it was not specified a valid build mergefiles list file argument"))
return(0);
if($data["Tag"]=="target")
{
if(!$this->BuildTarget($compiler,$context,$files_filename,$latest_build))
return(0);
$context->result[]=array(
"Data"=>array(
"Name"=>$files_filename,
"Type"=>"GENERATED"
),
"Type"=>"FILE"
);
}
if(!file_exists($files_filename))
{
$compiler->SetElementError($context->file,$element_path,"it was not specified an existing build mergefiles list file \"$files_filename\"");
return(0);
}
$compiler->CopyEmptyContext($context,$list_context);
$list_context->path=$element_path;
if(!$this->ReadListFile($compiler,$list_context,$files_filename,$files_list))
return(0);
for($file=0;$file<count($files_list);$file++,$files++)
{
$serialized=serialize($files_list[$file]);
if(!IsSet($got[$serialized]))
{
if(!file_exists($files_list[$file]["Name"]))
{
$compiler->SetElementError($context->file,$context->path,"it was specified a build mergefiles ".$files_list[$file]["Type"]." file (\"".$files_list[$file]["Name"]."\") in a list file that does exist");
return(0);
}
$context->result[]=array(
"Data"=>$files_list[$file],
"Type"=>"FILE"
);
$got[$serialized]=1;
}
}
$context->result[]=array(
"Data"=>array(
"Name"=>$files_filename,
"Type"=>"DEPENDENCY"
),
"Type"=>"FILE"
);
break;
default:
$compiler->SetElementError($context->file,$element_path,$data["Tag"]." is not a supported build object mergefiles argument");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($context->file,$data,$element_path))
return(0);
}
}
if($files==0)
{
$compiler->SetElementError($context->file,$context->path,"it were not specified any files to mergefiles function");
return(0);
}
break;
case "removegenerated":
$files=array();
if(!$this->ListGenerated($compiler,$code,$context,$files)
|| !$this->ListGenerated($compiler,$arguments_code,$arguments,$files))
return(0);
if(count($files)==0)
{
$compiler->SetElementError($context->file,$context->path,"it was not specified any build generated file to be removed");
return(0);
}
break;
case "echo":
if(!$compiler->GetValidData($context->file,$context->path,$data_text,"it was not specified a valid build echo data argument"))
return(0);
echo $data_text,"\n";
flush();
break;
case "updatefile":
$files=array();
$elements=$code->structure[$context->path]["Elements"];
for($element=0;$element<$elements;$element++)
{
$element_path=$context->path.",$element";
$data=$code->structure[$element_path];
if(GetType($data)=="array")
{
switch($data["Tag"])
{
case "from":
case "to":
if(IsSet($files[$data["Tag"]]))
{
$compiler->SetElementError($context->file,$element_path,"it was specified the build updatefile ".$data["Tag"]."argument more than once");
return(0);
}
if(!$compiler->GetValidData($context->file,$element_path,$files[$data["Tag"]],"it was not specified a valid build ".$data["Tag"]." updatefile argument"))
return(0);
if($data["Tag"]=="from"
&& !file_exists($files["from"]))
{
$compiler->SetElementError($context->file,$element_path,"it was not specified an existing build updatefile from file (\"".$files["from"]."\")");
return(0);
}
break;
default:
$compiler->SetElementError($context->file,$element_path,$data["Tag"]." is not a supported build updatefile argument");
return(0);
}
}
else
{
if(!$compiler->CheckWhiteSpace($context->file,$data,$element_path))
return(0);
}
}
if(!IsSet($files[$argument="from"])
|| !IsSet($files[$argument="to"]))
{
$compiler->SetElementError($context->file,$context->path,"it was not specified the build updatefile $argument argument");
return(0);
}
if(!file_exists($files["to"])
|| filemtime($files["to"])<filemtime($files["from"]))
{
if(!file_exists($files["to"])
&& !$compiler->CreateContextOutputDirectory(dirname($files["to"]),$context,"it was not possible to create the updatefile destination directory \"".dirname($files["to"])."\""))
return(0);
if(!copy($files["from"],$files["to"]))
{
$compiler->SetElementError($context->file,$context->path,"it was not possible to updatefile the file \"".$files["to"]."\" from \"".$files["from"]."\"");
return(0);
}
}
$context->result[]=array(
"Data"=>array(
"Name"=>$files["to"],
"Type"=>"GENERATED"
),
"Type"=>"FILE"
);
$context->result[]=array(
"Data"=>array(
"Name"=>$files["from"],
"Type"=>"DEPENDENCY"
),
"Type"=>"FILE"
);
break;
case "targetaction":
if(!strcmp($this->building_target,""))
{
$compiler->SetElementError($context->file,$context->path,"it is not defined any target");
return(0);
}
if(!IsSet($this->targets[$this->building_target]["Action"]))
{
$compiler->SetElementError($context->file,$context->path,"it was not defined an action for this target (\"".$this->building_target."\")");
return(0);
}
$compiler->CopyEmptyContext($this->targets[$this->building_target]["Action"],$action_context);
return($compiler->GetOutputData($action_context->file,$action_context->path,$context->result,"it was not defined a valid build target action",1));
case "targetname":
case "targetbasename":
if(!strcmp($this->building_target,""))
{
$compiler->SetElementError($context->file,$context->path,"it is not defined any target");
return(0);
}
$context->result[]=array(
"Data"=>(strcmp($function,"targetname") ? basename($this->building_target) : $this->building_target),
"Type"=>"DATA"
);
return(1);
case "targetargument":
if(!strcmp($this->building_target,""))
{
$compiler->SetElementError($context->file,$context->path,"it is not defined any target");
return(0);
}
if(!$compiler->GetValidData($context->file,$context->path,$argument,"it was not specified a valid build target argument name"))
return(0);
for($build_target_level=count($this->build_targets);;)
{
if($build_target_level==0)
{
$compiler->SetElementError($context->file,$context->path,"it was specified the build argument \"$argument\" that is not defined for the target \"".$this->building_target."\"");
return(0);
}
$build_target_level--;
$target=$this->build_targets[$build_target_level];
if(IsSet($this->targets[$target]["Arguments"][$argument]))
break;
}
$error="it was not specified a valid build target argument value";
if(IsSet($this->targets[$target]["Arguments"][$argument]["value"]))
{
$file=$this->targets[$target]["Arguments"][$argument]["value"]->file;
$path=$this->targets[$target]["Arguments"][$argument]["value"]->path;
}
elseif(IsSet($this->targets[$target]["Arguments"][$argument]["default"]))
{
$file=$this->targets[$target]["Arguments"][$argument]["default"]->file;
$path=$this->targets[$target]["Arguments"][$argument]["default"]->path;
}
else
{
$compiler->SetElementError($context->file,$context->path,$error);
return(0);
}
if(!$compiler->GetValidData($file,$path,$argument_value,$error))
return(0);
$context->result[]=array(
"Data"=>$argument_value,
"Type"=>"DATA"
);
return(1);
case "buildtrigger":
if(!strcmp($this->building_target,""))
{
$compiler->SetElementError($context->file,$context->path,"it is not defined any target");
return(0);
}
$context->result[]=array(
"Data"=>$this->build_trigger,
"Type"=>"DATA"
);
return(1);
case "source":
if(!strcmp($this->building_target,""))
{
$compiler->SetElementError($context->file,$context->path,"it is not defined any target");
return(0);
}
if(!$compiler->GetValidData($context->file,$context->path,$source,"it was not specified a valid build source name argument"))
return(0);
if(!IsSet($this->targets[$this->building_target]["Sources"][$source]))
{
$compiler->SetElementError($context->file,$context->path,"it was specified a build source name (\"$source\") for target \"".$this->building_target."\" that was not defined");
return(0);
}
$context->result[]=array(
"Data"=>$this->targets[$this->building_target]["Sources"][$source],
"Type"=>"DATA"
);
return(1);
default:
$compiler->SetElementError($context->file,$context->path,$function." is not a supported build object function");
return(0);
}
return(1);
}
};
}
?>