Factories for Backend creation Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/ssprintf.cpp _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -4,6 +4,35 @@
#include "../Rbuild.h" #include "backend.h"
+#include "mingw/mingw.h" + +using std::string; +using std::vector; + +vectorBackend::Factory* Backend::factories; + +/*static*/ void +Backend::InitFactories() +{ + factories.push_back ( new Factory ( "mingw", MingwBackend::Factory ) ); +} + +/*static*/ Backend* +Backend::Create ( const std::string& name, Project& project ) +{ + string sname ( name ); + strlwr ( &sname[0] ); + if ( !factories.size() ) + throw Exception ( "internal tool error: no registered factories" ); + for ( size_t i = 0; i < factories.size(); i++ ) + { + if ( sname == factories[i]->name ) + return (factories[i]->factory) ( project ); + } + throw UnknownBackendException ( sname ); + return NULL; +} + Backend::Backend ( Project& project ) : ProjectNode ( project ) { _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h 2005-01-06 02:55:11 UTC (rev 12845) @@ -3,11 +3,36 @@
#include "../rbuild.h"
+class Backend; + +typedef Backend* BackendFactory ( Project& project ); + class Backend { + class Factory + { + public: + std::string name; + BackendFactory* factory; + + Factory ( const std::string& name_, BackendFactory* factory_ ) + : name(name_), factory(factory_) + { + } + }; + + static std::vector<Factory*> factories; + public: + static void InitFactories(); + static Backend* Create ( const std::string& name, Project& project ); + +protected: Backend ( Project& project ); + +public: virtual void Process () = 0; + protected: Project& ProjectNode; }; _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -6,10 +6,17 @@
using std::string; using std::vector;
+Backend* +MingwBackend::Factory ( Project& project ) +{ + return new MingwBackend ( project ); +} + #ifdef WIN32 #define EXEPOSTFIX ".exe" #define SEP "\" -string FixSep ( const string& s ) +string +FixSep ( const string& s ) { string s2(s); char* p = strchr ( &s2[0], '/' ); @@ -23,7 +30,8 @@ #else #define EXEPOSTFIX #define SEP "/" -string FixSep ( const string& s ) +string +FixSep ( const string& s ) { string s2(s); char* p = strchr ( &s2[0], '\' ); @@ -41,7 +49,8 @@ { }
-void MingwBackend::Process () +void +MingwBackend::Process () { CreateMakefile (); GenerateHeader (); @@ -54,25 +63,29 @@ CloseMakefile (); }
-void MingwBackend::CreateMakefile () +void +MingwBackend::CreateMakefile () { fMakefile = fopen ( ProjectNode.makefile.c_str (), "w" ); if ( !fMakefile ) throw AccessDeniedException ( ProjectNode.makefile ); }
-void MingwBackend::CloseMakefile () +void +MingwBackend::CloseMakefile () { if (fMakefile) fclose ( fMakefile ); }
-void MingwBackend::GenerateHeader () +void +MingwBackend::GenerateHeader () { fprintf ( fMakefile, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" ); }
-void MingwBackend::GenerateAllTarget () +void +MingwBackend::GenerateAllTarget () { fprintf ( fMakefile, "all: " ); for ( size_t i = 0; i < ProjectNode.modules.size (); i++ ) @@ -86,7 +99,8 @@ fprintf ( fMakefile, "\n\n" ); }
-void MingwBackend::ProcessModule ( Module& module ) +void +MingwBackend::ProcessModule ( Module& module ) { MingwModuleHandlerList moduleHandlers; GetModuleHandlers ( moduleHandlers ); @@ -101,7 +115,8 @@ } }
-void MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) +void +MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) { moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) ); } _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-01-06 02:55:11 UTC (rev 12845) @@ -20,7 +20,10 @@
class MingwBackend : public Backend { public: + static Backend* Factory ( Project& project ); +protected: MingwBackend ( Project& project ); +public: virtual void Process (); private: void ProcessModule ( Module& module ); _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -12,15 +12,17 @@
{ }
-string MingwModuleHandler::GetModuleDependencies ( Module& module ) +string +MingwModuleHandler::GetModuleDependencies ( Module& module ) { - string dependencies ( "" ); - - for ( size_t i = 0; i < module.libraries.size(); i++ ) + if ( !module.libraries.size() ) + return ""; + + string dependencies ( module.libraries[0]->name ); + + for ( size_t i = 1; i < module.libraries.size(); i++ ) { - if (dependencies.size () > 0) - dependencies += " "; - dependencies += module.libraries[i]->name; + dependencies += " " + module.libraries[i]->name; } return dependencies; } @@ -31,17 +33,20 @@ { }
-bool MingwKernelModuleHandler::CanHandleModule ( Module& module ) +bool +MingwKernelModuleHandler::CanHandleModule ( Module& module ) { return true; }
-void MingwKernelModuleHandler::Process ( Module& module ) +void +MingwKernelModuleHandler::Process ( Module& module ) { GenerateKernelModuleTarget ( module ); }
-void MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module ) +void +MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module ) { fprintf ( fMakefile, "%s: %s", module.name.c_str (), _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -61,7 +61,7 @@
}
-XMLSyntaxErrorException::XMLSyntaxErrorException ( const std::string& location, +XMLSyntaxErrorException::XMLSyntaxErrorException ( const string& location, const char* message, ... ) { @@ -72,19 +72,30 @@ }
-RequiredAttributeNotFoundException::RequiredAttributeNotFoundException( const std::string& attributeName, - const std::string& elementName) +RequiredAttributeNotFoundException::RequiredAttributeNotFoundException( const string& attributeName, + const string& elementName) : InvalidBuildFileException ( "Required attribute '%s' not found on '%s'.", attributeName.c_str (), elementName.c_str ()) { }
-InvalidAttributeValueException::InvalidAttributeValueException(const std::string& name, - const std::string& value) +InvalidAttributeValueException::InvalidAttributeValueException(const string& name, + const string& value) : InvalidBuildFileException ( "Attribute '%s' has an invalid value '%s'.", name.c_str (), value.c_str ()) { } + +BackendNameConflictException::BackendNameConflictException ( const string& name ) + : Exception ( "Backend name conflict: '%s'", name.c_str() ) +{ +} + + +UnknownBackendException::UnknownBackendException ( const string& name ) + : Exception ( "Unknown Backend requested: '%s'", name.c_str() ) +{ +} _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h --- branches/xmlbuildsystem/reactos/tools/rbuild/exception.h 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.h 2005-01-06 02:55:11 UTC (rev 12845) @@ -67,4 +67,18 @@
const std::string& value); };
+ +class BackendNameConflictException : public Exception +{ +public: + BackendNameConflictException ( const std::string& name ); +}; + + +class UnknownBackendException : public Exception +{ +public: + UnknownBackendException ( const std::string& name ); +}; + #endif /* __EXCEPTION_H */ _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -27,8 +27,9 @@
delete libraries[i]; }
-void Module::ProcessXML ( const XMLElement& e, - const string& path ) +void +Module::ProcessXML ( const XMLElement& e, + const string& path ) { string subpath ( path ); if ( e.name == "file" && e.value.size () ) @@ -49,7 +50,8 @@ ProcessXML ( *e.subElements[i], subpath ); }
-ModuleType Module::GetModuleType ( const XMLAttribute& attribute ) +ModuleType +Module::GetModuleType ( const XMLAttribute& attribute ) { if ( attribute.value == "buildtool" ) return BuildTool; _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -25,7 +25,8 @@
delete head; }
-void Project::ReadXml () +void +Project::ReadXml () { Path path;
_____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -17,11 +17,19 @@
int main ( int argc, char** argv ) { + Backend::InitFactories(); + if ( argc != 2 ) + { + printf ( "syntax: rbuild {buildtarget}\n" ); + return 1; + } + string buildtarget ( argv[1] ); + strlwr ( &buildtarget[0] ); try { string projectFilename ( "ReactOS.xml" ); Project project ( projectFilename ); - Backend* backend = new MingwBackend ( project ); + Backend* backend = Backend::Create ( buildtarget, project ); backend->Process (); delete backend; _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/ssprintf.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/ssprintf.cpp 2005-01-06 02:06:44 UTC (rev 12844) +++ branches/xmlbuildsystem/reactos/tools/rbuild/ssprintf.cpp 2005-01-06 02:55:11 UTC (rev 12845) @@ -34,7 +34,8 @@
unsigned int empty:16; } ieee_long_double_t;
-std::string ssprintf ( const char* fmt, ... ) +std::string +ssprintf ( const char* fmt, ... ) { va_list arg; va_start(arg, fmt); @@ -43,7 +44,8 @@ return f; }
-std::wstring sswprintf ( const wchar_t* fmt, ... ) +std::wstring +sswprintf ( const wchar_t* fmt, ... ) { va_list arg; va_start(arg, fmt); @@ -62,7 +64,8 @@ #define ZEROTRUNC 128 /* truncate zero 's */
-static int skip_atoi(const char **s) +static int +skip_atoi(const char **s) { int i=0;
@@ -71,7 +74,8 @@ return i; }
-static int skip_wtoi(const wchar_t **s) +static int +skip_wtoi(const wchar_t **s) { int i=0;
@@ -81,7 +85,8 @@ }
-static int do_div(LONGLONG *n,int base) +static int +do_div(LONGLONG *n,int base) { int __res = ((ULONGLONG) *n) % (unsigned) base; *n = ((ULONGLONG) *n) / (unsigned) base; @@ -89,7 +94,8 @@ }
-static bool number(std::string& f, LONGLONG num, int base, int size, int precision ,int type) +static bool +number(std::string& f, LONGLONG num, int base, int size, int precision ,int type) { char c,sign,tmp[66]; const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; @@ -165,7 +171,8 @@ return true; }
-static bool wnumber(std::wstring& f, LONGLONG num, int base, int size, int precision ,int type) +static bool +wnumber(std::wstring& f, LONGLONG num, int base, int size, int precision ,int type) { wchar_t c,sign,tmp[66]; const wchar_t *digits = L"0123456789abcdefghijklmnopqrstuvwxyz"; @@ -242,7 +249,8 @@ }
-static bool numberf(std::string& f, double __n, char exp_sign, int size, int precision, int type) +static bool +numberf(std::string& f, double __n, char exp_sign, int size, int precision, int type) { double exponent = 0.0; double e; @@ -435,7 +443,8 @@ return true; }
-static bool wnumberf(std::wstring& f, double __n, wchar_t exp_sign, int size, int precision, int type) +static bool +wnumberf(std::wstring& f, double __n, wchar_t exp_sign, int size, int precision, int type) { double exponent = 0.0; double e; @@ -628,7 +637,8 @@ return true; }
-static bool numberfl(std::string& f, long double __n, char exp_sign, int size, int precision, int type) +static bool +numberfl(std::string& f, long double __n, char exp_sign, int size, int precision, int type) { long double exponent = 0.0; long double e; @@ -834,7 +844,8 @@ return true; }
-static bool wnumberfl(std::wstring& f, long double __n, wchar_t exp_sign, int size, int precision, int type) +static bool +wnumberfl(std::wstring& f, long double __n, wchar_t exp_sign, int size, int precision, int type) { long double exponent = 0.0; long double e; @@ -1035,7 +1046,8 @@ return true; }
-static int do_string(std::string& f, const char* s, int len, int field_width, int precision, int flags) +static int +do_string(std::string& f, const char* s, int len, int field_width, int precision, int flags) { int i, done = 0; if (s == NULL) @@ -1076,7 +1088,8 @@ return done; }
-static int do_wstring(std::wstring& f, const wchar_t* s, int len, int field_width, int precision, int flags) +static int +do_wstring(std::wstring& f, const wchar_t* s, int len, int field_width, int precision, int flags) { int i, done = 0; if (s == NULL) @@ -1117,7 +1130,8 @@ return done; }
-static int stringw(std::string& f, const wchar_t* sw, int len, int field_width, int precision, int flags) +static int +stringw(std::string& f, const wchar_t* sw, int len, int field_width, int precision, int flags) { int i, done = 0; if (sw == NULL) @@ -1169,7 +1183,8 @@ return done; }
-static int wstringa(std::wstring& f, const char* sa, int len, int field_width, int precision, int flags) +static int +wstringa(std::wstring& f, const char* sa, int len, int field_width, int precision, int flags) { int i, done = 0; if (sa == NULL) @@ -1219,7 +1234,8 @@ #define _isnanl _isnan #define _finitel _finite
-std::string ssvprintf ( const char *fmt, va_list args ) +std::string +ssvprintf ( const char *fmt, va_list args ) { ULONGLONG num; int base; @@ -1569,7 +1585,8 @@ return f; }
-std::wstring sswvprintf ( const wchar_t* fmt, va_list args ) +std::wstring +sswvprintf ( const wchar_t* fmt, va_list args ) { ULONGLONG num; int base;