diff --git a/reactos/tools/rbuild/automaticdependency.cpp b/reactos/tools/rbuild/automaticdependency.cpp index e6d94d0b42e..bf7f3e5dcee 100644 --- a/reactos/tools/rbuild/automaticdependency.cpp +++ b/reactos/tools/rbuild/automaticdependency.cpp @@ -87,15 +87,31 @@ SourceFile::SkipWhitespace () } bool -SourceFile::ReadInclude ( string& filename ) +SourceFile::ReadInclude ( string& filename, + bool& includeNext) { while ( p < end ) { - if ( ( *p == '#') && ( end - p > 8 ) ) + if ( ( *p == '#') && ( end - p > 13 ) ) { - if ( strncmp ( p, "#include", 8 ) == 0 ) + bool include = false; + p++; + SkipWhitespace (); + if ( strncmp ( p, "include ", 8 ) == 0 ) { p += 8; + includeNext = false; + include = true; + } + if ( strncmp ( p, "include_next ", 13 ) == 0 ) + { + p += 13; + includeNext = true; + include = true; + } + + if ( include ) + { SkipWhitespace (); if ( p < end && *p == '<' || *p == '"' ) { @@ -112,6 +128,7 @@ SourceFile::ReadInclude ( string& filename ) p++; } filename = ""; + includeNext = false; return false; } @@ -162,11 +179,27 @@ SourceFile::GetParentSourceFile () return this; } +bool +SourceFile::CanProcessFile ( const string& extension ) +{ + if ( extension == ".h" || extension == ".H" ) + return true; + if ( extension == ".c" || extension == ".C" ) + return true; + if ( extension == ".cpp" || extension == ".CPP" ) + return true; + if ( extension == ".rc" || extension == ".RC" ) + return true; + if ( extension == ".s" || extension == ".S" ) + return true; + return false; +} + SourceFile* SourceFile::ParseFile ( const string& normalizedFilename ) { string extension = GetExtension ( normalizedFilename ); - if ( extension == ".c" || extension == ".C" || extension == ".h" || extension == ".H" ) + if ( CanProcessFile ( extension ) ) { if ( IsIncludedFrom ( normalizedFilename ) ) return NULL; @@ -188,11 +221,15 @@ SourceFile::Parse () string includedFilename ( "" ); //printf ( "Parsing '%s'\n", filename.c_str () ); - while ( ReadInclude ( includedFilename )) + bool includeNext; + while ( ReadInclude ( includedFilename, + includeNext ) ) { string resolvedFilename ( "" ); - bool locatedFile = automaticDependency->LocateIncludedFile ( module, + bool locatedFile = automaticDependency->LocateIncludedFile ( this, + module, includedFilename, + includeNext, resolvedFilename ); if ( locatedFile ) { @@ -275,9 +312,22 @@ AutomaticDependency::LocateIncludedFile ( const string& directory, return false; } +string +AutomaticDependency::GetFilename ( const string& filename ) +{ + size_t index = filename.find_last_of ( CSEP ); + if (index == string::npos) + return filename; + else + return filename.substr ( index + 1, + filename.length () - index - 1); +} + bool -AutomaticDependency::LocateIncludedFile ( Module& module, +AutomaticDependency::LocateIncludedFile ( SourceFile* sourceFile, + Module& module, const string& includedFilename, + bool includeNext, string& resolvedFilename ) { size_t i; @@ -287,7 +337,12 @@ AutomaticDependency::LocateIncludedFile ( Module& module, if ( LocateIncludedFile ( include->directory, includedFilename, resolvedFilename ) ) + { + if ( includeNext && stricmp ( resolvedFilename.c_str (), + sourceFile->filename.c_str () ) == 0 ) + continue; return true; + } } /* FIXME: Ifs */ @@ -298,7 +353,12 @@ AutomaticDependency::LocateIncludedFile ( Module& module, if ( LocateIncludedFile ( include->directory, includedFilename, resolvedFilename ) ) + { + if ( includeNext && stricmp ( resolvedFilename.c_str (), + sourceFile->filename.c_str () ) == 0 ) + continue; return true; + } } resolvedFilename = ""; diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index 7f028861ddf..33208c84e13 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -63,7 +63,6 @@ public: std::vector properties; std::vector ifs; - //Project (); Project ( const std::string& filename ); ~Project (); void ProcessXML ( const std::string& path ); @@ -385,9 +384,11 @@ private: void Close (); void Open (); void SkipWhitespace (); - bool ReadInclude ( std::string& filename ); + bool ReadInclude ( std::string& filename, + bool& includeNext ); bool IsIncludedFrom ( const std::string& normalizedFilename ); SourceFile* GetParentSourceFile (); + bool CanProcessFile ( const std::string& extension ); bool IsParentOf ( const SourceFile* parent, const SourceFile* child ); std::string buf; @@ -405,11 +406,14 @@ public: AutomaticDependency ( const Project& project ); ~AutomaticDependency (); void Process (); + std::string GetFilename ( const std::string& filename ); bool LocateIncludedFile ( const std::string& directory, const std::string& includedFilename, std::string& resolvedFilename ); - bool LocateIncludedFile ( Module& module, + bool LocateIncludedFile ( SourceFile* sourceFile, + Module& module, const std::string& includedFilename, + bool includeNext, std::string& resolvedFilename ); SourceFile* RetrieveFromCacheOrParse ( Module& module, const std::string& filename, diff --git a/reactos/tools/rbuild/test.h b/reactos/tools/rbuild/test.h index 536c7e81099..fe5becc09a8 100644 --- a/reactos/tools/rbuild/test.h +++ b/reactos/tools/rbuild/test.h @@ -8,37 +8,38 @@ class BaseTest { public: bool Failed; - BaseTest(); - virtual ~BaseTest(); - virtual void Run() = 0; + BaseTest (); + virtual ~BaseTest (); + virtual void Run () = 0; protected: - void Assert(const char *message, ...); - void IsNull(void* reference, - const char* file, - int line); - void IsNotNull(void* reference, - const char* file, - int line); - void IsTrue(bool condition, - const char* file, - int line); - void IsFalse(bool condition, - const char* file, - int line); - void AreEqual(int expected, - int actual, + void Assert ( const char *message, + ... ); + void IsNull ( void* reference, const char* file, - int line); - void AreEqual(const std::string& expected, - const std::string& actual, - const char* file, - int line); - void AreNotEqual(int expected, - int actual, + int line ); + void IsNotNull ( void* reference, const char* file, - int line); + int line ); + void IsTrue ( bool condition, + const char* file, + int line ); + void IsFalse ( bool condition, + const char* file, + int line ); + void AreEqual ( int expected, + int actual, + const char* file, + int line ); + void AreEqual ( const std::string& expected, + const std::string& actual, + const char* file, + int line ); + void AreNotEqual ( int expected, + int actual, + const char* file, + int line ); private: - void Fail(); + void Fail (); }; #define IS_NULL(reference) IsNull((void*)reference,__FILE__,__LINE__) @@ -51,63 +52,65 @@ private: class ProjectTest : public BaseTest { public: - void Run(); + void Run (); }; class ModuleTest : public BaseTest { public: - void Run(); + void Run (); }; class DefineTest : public BaseTest { public: - void Run(); + void Run (); }; class IncludeTest : public BaseTest { public: - void Run(); + void Run (); }; class InvokeTest : public BaseTest { public: - void Run(); + void Run (); }; class LinkerFlagTest : public BaseTest { public: - void Run(); + void Run (); }; class IfTest : public BaseTest { public: - void Run(); + void Run (); }; class FunctionTest : public BaseTest { public: - void Run(); + void Run (); }; class SourceFileTest : public BaseTest { public: - void Run(); + void Run (); + void IncludeTest (); + void FullParseTest (); private: bool IsParentOf ( const SourceFile* parent, const SourceFile* child ); diff --git a/reactos/tools/rbuild/tests/data/automaticdependency_include.xml b/reactos/tools/rbuild/tests/data/automaticdependency_include.xml new file mode 100644 index 00000000000..8dcf7205039 --- /dev/null +++ b/reactos/tools/rbuild/tests/data/automaticdependency_include.xml @@ -0,0 +1,12 @@ + + + + + + . + sourcefile1 + sourcefile_include.c + + + + diff --git a/reactos/tools/rbuild/tests/data/sourcefile1/sourcefile_includenext.h b/reactos/tools/rbuild/tests/data/sourcefile1/sourcefile_includenext.h new file mode 100644 index 00000000000..ab79b95a5f7 --- /dev/null +++ b/reactos/tools/rbuild/tests/data/sourcefile1/sourcefile_includenext.h @@ -0,0 +1 @@ +/* empty */ diff --git a/reactos/tools/rbuild/tests/data/sourcefile_include.c b/reactos/tools/rbuild/tests/data/sourcefile_include.c new file mode 100644 index 00000000000..373a64d4dcc --- /dev/null +++ b/reactos/tools/rbuild/tests/data/sourcefile_include.c @@ -0,0 +1,2 @@ +# include +#include diff --git a/reactos/tools/rbuild/tests/data/sourcefile_include.h b/reactos/tools/rbuild/tests/data/sourcefile_include.h new file mode 100644 index 00000000000..ab79b95a5f7 --- /dev/null +++ b/reactos/tools/rbuild/tests/data/sourcefile_include.h @@ -0,0 +1 @@ +/* empty */ diff --git a/reactos/tools/rbuild/tests/data/sourcefile_includenext.h b/reactos/tools/rbuild/tests/data/sourcefile_includenext.h new file mode 100644 index 00000000000..f02b86b654d --- /dev/null +++ b/reactos/tools/rbuild/tests/data/sourcefile_includenext.h @@ -0,0 +1 @@ +#include_next diff --git a/reactos/tools/rbuild/tests/sourcefiletest.cpp b/reactos/tools/rbuild/tests/sourcefiletest.cpp index 699d5380056..93d216d2c24 100644 --- a/reactos/tools/rbuild/tests/sourcefiletest.cpp +++ b/reactos/tools/rbuild/tests/sourcefiletest.cpp @@ -32,9 +32,22 @@ SourceFileTest::IsParentOf ( const SourceFile* parent, } void -SourceFileTest::Run () +SourceFileTest::IncludeTest () { - const Project project ( "tests/data/automaticdependency.xml" ); + const Project project ( "tests" SSEP "data" SSEP "automaticdependency_include.xml" ); + AutomaticDependency automaticDependency ( project ); + automaticDependency.Process (); + ARE_EQUAL( 4, automaticDependency.sourcefile_map.size () ); + const SourceFile* include = automaticDependency.RetrieveFromCache ( "tests" SSEP "data" SSEP "sourcefile_include.h" ); + IS_NOT_NULL( include ); + const SourceFile* includenext = automaticDependency.RetrieveFromCache ( "tests" SSEP "data" SSEP "sourcefile1" SSEP "sourcefile_includenext.h" ); + IS_NOT_NULL( includenext ); +} + +void +SourceFileTest::FullParseTest () +{ + const Project project ( "tests" SSEP "data" SSEP "automaticdependency.xml" ); AutomaticDependency automaticDependency ( project ); automaticDependency.Process (); ARE_EQUAL( 5, automaticDependency.sourcefile_map.size () ); @@ -46,4 +59,12 @@ SourceFileTest::Run () recurse ) ); IS_FALSE( IsParentOf ( recurse, header1 ) ); + +} + +void +SourceFileTest::Run () +{ + IncludeTest (); + FullParseTest (); }