Add -D option to add variables in generated file

svn path=/trunk/; revision=28188
This commit is contained in:
Hervé Poussineau 2007-08-06 09:19:25 +00:00
parent 5a8a0a1af7
commit 9d77e4fff4
4 changed files with 62 additions and 7 deletions

View file

@ -1509,19 +1509,27 @@ If::ProcessXML()
Property::Property ( const XMLElement& node_,
const Project& project_,
const Module* module_ )
: node(node_), project(project_), module(module_)
: project(project_), module(module_)
{
const XMLAttribute* att;
att = node.GetAttribute ( "name", true );
att = node_.GetAttribute ( "name", true );
assert(att);
name = att->value;
att = node.GetAttribute ( "value", true );
att = node_.GetAttribute ( "value", true );
assert(att);
value = att->value;
}
Property::Property ( const Project& project_,
const Module* module_,
const std::string& name_,
const std::string& value_ )
: project(project_), module(module_), name(name_), value(value_)
{
}
void
Property::ProcessXML()
{

View file

@ -103,13 +103,29 @@ FileLocation::FileLocation ( Directory* directory,
Project::Project ( const Configuration& configuration,
const string& filename )
const string& filename,
const std::map<std::string, std::string>* properties )
: xmlfile (filename),
node (NULL),
head (NULL),
configuration (configuration)
{
_backend = NULL;
if ( properties )
{
std::map<string, string>::const_iterator it;
for (it = properties->begin (); it != properties->end (); it++)
{
const Property *existing = LookupProperty( it->first );
if ( !existing )
{
Property* property = new Property ( *this, NULL, it->first, it->second );
non_if_data.properties.push_back (property );
}
}
}
ReadXml();
}

View file

@ -35,6 +35,7 @@ using std::vector;
static string BuildSystem;
static string RootXmlFile;
static Configuration configuration;
static std::map<string, string> properties;
bool
ParseAutomaticDependencySwitch (
@ -167,6 +168,28 @@ ParseProxyMakefileSwitch ( char switchChar2 )
return true;
}
bool
ParseDefineSwitch ( char* switchStart )
{
string s = string ( switchStart + 2 );
string::size_type separator = s.find ( '=' );
if ( separator == string::npos || separator == 0 )
{
printf ( "Invalid define switch: '%s'\n", switchStart );
return false;
}
if ( s.find ( '=', separator + 1 ) != string::npos )
{
printf ( "Invalid define switch: '%s'\n", switchStart );
return false;
}
string var = s.substr ( 0, separator );
string val = s.substr ( separator + 1 );
properties.insert ( std::pair<string, string> ( var, val ) );
return true;
}
bool
ParseSwitch ( int argc, char** argv, int index )
{
@ -202,6 +225,8 @@ ParseSwitch ( int argc, char** argv, int index )
return ParseMakeSwitch ( switchChar2 );
case 'p':
return ParseProxyMakefileSwitch ( switchChar2 );
case 'D':
return ParseDefineSwitch ( argv[index] );
default:
printf (
"Unknown switch -%c\n",
@ -253,6 +278,7 @@ main ( int argc, char** argv )
printf ( " tree.\n" );
printf ( " -vs{version} Version of MS VS project files. Default is %s.\n", MS_VS_DEF_VERSION );
printf ( " -vo{version|configuration} Adds subdirectory path to the default Intermediate-Outputdirectory.\n" );
printf ( " -Dvar=val Set the value of 'var' variable to 'val'.\n" );
printf ( "\n" );
printf ( " buildsystem Target build system. Can be one of:\n" );
@ -272,7 +298,7 @@ main ( int argc, char** argv )
string projectFilename ( RootXmlFile );
printf ( "Reading build files..." );
Project project ( configuration, projectFilename );
Project project ( configuration, projectFilename, &properties );
printf ( "done\n" );
project.SetBackend ( Backend::Factory::Create (

View file

@ -215,7 +215,8 @@ public:
IfableData non_if_data;
Project ( const Configuration& configuration,
const std::string& filename );
const std::string& filename,
const std::map<std::string, std::string>* properties = NULL );
~Project ();
void SetBackend ( Backend* backend ) { _backend = backend; }
Backend& GetBackend() { return *_backend; }
@ -590,7 +591,6 @@ public:
class Property
{
public:
const XMLElement& node;
const Project& project;
const Module* module;
std::string name, value;
@ -599,6 +599,11 @@ public:
const Project& project_,
const Module* module_ );
Property ( const Project& project_,
const Module* module_,
const std::string& name_,
const std::string& value_ );
void ProcessXML();
};