Use automatic dependencies to mark files to be rebuilt. Modified: branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp 2005-02-01 17:54:25 UTC (rev 13384) +++ branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp 2005-02-01 20:49:03 UTC (rev 13385) @@ -1,12 +1,4 @@
#include "pch.h" - -#ifdef WIN32 -#include <direct.h> -#include <io.h> -#else -#include <sys/stat.h> -#define _MAX_PATH 255 -#endif #include <assert.h>
#include "rbuild.h" @@ -26,7 +18,8 @@ : automaticDependency ( automaticDependency ), module ( module ), filename ( filename ), - isNonAutomaticDependency ( isNonAutomaticDependency ) + isNonAutomaticDependency ( isNonAutomaticDependency ), + youngestLastWriteTime ( 0 ) { if ( parent != NULL ) parents.push_back ( parent ); @@ -59,12 +52,25 @@ void SourceFile::Open () { + struct stat statbuf; + Close (); FILE* f = fopen ( filename.c_str (), "rb" ); if ( !f ) throw FileNotFoundException ( filename ); + + if ( fstat ( fileno ( f ), &statbuf ) != 0 ) + { + fclose ( f ); + throw AccessDeniedException ( filename ); + } + lastWriteTime = statbuf.st_mtime; +/* printf ( "lastWriteTime of %s is %s\n", + filename.c_str (), + ctime ( &lastWriteTime ) ); */ + unsigned long len = (unsigned long) filelen ( f ); - if ( len > MAX_BYTES_TO_READ) + if ( len > MAX_BYTES_TO_READ ) len = MAX_BYTES_TO_READ; buf.resize ( len ); fread ( &buf[0], 1, len, f ); @@ -325,3 +331,76 @@ { return sourcefile_map[filename]; } + +void +AutomaticDependency::CheckAutomaticDependencies () +{ + struct utimbuf timebuf; + for ( size_t mi = 0; mi < project.modules.size (); mi++ ) + { + Module& module = *project.modules[mi]; + for ( size_t fi = 0; fi < module.files.size (); fi++ ) + { + File& file = *module.files[fi]; + string normalizedFilename = NormalizeFilename ( file.name ); + + SourceFile* sourceFile = RetrieveFromCache ( normalizedFilename ); + if ( sourceFile != NULL ) + { + CheckAutomaticDependenciesForFile ( sourceFile ); + assert ( sourceFile->youngestLastWriteTime != 0 ); + if ( sourceFile->youngestLastWriteTime > sourceFile->lastWriteTime ) + { + printf ( "Marking %s for rebuild\n", + sourceFile->filename.c_str () ); + timebuf.actime = sourceFile->youngestLastWriteTime; + timebuf.modtime = sourceFile->youngestLastWriteTime; + utime ( sourceFile->filename.c_str (), + &timebuf ); + + /*printf ( "lastWriteTime of %s is %s\n", + sourceFile->filename.c_str (), + ctime ( &sourceFile->lastWriteTime ) ); + printf ( "youngestLastWriteTime is %s with %s\n", + sourceFile->youngestFile->filename.c_str (), + ctime ( &sourceFile->youngestLastWriteTime ) );*/ + } + } + } + } +} + +void +AutomaticDependency::CheckAutomaticDependenciesForFile ( SourceFile* sourceFile ) +{ + if ( sourceFile->youngestLastWriteTime > 0 ) + return; + + if ( sourceFile->files.size () == 0 ) + { + sourceFile->youngestLastWriteTime = sourceFile->lastWriteTime; + sourceFile->youngestFile = sourceFile; + return; + } + + for ( size_t i = 0; i < sourceFile->files.size (); i++ ) + { + SourceFile* childSourceFile = sourceFile->files[i]; + + CheckAutomaticDependenciesForFile ( childSourceFile ); + if ( ( childSourceFile->youngestLastWriteTime > sourceFile->youngestLastWriteTime ) || + ( childSourceFile->lastWriteTime > sourceFile->youngestLastWriteTime ) ) + { + if ( childSourceFile->youngestLastWriteTime > childSourceFile->lastWriteTime ) + { + sourceFile->youngestLastWriteTime = childSourceFile->youngestLastWriteTime; + sourceFile->youngestFile = childSourceFile->youngestFile; + } + else + { + sourceFile->youngestLastWriteTime = childSourceFile->lastWriteTime; + sourceFile->youngestFile = childSourceFile; + } + } + } +} _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-02-01 17:54:25 UTC (rev 13384) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-02-01 20:49:03 UTC (rev 13385) @@ -19,8 +19,7 @@
MingwBackend::MingwBackend ( Project& project ) - : Backend ( project ), - automaticDependencyUniqueIdCounter ( 0 ) + : Backend ( project ) { }
@@ -36,7 +35,7 @@ Module& module = *ProjectNode.modules[i]; ProcessModule ( module ); } - //GenerateAutomaticDependencies (); + CheckAutomaticDependencies (); CloseMakefile (); }
@@ -241,136 +240,15 @@ fprintf ( fMakefile, "\n\t\n\n" ); }
-string* -MingwBackend::GenerateAutomaticDependencyUniqueId () -{ - automaticDependencyUniqueIdCounter++; - return new string ( ssprintf ( "d%d", - automaticDependencyUniqueIdCounter ) ); -} - void -MingwBackend::GenerateAutomaticDependencies () +MingwBackend::CheckAutomaticDependencies () { AutomaticDependency automaticDependency ( ProjectNode ); automaticDependency.Process (); - for ( size_t mi = 0; mi < ProjectNode.modules.size (); mi++ ) - { - Module& module = *ProjectNode.modules[mi]; - for ( size_t fi = 0; fi < module.files.size (); fi++ ) - { - File& file = *module.files[fi]; - string normalizedFilename = NormalizeFilename ( file.name ); - - SourceFile* sourceFile = automaticDependency.RetrieveFromCache ( normalizedFilename ); - if ( sourceFile != NULL ) - { - string dependencies ( "" ); - GenerateAutomaticDependenciesForFileCached ( sourceFile, - dependencies ); - if ( dependencies.size () > 0 ) - { - const string& objectFilename = MingwModuleHandler::GetObjectFilename ( normalizedFilename ); - string* uniqueId = automaticDependencyMap[dependencies]; - if ( uniqueId == NULL ) - { - uniqueId = GenerateAutomaticDependencyUniqueId (); - automaticDependencyMap[dependencies] = uniqueId; - fprintf ( fMakefile, - "%s = %s\n", - uniqueId->c_str (), - dependencies.c_str () ); - } - fprintf ( fMakefile, - "%s: $(%s)\n", - objectFilename.c_str (), - uniqueId->c_str () ); - } - } - } - } + automaticDependency.CheckAutomaticDependencies (); }
-string -MingwBackend::GetFilename ( const string& filename ) const -{ - size_t index = filename.find_last_of ( CSEP ); - if ( index == string::npos ) - return filename; - else - return filename.substr ( index + 1, filename.length () - index ); -} - void -MingwBackend::GenerateAutomaticDependenciesForFileCached ( SourceFile* sourceFile, - string& dependencies ) -{ - for ( size_t i = 0; i < sourceFile->files.size (); i++) - { - SourceFile* childSourceFile = sourceFile->files[i]; - - string* uniqueId = automaticDependencyDirectoryMap[childSourceFile->directoryPart]; - if ( uniqueId == NULL ) - { - uniqueId = GenerateAutomaticDependencyUniqueId (); - automaticDependencyDirectoryMap[childSourceFile->directoryPart] = uniqueId; - fprintf ( fMakefile, - "%s = %s\n", - uniqueId->c_str (), - childSourceFile->directoryPart.c_str () ); - } - dependencies += ssprintf ( "${%s}%s%s", - uniqueId->c_str (), - SSEP, - childSourceFile->filenamePart.c_str () ); - - string childDependencies; - if ( childSourceFile->cachedDependencies.length () > 0 ) - childDependencies = childSourceFile->cachedDependencies; - else - { - GenerateAutomaticDependenciesForFile ( childSourceFile, - childDependencies ); - if ( childDependencies.length () > 200 ) - { - childSourceFile->cachedDependencies = childDependencies; - } - } - dependencies += " " + childDependencies; - } -} - -void -MingwBackend::GenerateAutomaticDependenciesForFile ( SourceFile* sourceFile, - string& dependencies ) -{ - for ( size_t i = 0; i < sourceFile->files.size (); i++ ) - { - SourceFile* childSourceFile = sourceFile->files[i]; - - if ( dependencies.length () > 0 ) - dependencies += " "; - - string* uniqueId = automaticDependencyDirectoryMap[childSourceFile->directoryPart]; - if ( uniqueId == NULL ) - { - uniqueId = GenerateAutomaticDependencyUniqueId (); - automaticDependencyDirectoryMap[childSourceFile->directoryPart] = uniqueId; - fprintf ( fMakefile, - "%s = %s\n", - uniqueId->c_str (), - childSourceFile->directoryPart.c_str () ); - } - dependencies += ssprintf ( "${%s}%s%s", - uniqueId->c_str (), - SSEP, - childSourceFile->filenamePart.c_str () ); - GenerateAutomaticDependenciesForFile ( childSourceFile, - dependencies ); - } -} - -void MingwBackend::ProcessModule ( Module& module ) const { MingwModuleHandler* h = MingwModuleHandler::LookupHandler ( _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-02-01 17:54:25 UTC (rev 13384) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-02-01 20:49:03 UTC (rev 13385) @@ -28,19 +28,8 @@
void GenerateGlobalVariables () const; bool IncludeInAllTarget ( const Module& module ) const; void GenerateAllTarget () const; - std::string* GenerateAutomaticDependencyUniqueId (); - void GenerateAutomaticDependencies (); - bool IsAutomaticDependencyGenerated ( SourceFile* sourceFile ); - void OutputAutomaticDependenciesForFile ( SourceFile* sourceFile ); - std::string GetFilename ( const std::string& filename ) const; - void GenerateAutomaticDependenciesForFileCached ( SourceFile* sourceFile, - std::string& dependencies ); - void GenerateAutomaticDependenciesForFile ( SourceFile* sourceFile, - std::string& dependencies ); + void CheckAutomaticDependencies (); FILE* fMakefile; - int automaticDependencyUniqueIdCounter; - std::map<std::string, std::string*> automaticDependencyMap; - std::map<std::string, std::string*> automaticDependencyDirectoryMap; };
std::string FixupTargetFilename ( const std::string& targetFilename ); _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h --- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-02-01 17:54:25 UTC (rev 13384) +++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-02-01 20:49:03 UTC (rev 13385) @@ -3,6 +3,16 @@
#include "pch.h"
+#ifdef WIN32 +#include <direct.h> +#include <io.h> +#else +#define _MAX_PATH 255 +#endif +#include <sys/stat.h> +#include <time.h> +#include <utime.h> + #include "ssprintf.h" #include "exception.h" #include "XML.h" @@ -367,6 +377,9 @@ std::vector<SourceFile*> parents; /* List of files, this file is included from */ bool isNonAutomaticDependency; std::string cachedDependencies; + time_t lastWriteTime; + time_t youngestLastWriteTime; /* Youngest last write time of this file and all children */ + SourceFile* youngestFile; private: void GetDirectoryAndFilenameParts (); void Close (); @@ -402,6 +415,8 @@ const std::string& filename, SourceFile* parentSourceFile ); SourceFile* RetrieveFromCache ( const std::string& filename ); + void CheckAutomaticDependencies (); + void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile ); private: void ProcessModule ( Module& module ); void ProcessFile ( Module& module,