mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 15:05:54 +00:00
Factories for Backend creation
svn path=/branches/xmlbuildsystem/; revision=12845
This commit is contained in:
parent
8051633a4c
commit
477157b4d4
11 changed files with 176 additions and 46 deletions
|
@ -4,6 +4,35 @@
|
|||
#include "../Rbuild.h"
|
||||
#include "backend.h"
|
||||
|
||||
#include "mingw/mingw.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
vector<Backend::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 )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 @@ string FixSep ( const string& s )
|
|||
#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 @@ MingwBackend::MingwBackend ( Project& project )
|
|||
{
|
||||
}
|
||||
|
||||
void MingwBackend::Process ()
|
||||
void
|
||||
MingwBackend::Process ()
|
||||
{
|
||||
CreateMakefile ();
|
||||
GenerateHeader ();
|
||||
|
@ -54,25 +63,29 @@ void MingwBackend::Process ()
|
|||
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 @@ void MingwBackend::GenerateAllTarget ()
|
|||
fprintf ( fMakefile, "\n\n" );
|
||||
}
|
||||
|
||||
void MingwBackend::ProcessModule ( Module& module )
|
||||
void
|
||||
MingwBackend::ProcessModule ( Module& module )
|
||||
{
|
||||
MingwModuleHandlerList moduleHandlers;
|
||||
GetModuleHandlers ( moduleHandlers );
|
||||
|
@ -101,7 +115,8 @@ void MingwBackend::ProcessModule ( Module& module )
|
|||
}
|
||||
}
|
||||
|
||||
void MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers )
|
||||
void
|
||||
MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers )
|
||||
{
|
||||
moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) );
|
||||
}
|
||||
|
|
|
@ -20,7 +20,10 @@ public:
|
|||
class MingwBackend : public Backend
|
||||
{
|
||||
public:
|
||||
static Backend* Factory ( Project& project );
|
||||
protected:
|
||||
MingwBackend ( Project& project );
|
||||
public:
|
||||
virtual void Process ();
|
||||
private:
|
||||
void ProcessModule ( Module& module );
|
||||
|
|
|
@ -12,15 +12,17 @@ MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile )
|
|||
{
|
||||
}
|
||||
|
||||
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 @@ MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile )
|
|||
{
|
||||
}
|
||||
|
||||
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 (),
|
||||
|
|
|
@ -61,7 +61,7 @@ InvalidBuildFileException::InvalidBuildFileException()
|
|||
}
|
||||
|
||||
|
||||
XMLSyntaxErrorException::XMLSyntaxErrorException ( const std::string& location,
|
||||
XMLSyntaxErrorException::XMLSyntaxErrorException ( const string& location,
|
||||
const char* message,
|
||||
... )
|
||||
{
|
||||
|
@ -72,19 +72,30 @@ XMLSyntaxErrorException::XMLSyntaxErrorException ( const std::string& location,
|
|||
}
|
||||
|
||||
|
||||
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() )
|
||||
{
|
||||
}
|
||||
|
|
|
@ -67,4 +67,18 @@ public:
|
|||
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 */
|
||||
|
|
|
@ -27,8 +27,9 @@ Module::~Module ()
|
|||
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 @@ void Module::ProcessXML ( const XMLElement& e,
|
|||
ProcessXML ( *e.subElements[i], subpath );
|
||||
}
|
||||
|
||||
ModuleType Module::GetModuleType ( const XMLAttribute& attribute )
|
||||
ModuleType
|
||||
Module::GetModuleType ( const XMLAttribute& attribute )
|
||||
{
|
||||
if ( attribute.value == "buildtool" )
|
||||
return BuildTool;
|
||||
|
|
|
@ -25,7 +25,8 @@ Project::~Project ()
|
|||
delete head;
|
||||
}
|
||||
|
||||
void Project::ReadXml ()
|
||||
void
|
||||
Project::ReadXml ()
|
||||
{
|
||||
Path path;
|
||||
|
||||
|
|
|
@ -17,11 +17,19 @@ using std::vector;
|
|||
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;
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ typedef struct {
|
|||
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 @@ std::string ssprintf ( const char* fmt, ... )
|
|||
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 @@ std::wstring sswprintf ( const wchar_t* fmt, ... )
|
|||
#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 @@ static int skip_atoi(const char **s)
|
|||
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 skip_wtoi(const wchar_t **s)
|
|||
}
|
||||
|
||||
|
||||
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 int do_div(LONGLONG *n,int base)
|
|||
}
|
||||
|
||||
|
||||
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 @@ static bool number(std::string& f, LONGLONG num, int base, int size, int precisi
|
|||
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 wnumber(std::wstring& f, LONGLONG num, int base, int size, int preci
|
|||
}
|
||||
|
||||
|
||||
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 @@ static bool numberf(std::string& f, double __n, char exp_sign, int size, int pr
|
|||
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 @@ static bool wnumberf(std::wstring& f, double __n, wchar_t exp_sign, int size, i
|
|||
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 @@ static bool numberfl(std::string& f, long double __n, char exp_sign, int size,
|
|||
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 @@ static bool wnumberfl(std::wstring& f, long double __n, wchar_t exp_sign, int s
|
|||
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 @@ static int do_string(std::string& f, const char* s, int len, int field_width, in
|
|||
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 @@ static int do_wstring(std::wstring& f, const wchar_t* s, int len, int field_widt
|
|||
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 @@ static int stringw(std::string& f, const wchar_t* sw, int len, int field_width,
|
|||
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 @@ static int wstringa(std::wstring& f, const char* sa, int len, int field_width, i
|
|||
#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 @@ std::string ssvprintf ( const char *fmt, va_list args )
|
|||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue