From d32ad9196b41fd625765f0e1fbf9e2b021a930e6 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Fri, 13 May 2005 19:17:44 +0000 Subject: [PATCH] Support compilerflag within IFs svn path=/branches/xmlbuildsystem/; revision=15267 --- reactos/ntoskrnl/rtl/misc.c | 2 +- reactos/tools/rbuild/backend/mingw/mingw.cpp | 12 ++++++- .../rbuild/backend/mingw/modulehandler.cpp | 35 +++++++------------ .../rbuild/backend/mingw/modulehandler.h | 5 +-- reactos/tools/rbuild/compilerflag.cpp | 10 +++--- reactos/tools/rbuild/module.cpp | 10 +++++- reactos/tools/rbuild/project.cpp | 9 +++++ reactos/tools/rbuild/rbuild.h | 1 + reactos/tools/rbuild/rbuild.txt | 2 +- reactos/tools/rbuild/test.h | 3 ++ reactos/tools/rbuild/tests/data/if.xml | 6 +++- reactos/tools/rbuild/tests/iftest.cpp | 35 ++++++++++++++++--- 12 files changed, 88 insertions(+), 42 deletions(-) diff --git a/reactos/ntoskrnl/rtl/misc.c b/reactos/ntoskrnl/rtl/misc.c index 311db1df9de..9524c89bcbf 100644 --- a/reactos/ntoskrnl/rtl/misc.c +++ b/reactos/ntoskrnl/rtl/misc.c @@ -1,4 +1,4 @@ -/* $Id:$ +/* $Id$ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index 93bb9e71752..34135575bd4 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -393,6 +393,15 @@ MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation, fMakefile, "PROJECT_CFLAGS %s", assignmentOperation ); + + for ( i = 0; i < data.compilerFlags.size(); i++ ) + { + fprintf ( + fMakefile, + " %s", + data.compilerFlags[i]->flag.c_str() ); + } + for ( i = 0; i < data.includes.size(); i++ ) { fprintf ( @@ -432,7 +441,7 @@ MingwBackend::GenerateGlobalCFlagsAndProperties ( prop.value.c_str() ); } - if ( data.includes.size() || data.defines.size() ) + if ( data.includes.size() || data.defines.size() || data.compilerFlags.size() ) { GenerateProjectCFlagsMacro ( assignmentOperation, data ); @@ -443,6 +452,7 @@ MingwBackend::GenerateGlobalCFlagsAndProperties ( If& rIf = *data.ifs[i]; if ( rIf.data.defines.size() || rIf.data.includes.size() + || rIf.data.compilerFlags.size() || rIf.data.ifs.size() ) { fprintf ( diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index e31874639f2..652cbc5b3e5 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -562,7 +562,6 @@ MingwModuleHandler::GenerateGccIncludeParameters () const return parameters; } - string MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector& compilerFlags ) const { @@ -618,8 +617,7 @@ void MingwModuleHandler::GenerateMacro ( const char* assignmentOperation, const string& macro, - const IfableData& data, - const vector* compilerFlags ) + const IfableData& data ) { size_t i; @@ -629,16 +627,13 @@ MingwModuleHandler::GenerateMacro ( macro.c_str(), assignmentOperation ); - if ( compilerFlags != NULL ) + string compilerParameters = GenerateCompilerParametersFromVector ( data.compilerFlags ); + if ( compilerParameters.size () > 0 ) { - string compilerParameters = GenerateCompilerParametersFromVector ( *compilerFlags ); - if ( compilerParameters.size () > 0 ) - { - fprintf ( - fMakefile, - " %s", - compilerParameters.c_str () ); - } + fprintf ( + fMakefile, + " %s", + compilerParameters.c_str () ); } for ( i = 0; i < data.includes.size(); i++ ) @@ -668,21 +663,18 @@ void MingwModuleHandler::GenerateMacros ( const char* assignmentOperation, const IfableData& data, - const vector* compilerFlags, const vector* linkerFlags ) { size_t i; - if ( data.includes.size () > 0 || data.defines.size () > 0 ) + if ( data.includes.size () > 0 || data.defines.size () > 0 || data.compilerFlags.size () > 0 ) { GenerateMacro ( assignmentOperation, cflagsMacro, - data, - compilerFlags ); + data ); GenerateMacro ( assignmentOperation, windresflagsMacro, - data, - compilerFlags ); + data ); } if ( linkerFlags != NULL ) @@ -721,6 +713,7 @@ MingwModuleHandler::GenerateMacros ( || rIf.data.includes.size() || rIf.data.libraries.size() || rIf.data.files.size() + || rIf.data.compilerFlags.size() || rIf.data.ifs.size() ) { fprintf ( @@ -731,7 +724,6 @@ MingwModuleHandler::GenerateMacros ( GenerateMacros ( "+=", rIf.data, - NULL, NULL ); fprintf ( fMakefile, @@ -744,7 +736,6 @@ void MingwModuleHandler::GenerateObjectMacros ( const char* assignmentOperation, const IfableData& data, - const vector* compilerFlags, const vector* linkerFlags ) { size_t i; @@ -794,6 +785,7 @@ MingwModuleHandler::GenerateObjectMacros ( || rIf.data.includes.size() || rIf.data.libraries.size() || rIf.data.files.size() + || rIf.data.compilerFlags.size() || rIf.data.ifs.size() ) { fprintf ( @@ -804,7 +796,6 @@ MingwModuleHandler::GenerateObjectMacros ( GenerateObjectMacros ( "+=", rIf.data, - NULL, NULL ); fprintf ( fMakefile, @@ -1531,7 +1522,6 @@ MingwModuleHandler::GenerateObjectMacro () GenerateObjectMacros ( "=", module.non_if_data, - &module.compilerFlags, &module.linkerFlags ); // future references to the macro will be to get its values @@ -1561,7 +1551,6 @@ MingwModuleHandler::GenerateOtherMacros () GenerateMacros ( "=", module.non_if_data, - &module.compilerFlags, &module.linkerFlags ); if ( module.importLibrary ) diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index e4df0d2b967..751cb095934 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -109,15 +109,12 @@ private: std::string GenerateLinkerParameters () const; void GenerateMacro ( const char* assignmentOperation, const std::string& macro, - const IfableData& data, - const std::vector* compilerFlags ); + const IfableData& data ); void GenerateMacros ( const char* op, const IfableData& data, - const std::vector* compilerFlags, const std::vector* linkerFlags ); void GenerateObjectMacros ( const char* assignmentOperation, const IfableData& data, - const std::vector* compilerFlags, const std::vector* linkerFlags ); std::string GenerateGccIncludeParameters () const; std::string GenerateGccParameters () const; diff --git a/reactos/tools/rbuild/compilerflag.cpp b/reactos/tools/rbuild/compilerflag.cpp index dde21edce25..d166254f99f 100644 --- a/reactos/tools/rbuild/compilerflag.cpp +++ b/reactos/tools/rbuild/compilerflag.cpp @@ -31,11 +31,6 @@ CompilerFlag::~CompilerFlag () void CompilerFlag::Initialize () -{ -} - -void -CompilerFlag::ProcessXML () { if (node.value.size () == 0) { @@ -45,3 +40,8 @@ CompilerFlag::ProcessXML () } flag = node.value; } + +void +CompilerFlag::ProcessXML () +{ +} diff --git a/reactos/tools/rbuild/module.cpp b/reactos/tools/rbuild/module.cpp index 9820906abae..eafbfc37fa6 100644 --- a/reactos/tools/rbuild/module.cpp +++ b/reactos/tools/rbuild/module.cpp @@ -100,6 +100,8 @@ IfableData::~IfableData() delete libraries[i]; for ( i = 0; i < properties.size(); i++ ) delete properties[i]; + for ( i = 0; i < compilerFlags.size(); i++ ) + delete compilerFlags[i]; for ( i = 0; i < ifs.size(); i++ ) delete ifs[i]; } @@ -117,6 +119,8 @@ void IfableData::ProcessXML () libraries[i]->ProcessXML (); for ( i = 0; i < properties.size(); i++ ) properties[i]->ProcessXML (); + for ( i = 0; i < compilerFlags.size(); i++ ) + compilerFlags[i]->ProcessXML (); for ( i = 0; i < ifs.size (); i++ ) ifs[i]->ProcessXML (); } @@ -390,7 +394,11 @@ Module::ProcessXMLSubElement ( const XMLElement& e, } else if ( e.name == "compilerflag" ) { - compilerFlags.push_back ( new CompilerFlag ( project, this, e ) ); + CompilerFlag* pCompilerFlag = new CompilerFlag ( project, this, e ); + if ( pIf ) + pIf->data.compilerFlags.push_back ( pCompilerFlag ); + else + non_if_data.compilerFlags.push_back ( pCompilerFlag ); subs_invalid = true; } else if ( e.name == "linkerflag" ) diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index f41c7a0be00..453268cace0 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -285,6 +285,15 @@ Project::ProcessXMLSubElement ( const XMLElement& e, non_if_data.defines.push_back ( define ); subs_invalid = true; } + else if ( e.name == "compilerflag" ) + { + CompilerFlag* pCompilerFlag = new CompilerFlag ( *this, e ); + if ( pIf ) + pIf->data.compilerFlags.push_back ( pCompilerFlag ); + else + non_if_data.compilerFlags.push_back ( pCompilerFlag ); + subs_invalid = true; + } else if ( e.name == "linkerflag" ) { linkerFlags.push_back ( new LinkerFlag ( *this, e ) ); diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index d32040711fe..b65ea6b3a9f 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -73,6 +73,7 @@ public: std::vector defines; std::vector libraries; std::vector properties; + std::vector compilerFlags; std::vector ifs; ~IfableData(); diff --git a/reactos/tools/rbuild/rbuild.txt b/reactos/tools/rbuild/rbuild.txt index 4633fe39947..24ac49e4b29 100644 --- a/reactos/tools/rbuild/rbuild.txt +++ b/reactos/tools/rbuild/rbuild.txt @@ -310,7 +310,7 @@ Value: None. Elements: - define, directory, file, if, include, property. + compilerflag, define, directory, file, if, include, property. Importlibrary element diff --git a/reactos/tools/rbuild/test.h b/reactos/tools/rbuild/test.h index 94bd90e41e3..ce8309bdeef 100644 --- a/reactos/tools/rbuild/test.h +++ b/reactos/tools/rbuild/test.h @@ -97,6 +97,9 @@ class IfTest : public BaseTest { public: void Run (); +private: + void TestProjectIf ( Project& project ); + void TestModuleIf ( Project& project ); }; diff --git a/reactos/tools/rbuild/tests/data/if.xml b/reactos/tools/rbuild/tests/data/if.xml index 03a981831de..759f486298e 100644 --- a/reactos/tools/rbuild/tests/data/if.xml +++ b/reactos/tools/rbuild/tests/data/if.xml @@ -1,7 +1,11 @@ + + compilerflag1 + - + + compilerflag2 file1.c file2.c diff --git a/reactos/tools/rbuild/tests/iftest.cpp b/reactos/tools/rbuild/tests/iftest.cpp index 37d88c15c63..2d938ddb7e5 100644 --- a/reactos/tools/rbuild/tests/iftest.cpp +++ b/reactos/tools/rbuild/tests/iftest.cpp @@ -2,18 +2,29 @@ using std::string; -void IfTest::Run() +void +IfTest::TestProjectIf ( Project& project ) { - string projectFilename ( RBUILD_BASE "tests/data/if.xml" ); - Project project ( projectFilename ); + ARE_EQUAL ( 1, project.non_if_data.ifs.size () ); + If& if1 = *project.non_if_data.ifs[0]; + ARE_EQUAL ( "VAR1", if1.property ); + ARE_EQUAL ( "value1", if1.value ); + ARE_EQUAL ( 1, if1.data.compilerFlags.size () ); + CompilerFlag& compilerFlag1 = *if1.data.compilerFlags[0]; + ARE_EQUAL( "compilerflag1", compilerFlag1.flag ); +} + +void +IfTest::TestModuleIf ( Project& project ) +{ ARE_EQUAL ( 1, project.modules.size () ); Module& module1 = *project.modules[0]; ARE_EQUAL ( 1, module1.non_if_data.ifs.size () ); If& if1 = *module1.non_if_data.ifs[0]; - ARE_EQUAL ( "VAR1", if1.property ); - ARE_EQUAL ( "value1", if1.value ); + ARE_EQUAL ( "VAR2", if1.property ); + ARE_EQUAL ( "value2", if1.value ); ARE_EQUAL ( 1, if1.data.files.size () ); File& file1 = *if1.data.files[0]; @@ -22,4 +33,18 @@ void IfTest::Run() ARE_EQUAL ( 1, module1.non_if_data.files.size () ); File& file2 = *module1.non_if_data.files[0]; ARE_EQUAL( SSEP "file2.c", file2.name ); + + ARE_EQUAL ( 1, if1.data.compilerFlags.size () ); + CompilerFlag& compilerFlag2 = *if1.data.compilerFlags[0]; + ARE_EQUAL( "compilerflag2", compilerFlag2.flag ); +} + +void +IfTest::Run () +{ + string projectFilename ( RBUILD_BASE "tests/data/if.xml" ); + Project project ( projectFilename ); + + TestProjectIf ( project ); + TestModuleIf ( project ); }