mirror of
https://github.com/reactos/reactos.git
synced 2025-07-28 14:52:35 +00:00
add 'location' information to a couple exceptions that should have it
fixed bug I introduced in MingwBackend::ProcessModule() fixed bug in std::map usage, apparently map<const char*,...> is a bad idea let make do some work, create variables to hold include list for each module svn path=/branches/xmlbuildsystem/; revision=12901
This commit is contained in:
parent
10324ce772
commit
03e6c98e63
11 changed files with 82 additions and 50 deletions
|
@ -422,7 +422,8 @@ XMLElement::GetAttribute ( const string& attribute,
|
|||
}
|
||||
if ( required )
|
||||
{
|
||||
throw RequiredAttributeNotFoundException ( attribute,
|
||||
throw RequiredAttributeNotFoundException ( location,
|
||||
attribute,
|
||||
name );
|
||||
}
|
||||
return NULL;
|
||||
|
@ -441,7 +442,8 @@ XMLElement::GetAttribute ( const string& attribute,
|
|||
}
|
||||
if ( required )
|
||||
{
|
||||
throw RequiredAttributeNotFoundException ( attribute,
|
||||
throw RequiredAttributeNotFoundException ( location,
|
||||
attribute,
|
||||
name );
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -8,25 +8,26 @@ using std::string;
|
|||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
map<const char*,Backend::Factory*>* Backend::Factory::factories = NULL;
|
||||
map<string,Backend::Factory*>* Backend::Factory::factories = NULL;
|
||||
|
||||
Backend::Factory::Factory ( const std::string& name_ )
|
||||
{
|
||||
string name(name_);
|
||||
strlwr ( &name[0] );
|
||||
if ( !factories )
|
||||
factories = new map<const char*,Factory*>;
|
||||
(*factories)[name.c_str()] = this;
|
||||
factories = new map<string,Factory*>;
|
||||
(*factories)[name] = this;
|
||||
}
|
||||
|
||||
/*static*/ Backend*
|
||||
Backend::Factory::Create ( const std::string& name, Project& project )
|
||||
Backend::Factory::Create ( const string& name,
|
||||
Project& project )
|
||||
{
|
||||
string sname ( name );
|
||||
strlwr ( &sname[0] );
|
||||
if ( !factories || !factories->size() )
|
||||
throw Exception ( "internal tool error: no registered factories" );
|
||||
Backend::Factory* f = (*factories)[sname.c_str()];
|
||||
Backend::Factory* f = (*factories)[sname];
|
||||
if ( !f )
|
||||
{
|
||||
throw UnknownBackendException ( sname );
|
||||
|
|
|
@ -12,7 +12,7 @@ class Backend
|
|||
public:
|
||||
class Factory
|
||||
{
|
||||
static std::map<const char*,Factory*>* factories;
|
||||
static std::map<std::string,Factory*>* factories;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -22,7 +22,8 @@ public:
|
|||
virtual Backend* operator() ( Project& ) = 0;
|
||||
|
||||
public:
|
||||
static Backend* Create ( const std::string& name, Project& project );
|
||||
static Backend* Create ( const std::string& name,
|
||||
Project& project );
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -90,7 +90,9 @@ MingwBackend::GenerateAllTarget ()
|
|||
void
|
||||
MingwBackend::ProcessModule ( Module& module )
|
||||
{
|
||||
MingwModuleHandler* h = MingwModuleHandler::LookupHandler ( module.name );
|
||||
MingwModuleHandler* h = MingwModuleHandler::LookupHandler (
|
||||
module.node.location,
|
||||
module.stype );
|
||||
h->Process ( module );
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ using std::string;
|
|||
using std::vector;
|
||||
using std::map;
|
||||
|
||||
map<const char*,MingwModuleHandler*>*
|
||||
map<string,MingwModuleHandler*>*
|
||||
MingwModuleHandler::handler_map = NULL;
|
||||
|
||||
FILE*
|
||||
|
@ -21,8 +21,8 @@ MingwModuleHandler::MingwModuleHandler ( const char* moduletype_ )
|
|||
string moduletype ( moduletype_ );
|
||||
strlwr ( &moduletype[0] );
|
||||
if ( !handler_map )
|
||||
handler_map = new map<const char*,MingwModuleHandler*>;
|
||||
(*handler_map)[moduletype.c_str()] = this;
|
||||
handler_map = new map<string,MingwModuleHandler*>;
|
||||
(*handler_map)[moduletype] = this;
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
|
@ -32,16 +32,17 @@ MingwModuleHandler::SetMakefile ( FILE* f )
|
|||
}
|
||||
|
||||
/*static*/ MingwModuleHandler*
|
||||
MingwModuleHandler::LookupHandler ( const string& moduletype_ )
|
||||
MingwModuleHandler::LookupHandler ( const string& location,
|
||||
const string& moduletype_ )
|
||||
{
|
||||
string moduletype ( moduletype_ );
|
||||
strlwr ( &moduletype[0] );
|
||||
if ( !handler_map )
|
||||
throw Exception ( "internal tool error: no registered module handlers" );
|
||||
MingwModuleHandler* h = (*handler_map)[moduletype.c_str()];
|
||||
MingwModuleHandler* h = (*handler_map)[moduletype];
|
||||
if ( !h )
|
||||
{
|
||||
throw UnknownModuleTypeException ( moduletype );
|
||||
throw UnknownModuleTypeException ( location, moduletype );
|
||||
return NULL;
|
||||
}
|
||||
return h;
|
||||
|
@ -217,6 +218,16 @@ MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Includ
|
|||
return parameters;
|
||||
}
|
||||
|
||||
void
|
||||
MingwModuleHandler::GenerateGccModuleIncludeVariable ( const Module& module ) const
|
||||
{
|
||||
string name ( module.name + "_INCLUDES" );
|
||||
fprintf ( fMakefile,
|
||||
"%s := %s\n",
|
||||
name.c_str(),
|
||||
GenerateGccIncludeParameters(module).c_str() );
|
||||
}
|
||||
|
||||
string
|
||||
MingwModuleHandler::GenerateGccIncludeParameters ( const Module& module ) const
|
||||
{
|
||||
|
@ -234,12 +245,7 @@ string
|
|||
MingwModuleHandler::GenerateGccParameters ( const Module& module ) const
|
||||
{
|
||||
string parameters = GenerateGccDefineParameters ( module );
|
||||
string s = GenerateGccIncludeParameters ( module );
|
||||
if ( s.length () > 0 )
|
||||
{
|
||||
parameters += " ";
|
||||
parameters += s;
|
||||
}
|
||||
parameters += ssprintf(" $(%s_INCLUDES)",module.name.c_str());
|
||||
return parameters;
|
||||
}
|
||||
|
||||
|
@ -250,6 +256,8 @@ MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
|
|||
if ( module.files.size () == 0 )
|
||||
return;
|
||||
|
||||
GenerateGccModuleIncludeVariable ( module );
|
||||
|
||||
for ( size_t i = 0; i < module.files.size (); i++ )
|
||||
{
|
||||
string sourceFilename = module.files[i]->name;
|
||||
|
@ -378,7 +386,7 @@ MingwModuleHandler::GenerateInvocations ( const Module& module ) const
|
|||
{
|
||||
const Invoke& invoke = *module.invocations[i];
|
||||
|
||||
if ( invoke.invokeModule->type != BuildTool )
|
||||
if ( invoke.invokeModule->etype != BuildTool )
|
||||
throw InvalidBuildFileException ( module.node.location,
|
||||
"Only modules of type buildtool can be invoked." );
|
||||
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
class MingwModuleHandler
|
||||
{
|
||||
public:
|
||||
static std::map<const char*,MingwModuleHandler*>* handler_map;
|
||||
static std::map<std::string,MingwModuleHandler*>* handler_map;
|
||||
|
||||
MingwModuleHandler ( const char* moduletype_ );
|
||||
virtual ~MingwModuleHandler() {}
|
||||
|
||||
static void SetMakefile ( FILE* f );
|
||||
static MingwModuleHandler* LookupHandler ( const std::string& moduletype_ );
|
||||
static MingwModuleHandler* LookupHandler ( const std::string& location,
|
||||
const std::string& moduletype_ );
|
||||
virtual void Process ( const Module& module ) = 0;
|
||||
|
||||
protected:
|
||||
|
@ -42,6 +43,7 @@ private:
|
|||
std::string GenerateGccDefineParametersFromVector ( const std::vector<Define*>& defines ) const;
|
||||
std::string GenerateGccDefineParameters ( const Module& module ) const;
|
||||
std::string GenerateGccIncludeParametersFromVector ( const std::vector<Include*>& includes ) const;
|
||||
void GenerateGccModuleIncludeVariable ( const Module& module ) const;
|
||||
std::string GenerateGccIncludeParameters ( const Module& module ) const;
|
||||
std::string GenerateGccParameters ( const Module& module ) const;
|
||||
void GenerateObjectFileTargets ( const Module& module,
|
||||
|
|
|
@ -93,17 +93,23 @@ XMLSyntaxErrorException::XMLSyntaxErrorException ( const string& location,
|
|||
}
|
||||
|
||||
|
||||
RequiredAttributeNotFoundException::RequiredAttributeNotFoundException ( const string& attributeName,
|
||||
const string& elementName )
|
||||
: InvalidBuildFileException ( "Required attribute '%s' not found on '%s'.",
|
||||
RequiredAttributeNotFoundException::RequiredAttributeNotFoundException (
|
||||
const string& location,
|
||||
const string& attributeName,
|
||||
const string& elementName )
|
||||
: InvalidBuildFileException ( location,
|
||||
"Required attribute '%s' not found on '%s'.",
|
||||
attributeName.c_str (),
|
||||
elementName.c_str ())
|
||||
{
|
||||
}
|
||||
|
||||
InvalidAttributeValueException::InvalidAttributeValueException ( const string& name,
|
||||
const string& value )
|
||||
: InvalidBuildFileException ( "Attribute '%s' has an invalid value '%s'.",
|
||||
InvalidAttributeValueException::InvalidAttributeValueException (
|
||||
const string& location,
|
||||
const string& name,
|
||||
const string& value )
|
||||
: InvalidBuildFileException ( location,
|
||||
"Attribute '%s' has an invalid value '%s'.",
|
||||
name.c_str (),
|
||||
value.c_str () )
|
||||
{
|
||||
|
@ -119,12 +125,14 @@ BackendNameConflictException::BackendNameConflictException ( const string& name
|
|||
|
||||
UnknownBackendException::UnknownBackendException ( const string& name )
|
||||
: Exception ( "Unknown Backend requested: '%s'",
|
||||
name.c_str() )
|
||||
name.c_str() )
|
||||
{
|
||||
}
|
||||
|
||||
UnknownModuleTypeException::UnknownModuleTypeException ( const string& moduletype )
|
||||
: Exception ( "module type requested: '%s'",
|
||||
moduletype.c_str() )
|
||||
UnknownModuleTypeException::UnknownModuleTypeException ( const string& location,
|
||||
const string& moduletype )
|
||||
: InvalidBuildFileException ( location,
|
||||
"module type requested: '%s'",
|
||||
moduletype.c_str() )
|
||||
{
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ public:
|
|||
class RequiredAttributeNotFoundException : public InvalidBuildFileException
|
||||
{
|
||||
public:
|
||||
RequiredAttributeNotFoundException ( const std::string& attributeName,
|
||||
RequiredAttributeNotFoundException ( const std::string& location,
|
||||
const std::string& attributeName,
|
||||
const std::string& elementName );
|
||||
};
|
||||
|
||||
|
@ -74,7 +75,8 @@ public:
|
|||
class InvalidAttributeValueException : public InvalidBuildFileException
|
||||
{
|
||||
public:
|
||||
InvalidAttributeValueException ( const std::string& name,
|
||||
InvalidAttributeValueException ( const std::string& location,
|
||||
const std::string& name,
|
||||
const std::string& value );
|
||||
};
|
||||
|
||||
|
@ -92,10 +94,11 @@ public:
|
|||
UnknownBackendException ( const std::string& name );
|
||||
};
|
||||
|
||||
class UnknownModuleTypeException : public Exception
|
||||
class UnknownModuleTypeException : public InvalidBuildFileException
|
||||
{
|
||||
public:
|
||||
UnknownModuleTypeException ( const std::string& moduletype );
|
||||
UnknownModuleTypeException ( const std::string& location,
|
||||
const std::string& moduletype );
|
||||
};
|
||||
|
||||
#endif /* __EXCEPTION_H */
|
||||
|
|
|
@ -38,7 +38,9 @@ Module::Module ( const Project& project,
|
|||
|
||||
att = moduleNode.GetAttribute ( "type", true );
|
||||
assert(att);
|
||||
type = GetModuleType ( *att );
|
||||
stype = att->value;
|
||||
strlwr ( &stype[0] );
|
||||
etype = GetModuleType ( node.location, *att );
|
||||
|
||||
att = moduleNode.GetAttribute ( "extension", false );
|
||||
if (att != NULL)
|
||||
|
@ -136,7 +138,7 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
|
|||
}
|
||||
|
||||
ModuleType
|
||||
Module::GetModuleType ( const XMLAttribute& attribute )
|
||||
Module::GetModuleType ( const string& location, const XMLAttribute& attribute )
|
||||
{
|
||||
if ( attribute.value == "buildtool" )
|
||||
return BuildTool;
|
||||
|
@ -144,14 +146,15 @@ Module::GetModuleType ( const XMLAttribute& attribute )
|
|||
return StaticLibrary;
|
||||
if ( attribute.value == "kernelmodedll" )
|
||||
return KernelModeDLL;
|
||||
throw InvalidAttributeValueException ( attribute.name,
|
||||
throw InvalidAttributeValueException ( location,
|
||||
attribute.name,
|
||||
attribute.value );
|
||||
}
|
||||
|
||||
string
|
||||
Module::GetDefaultModuleExtension () const
|
||||
{
|
||||
switch (type)
|
||||
switch (etype)
|
||||
{
|
||||
case BuildTool:
|
||||
return EXEPOSTFIX;
|
||||
|
@ -264,7 +267,7 @@ Invoke::ProcessXML()
|
|||
module.name.c_str(),
|
||||
att->value.c_str() );
|
||||
}
|
||||
|
||||
|
||||
for ( size_t i = 0; i < node.subElements.size (); i++ )
|
||||
ProcessXMLSubElement ( *node.subElements[i] );
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
std::vector<Module*> modules;
|
||||
std::vector<Include*> includes;
|
||||
std::vector<Define*> defines;
|
||||
|
||||
|
||||
Project ();
|
||||
Project ( const std::string& filename );
|
||||
~Project ();
|
||||
|
@ -71,19 +71,21 @@ public:
|
|||
std::string name;
|
||||
std::string extension;
|
||||
std::string path;
|
||||
ModuleType type;
|
||||
ModuleType etype;
|
||||
std::string stype;
|
||||
std::vector<File*> files;
|
||||
std::vector<Library*> libraries;
|
||||
std::vector<Include*> includes;
|
||||
std::vector<Define*> defines;
|
||||
std::vector<Invoke*> invocations;
|
||||
std::vector<Dependency*> dependencies;
|
||||
|
||||
|
||||
Module ( const Project& project,
|
||||
const XMLElement& moduleNode,
|
||||
const std::string& modulePath );
|
||||
~Module ();
|
||||
ModuleType GetModuleType (const XMLAttribute& attribute );
|
||||
ModuleType GetModuleType ( const std::string& location,
|
||||
const XMLAttribute& attribute );
|
||||
std::string GetBasePath() const;
|
||||
std::string GetPath () const;
|
||||
std::string GetTargets () const;
|
||||
|
|
|
@ -9,7 +9,7 @@ void ModuleTest::Run()
|
|||
ARE_EQUAL(2, project.modules.size());
|
||||
|
||||
Module& module1 = *project.modules[0];
|
||||
IS_TRUE(module1.type == BuildTool);
|
||||
IS_TRUE(module1.etype == BuildTool);
|
||||
ARE_EQUAL(2, module1.files.size());
|
||||
ARE_EQUAL("." SSEP "dir1" SSEP "file1.c", module1.files[0]->name);
|
||||
ARE_EQUAL("." SSEP "dir1" SSEP "file2.c", module1.files[1]->name);
|
||||
|
@ -17,7 +17,7 @@ void ModuleTest::Run()
|
|||
ARE_EQUAL(0, module1.libraries.size());
|
||||
|
||||
Module& module2 = *project.modules[1];
|
||||
IS_TRUE(module2.type == KernelModeDLL);
|
||||
IS_TRUE(module2.etype == KernelModeDLL);
|
||||
ARE_EQUAL(2, module2.files.size());
|
||||
ARE_EQUAL("." SSEP "dir2" SSEP "file3.c", module2.files[0]->name);
|
||||
ARE_EQUAL("." SSEP "dir2" SSEP "file4.c", module2.files[1]->name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue