From 59605ac1e7b246f6ac0897f912ca655d95e62c01 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Fri, 24 Jun 2005 19:39:47 +0000 Subject: [PATCH] Search current directory first for #include "". svn path=/trunk/; revision=16260 --- reactos/tools/rbuild/automaticdependency.cpp | 71 ++++++++++++-------- reactos/tools/rbuild/include.cpp | 52 +++++++------- reactos/tools/rbuild/module.cpp | 2 +- reactos/tools/rbuild/project.cpp | 2 +- reactos/tools/rbuild/rbuild.h | 16 +++-- 5 files changed, 84 insertions(+), 59 deletions(-) diff --git a/reactos/tools/rbuild/automaticdependency.cpp b/reactos/tools/rbuild/automaticdependency.cpp index 8c8a3603b33..6f3ca576683 100644 --- a/reactos/tools/rbuild/automaticdependency.cpp +++ b/reactos/tools/rbuild/automaticdependency.cpp @@ -85,6 +85,7 @@ SourceFile::SkipWhitespace () bool SourceFile::ReadInclude ( string& filename, + bool& searchCurrentDirectory, bool& includeNext) { while ( p < end ) @@ -117,6 +118,7 @@ SourceFile::ReadInclude ( string& filename, register char ch = *p; if ( ch == '<' || ch == '"' ) { + searchCurrentDirectory = (ch == '"'); p++; filename.resize ( MAX_PATH ); int i = 0; @@ -138,6 +140,7 @@ SourceFile::ReadInclude ( string& filename, p++; } filename = ""; + searchCurrentDirectory = false; includeNext = false; return false; } @@ -230,14 +233,17 @@ SourceFile::Parse () { string includedFilename ( "" ); + bool searchCurrentDirectory; bool includeNext; while ( ReadInclude ( includedFilename, + searchCurrentDirectory, includeNext ) ) { string resolvedFilename ( "" ); bool locatedFile = automaticDependency->LocateIncludedFile ( this, module, includedFilename, + searchCurrentDirectory, includeNext, resolvedFilename ); if ( locatedFile ) @@ -321,8 +327,8 @@ AutomaticDependency::ParseFile ( Module& module, bool AutomaticDependency::LocateIncludedFile ( const string& directory, - const string& includedFilename, - string& resolvedFilename ) + const string& includedFilename, + string& resolvedFilename ) { string normalizedFilename = NormalizeFilename ( directory + SSEP + includedFilename ); FILE* f = fopen ( normalizedFilename.c_str (), "rb" ); @@ -347,37 +353,44 @@ AutomaticDependency::GetFilename ( const string& filename ) filename.length () - index - 1); } +void +AutomaticDependency::GetIncludeDirectories ( vector& includes, + Module& module, + Include& currentDirectory, + bool searchCurrentDirectory ) +{ + if ( searchCurrentDirectory ) + includes.push_back( ¤tDirectory ); + for ( size_t i = 0; i < module.non_if_data.includes.size (); i++ ) + includes.push_back( module.non_if_data.includes[i] ); + for ( size_t i = 0; i < module.project.non_if_data.includes.size (); i++ ) + includes.push_back( module.project.non_if_data.includes[i] ); +} + bool AutomaticDependency::LocateIncludedFile ( SourceFile* sourceFile, - Module& module, - const string& includedFilename, - bool includeNext, - string& resolvedFilename ) + Module& module, + const string& includedFilename, + bool searchCurrentDirectory, + bool includeNext, + string& resolvedFilename ) { - size_t i, j; - const vector* pincludes; - for ( i = 0; i < 2; i++ ) + vector includes; + Include currentDirectory ( module.project, ".", sourceFile->directoryPart ); + GetIncludeDirectories ( includes, module, currentDirectory, searchCurrentDirectory ); + for ( size_t j = 0; j < includes.size (); j++ ) { - if ( !i ) - pincludes = &module.non_if_data.includes; - else - pincludes = &module.project.non_if_data.includes; - const vector& includes = *pincludes; - for ( j = 0; j < includes.size (); j++ ) + Include& include = *includes[j]; + if ( LocateIncludedFile ( include.directory, + includedFilename, + resolvedFilename ) ) { - Include& include = *includes[j]; - if ( LocateIncludedFile ( include.directory, - includedFilename, - resolvedFilename ) ) - { - if ( includeNext && stricmp ( resolvedFilename.c_str (), - sourceFile->filename.c_str () ) == 0 ) - continue; - return true; - } + if ( includeNext && stricmp ( resolvedFilename.c_str (), + sourceFile->filename.c_str () ) == 0 ) + continue; + return true; } } - resolvedFilename = ""; return false; } @@ -422,15 +435,15 @@ AutomaticDependency::CheckAutomaticDependencies ( bool verbose ) void AutomaticDependency::CheckAutomaticDependencies ( Module& module, - bool verbose ) + bool verbose ) { CheckAutomaticDependencies ( module, verbose, true ); } void AutomaticDependency::CheckAutomaticDependencies ( Module& module, - bool verbose, - bool parseFiles ) + bool verbose, + bool parseFiles ) { if ( parseFiles ) ParseFiles ( module ); diff --git a/reactos/tools/rbuild/include.cpp b/reactos/tools/rbuild/include.cpp index 35e4dcc751e..1d81cfc343a 100644 --- a/reactos/tools/rbuild/include.cpp +++ b/reactos/tools/rbuild/include.cpp @@ -6,45 +6,49 @@ using std::string; using std::vector; -Include::Include ( const Project& project_, - const XMLElement& includeNode ) - : project (project_), - module (NULL), - node (includeNode) +Include::Include ( const Project& project, + const XMLElement* includeNode ) + : project ( project ), + module ( NULL ), + node ( includeNode ) { - Initialize(); } -Include::Include ( const Project& project_, - const Module* module_, - const XMLElement& includeNode ) - : project (project_), - module (module_), - node (includeNode) +Include::Include ( const Project& project, + const Module* module, + const XMLElement* includeNode ) + : project ( project ), + module ( module ), + node ( includeNode ) { - Initialize(); +} + +Include::Include ( const Project& project, + string directory, + string basePath ) + : project ( project ), + module ( NULL ), + node ( NULL ) +{ + this->directory = NormalizeFilename ( basePath + SSEP + directory ); + this->basePath = NormalizeFilename ( basePath ); } Include::~Include () { } -void -Include::Initialize() -{ -} - void Include::ProcessXML() { const XMLAttribute* att; - att = node.GetAttribute ( "base", - false ); + att = node->GetAttribute ( "base", + false ); if ( att ) { if ( !module ) throw InvalidBuildFileException ( - node.location, + node->location, "'base' attribute illegal from global " ); bool referenceResolved = false; if ( att->value == project.name ) @@ -63,11 +67,11 @@ Include::ProcessXML() } if ( !referenceResolved ) throw InvalidBuildFileException ( - node.location, + node->location, " attribute 'base' references non-existant project or module '%s'", att->value.c_str() ); - directory = FixSeparator ( basePath + "/" + node.value ); + directory = NormalizeFilename ( basePath + SSEP + node->value ); } else - directory = FixSeparator ( node.value ); + directory = NormalizeFilename ( node->value ); } diff --git a/reactos/tools/rbuild/module.cpp b/reactos/tools/rbuild/module.cpp index 3b833156132..93ebc62aa54 100644 --- a/reactos/tools/rbuild/module.cpp +++ b/reactos/tools/rbuild/module.cpp @@ -367,7 +367,7 @@ Module::ProcessXMLSubElement ( const XMLElement& e, } else if ( e.name == "include" ) { - Include* include = new Include ( project, this, e ); + Include* include = new Include ( project, this, &e ); if ( pIf ) pIf->data.includes.push_back ( include ); else diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index 464626aa311..290d7b4ea93 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -290,7 +290,7 @@ Project::ProcessXMLSubElement ( const XMLElement& e, } else if ( e.name == "include" ) { - Include* include = new Include ( *this, e ); + Include* include = new Include ( *this, &e ); if ( pIf ) pIf->data.includes.push_back ( include ); else diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index 1830ab96369..1f9b83a154f 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -253,19 +253,21 @@ class Include public: const Project& project; const Module* module; - const XMLElement& node; + const XMLElement* node; std::string directory; std::string basePath; Include ( const Project& project, - const XMLElement& includeNode ); + const XMLElement* includeNode ); Include ( const Project& project, const Module* module, - const XMLElement& includeNode ); + const XMLElement* includeNode ); + Include ( const Project& project, + std::string directory, + std::string basePath ); ~Include (); void ProcessXML(); private: - void Initialize(); }; @@ -556,6 +558,7 @@ private: void Open (); void SkipWhitespace (); bool ReadInclude ( std::string& filename, + bool& searchCurrentDirectory, bool& includeNext ); bool IsIncludedFrom ( const std::string& normalizedFilename ); SourceFile* GetParentSourceFile (); @@ -583,6 +586,7 @@ public: bool LocateIncludedFile ( SourceFile* sourceFile, Module& module, const std::string& includedFilename, + bool searchCurrentDirectory, bool includeNext, std::string& resolvedFilename ); SourceFile* RetrieveFromCacheOrParse ( Module& module, @@ -597,6 +601,10 @@ public: bool parseFiles ); void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile ); private: + void GetIncludeDirectories ( std::vector& includes, + Module& module, + Include& currentDirectory, + bool searchCurrentDirectory ); void GetModuleFiles ( Module& module, std::vector& files ) const; void ParseFiles ();