From 7d876c4d0cb9ba513e427e53acbbc4e5bd491216 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Wed, 5 Jan 2005 22:36:17 +0000 Subject: [PATCH] Parse libraries. svn path=/branches/xmlbuildsystem/; revision=12840 --- reactos/tools/rbuild/backend/mingw/mingw.cpp | 2 +- .../rbuild/backend/mingw/modulehandler.cpp | 32 +++++++++++++++++-- .../rbuild/backend/mingw/modulehandler.h | 9 ++++-- reactos/tools/rbuild/module.cpp | 13 ++++++++ reactos/tools/rbuild/project.cpp | 5 --- reactos/tools/rbuild/rbuild.h | 13 +++++++- reactos/tools/rbuild/tests/data/module.xml | 1 + reactos/tools/rbuild/tests/moduletest.cpp | 9 +++++- 8 files changed, 72 insertions(+), 12 deletions(-) diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index 83d999e4325..56b43f08057 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -103,5 +103,5 @@ void MingwBackend::ProcessModule ( Module& module ) void MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) { - moduleHandlers.push_back ( new MingwKernelModuleHandler () ); + moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) ); } diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index 2a539c148f4..f2653ca752e 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -5,12 +5,29 @@ #include "mingw.h" #include "modulehandler.h" -MingwModuleHandler::MingwModuleHandler () +using std::string; + +MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile ) + : fMakefile ( fMakefile ) { } +string MingwModuleHandler::GetModuleDependencies ( Module& module ) +{ + string dependencies ( "" ); + + for ( size_t i = 0; i < module.libraries.size(); i++ ) + { + if (dependencies.size () > 0) + dependencies += " "; + dependencies += module.libraries[i]->name; + } + return dependencies; +} -MingwKernelModuleHandler::MingwKernelModuleHandler () + +MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile ) + : MingwModuleHandler ( fMakefile ) { } @@ -21,4 +38,15 @@ bool MingwKernelModuleHandler::CanHandleModule ( Module& module ) void MingwKernelModuleHandler::Process ( Module& module ) { + GenerateKernelModuleTarget ( module ); +} + +void MingwKernelModuleHandler::GenerateKernelModuleTarget ( Module& module ) +{ + fprintf ( fMakefile, "%s: %s", + module.name.c_str (), + GetModuleDependencies ( module ).c_str () ); + fprintf ( fMakefile, "\n" ); + fprintf ( fMakefile, "\t" ); + fprintf ( fMakefile, "\n\n" ); } diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index 0294a0e9172..1f827be809f 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -6,18 +6,23 @@ class MingwModuleHandler { public: - MingwModuleHandler (); + MingwModuleHandler ( FILE* fMakefile ); virtual bool CanHandleModule ( Module& module ) = 0; virtual void Process ( Module& module ) = 0; +protected: + FILE* fMakefile; + std::string GetModuleDependencies ( Module& module ); }; class MingwKernelModuleHandler : public MingwModuleHandler { public: - MingwKernelModuleHandler (); + MingwKernelModuleHandler ( FILE* fMakefile ); virtual bool CanHandleModule ( Module& module ); virtual void Process ( Module& module ); +private: + void GenerateKernelModuleTarget ( Module& module ); }; #endif /* MINGW_MODULEHANDLER_H */ diff --git a/reactos/tools/rbuild/module.cpp b/reactos/tools/rbuild/module.cpp index fdbde720da3..d0f1e5ec099 100644 --- a/reactos/tools/rbuild/module.cpp +++ b/reactos/tools/rbuild/module.cpp @@ -21,6 +21,8 @@ Module::~Module () { for ( size_t i = 0; i < files.size(); i++ ) delete files[i]; + for ( size_t i = 0; i < libraries.size(); i++ ) + delete libraries[i]; } void Module::ProcessXML ( const XMLElement& e, @@ -31,6 +33,10 @@ void Module::ProcessXML ( const XMLElement& e, { files.push_back ( new File ( path + "/" + e.value ) ); } + else if ( e.name == "library" && e.value.size () ) + { + libraries.push_back ( new Library ( e.value ) ); + } else if ( e.name == "directory" ) { const XMLAttribute* att = e.GetAttribute ( "name", true ); @@ -50,7 +56,14 @@ ModuleType Module::GetModuleType ( const XMLAttribute& attribute ) attribute.value ); } + File::File ( const string& _name ) : name(_name) { } + + +Library::Library ( const string& _name ) + : name(_name) +{ +} diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index 19b59390f12..1ac65a38b31 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -60,8 +60,6 @@ Project::ProcessXML ( const XMLElement& e, const string& path ) else if ( e.name == "module" ) { att = e.GetAttribute ( "name", true ); - if ( !att ) - return; Module* module = new Module ( e, att->value, path ); modules.push_back ( module ); module->ProcessXML ( e, path ); @@ -69,10 +67,7 @@ Project::ProcessXML ( const XMLElement& e, const string& path ) } else if ( e.name == "directory" ) { - // this code is duplicated between Project::ProcessXML() and Module::ProcessXML() :( const XMLAttribute* att = e.GetAttribute ( "name", true ); - if ( !att ) - return; subpath = path + "/" + att->value; } for ( size_t i = 0; i < e.subElements.size (); i++ ) diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index fc0060f563a..c722078708b 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -10,6 +10,7 @@ class Project; class Module; class File; +class Library; class Project { @@ -42,8 +43,9 @@ public: const XMLElement& node; std::string name; std::string path; - std::vector files; ModuleType type; + std::vector files; + std::vector libraries; Module ( const XMLElement& moduleNode, const std::string& moduleName, @@ -64,4 +66,13 @@ public: File ( const std::string& _name ); }; + +class Library +{ +public: + std::string name; + + Library ( const std::string& _name ); +}; + #endif /* __RBUILD_H */ diff --git a/reactos/tools/rbuild/tests/data/module.xml b/reactos/tools/rbuild/tests/data/module.xml index f3e8a636d56..cd290482974 100644 --- a/reactos/tools/rbuild/tests/data/module.xml +++ b/reactos/tools/rbuild/tests/data/module.xml @@ -7,6 +7,7 @@ + module1 file3.c file4.c diff --git a/reactos/tools/rbuild/tests/moduletest.cpp b/reactos/tools/rbuild/tests/moduletest.cpp index f7f152c4f74..80a366baa78 100644 --- a/reactos/tools/rbuild/tests/moduletest.cpp +++ b/reactos/tools/rbuild/tests/moduletest.cpp @@ -13,10 +13,17 @@ void ModuleTest::Run() ARE_EQUAL(2, module1.files.size()); ARE_EQUAL("./dir1/file1.c", module1.files[0]->name); ARE_EQUAL("./dir1/file2.c", module1.files[1]->name); - + + ARE_EQUAL(0, module1.libraries.size()); + Module& module2 = *project.modules[1]; IS_TRUE(module2.type == KernelModeDLL); ARE_EQUAL(2, module2.files.size()); ARE_EQUAL("./dir2/file3.c", module2.files[0]->name); ARE_EQUAL("./dir2/file4.c", module2.files[1]->name); + + ARE_EQUAL(1, module2.libraries.size()); + Library& library1 = *module2.libraries[0]; + + ARE_EQUAL("module1", library1.name); }