From 9d77e4fff41f0e7fcdb918b686c5079693e3709a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Mon, 6 Aug 2007 09:19:25 +0000 Subject: [PATCH] Add -D option to add variables in generated file svn path=/trunk/; revision=28188 --- reactos/tools/rbuild/module.cpp | 14 +++++++++++--- reactos/tools/rbuild/project.cpp | 18 +++++++++++++++++- reactos/tools/rbuild/rbuild.cpp | 28 +++++++++++++++++++++++++++- reactos/tools/rbuild/rbuild.h | 9 +++++++-- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/reactos/tools/rbuild/module.cpp b/reactos/tools/rbuild/module.cpp index f6e6341c268..e35cfd3a631 100644 --- a/reactos/tools/rbuild/module.cpp +++ b/reactos/tools/rbuild/module.cpp @@ -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() { diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index d68d4ac5eb6..5b961ffc960 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -103,13 +103,29 @@ FileLocation::FileLocation ( Directory* directory, Project::Project ( const Configuration& configuration, - const string& filename ) + const string& filename, + const std::map* properties ) : xmlfile (filename), node (NULL), head (NULL), configuration (configuration) { _backend = NULL; + + if ( properties ) + { + std::map::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(); } diff --git a/reactos/tools/rbuild/rbuild.cpp b/reactos/tools/rbuild/rbuild.cpp index abe255ff038..cc84f40d1ff 100644 --- a/reactos/tools/rbuild/rbuild.cpp +++ b/reactos/tools/rbuild/rbuild.cpp @@ -35,6 +35,7 @@ using std::vector; static string BuildSystem; static string RootXmlFile; static Configuration configuration; +static std::map 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 ( 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 ( diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index 5476dab2715..d84969a553c 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -215,7 +215,8 @@ public: IfableData non_if_data; Project ( const Configuration& configuration, - const std::string& filename ); + const std::string& filename, + const std::map* 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(); };