From b102fa96a8df4d3ef29ed72b7323e039c96b9e6c Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Tue, 22 Nov 2005 22:16:14 +0000 Subject: [PATCH] * Name compilation unit * Generate compilation unit support code svn path=/trunk/; revision=19470 --- .../tools/rbuild/backend/devcpp/devcpp.cpp | 8 +- reactos/tools/rbuild/backend/mingw/mingw.cpp | 10 ++ reactos/tools/rbuild/backend/mingw/mingw.h | 1 + .../rbuild/backend/mingw/modulehandler.cpp | 140 ++++++++++++------ .../rbuild/backend/mingw/modulehandler.h | 17 ++- reactos/tools/rbuild/compilationunit.cpp | 19 +-- .../rbuild/compilationunitsupportcode.cpp | 99 +++++++++++++ reactos/tools/rbuild/doc/rbuild.txt | 4 +- reactos/tools/rbuild/project.cpp | 9 ++ reactos/tools/rbuild/rbuild.h | 32 +++- reactos/tools/rbuild/rbuild.mak | 5 + reactos/tools/rbuild/testsupportcode.cpp | 6 +- 12 files changed, 276 insertions(+), 74 deletions(-) create mode 100644 reactos/tools/rbuild/compilationunitsupportcode.cpp diff --git a/reactos/tools/rbuild/backend/devcpp/devcpp.cpp b/reactos/tools/rbuild/backend/devcpp/devcpp.cpp index 58f7b574ef7..a2328cb9385 100644 --- a/reactos/tools/rbuild/backend/devcpp/devcpp.cpp +++ b/reactos/tools/rbuild/backend/devcpp/devcpp.cpp @@ -129,11 +129,11 @@ void DevCppBackend::ProcessModules() { Module &module = *ProjectNode.modules[i]; - for(size_t k = 0; k < module.non_if_data.compilationUnits.size(); k++) + for(size_t k = 0; k < module.non_if_data.files.size(); k++) { - CompilationUnit &compilationUnit = *module.non_if_data.compilationUnits[k]; - string filename = compilationUnit.GetFilename(); - ProcessFile(filename); + File &file = *module.non_if_data.files[k]; + + ProcessFile(file.name); } } } diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index f1e25ee807b..42876579cc9 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -193,6 +193,7 @@ MingwBackend::ProcessNormal () GenerateDirectories (); UnpackWineResources (); GenerateTestSupportCode (); + GenerateCompilationUnitSupportCode (); GenerateProxyMakefiles (); CheckAutomaticDependencies (); CloseMakefile (); @@ -523,6 +524,15 @@ MingwBackend::GenerateTestSupportCode () printf ( "done\n" ); } +void +MingwBackend::GenerateCompilationUnitSupportCode () +{ + printf ( "Generating compilation unit support code..." ); + CompilationUnitSupportCode compilationUnitSupportCode ( ProjectNode ); + compilationUnitSupportCode.Generate ( configuration.Verbose ); + printf ( "done\n" ); +} + string MingwBackend::GetProxyMakefileTree () const { diff --git a/reactos/tools/rbuild/backend/mingw/mingw.h b/reactos/tools/rbuild/backend/mingw/mingw.h index effe409cc93..a4237044013 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.h +++ b/reactos/tools/rbuild/backend/mingw/mingw.h @@ -77,6 +77,7 @@ private: std::string GetBin2ResExecutable (); void UnpackWineResources (); void GenerateTestSupportCode (); + void GenerateCompilationUnitSupportCode (); std::string GetProxyMakefileTree () const; void GenerateProxyMakefiles (); void CheckAutomaticDependencies (); diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index 1f006f81c6b..a4b3e6fc900 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -121,6 +121,8 @@ MingwModuleHandler::PassThruCacheDirectory ( Directory* directoryTree ) { string directory ( GetDirectory ( RemoveVariables ( file ) ) ); + if ( directoryTree == NULL ) + return file; string generatedFilesDirectory = backend->AddDirectoryTarget ( directory, directoryTree ); if ( directory.find ( generatedFilesDirectory ) != string::npos ) @@ -134,6 +136,13 @@ MingwModuleHandler::PassThruCacheDirectory ( } } +/*static*/ string +MingwModuleHandler::PassThruCacheDirectory (const FileLocation* fileLocation ) +{ + return PassThruCacheDirectory ( fileLocation->filename, + fileLocation->directory ); +} + /*static*/ Directory* MingwModuleHandler::GetTargetDirectoryTree ( const Module& module ) @@ -264,16 +273,18 @@ MingwModuleHandler::GetBasename ( const string& filename ) const return ""; } -string +FileLocation* MingwModuleHandler::GetActualSourceFilename ( - const string& filename ) const + const FileLocation* fileLocation ) const { + string filename = fileLocation->filename; string extension = GetExtension ( filename ); if ( extension == ".spec" || extension == ".SPEC" ) { string basename = GetBasename ( filename ); - return PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ), - backend->intermediateDirectory ); + PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ), + backend->intermediateDirectory ); + return new FileLocation ( backend->intermediateDirectory, NormalizeFilename ( basename + ".stubs.c" ) ); } else if ( extension == ".idl" || extension == ".IDL" ) { @@ -283,11 +294,12 @@ MingwModuleHandler::GetActualSourceFilename ( newname = basename + "_s.c"; else newname = basename + "_c.c"; - return PassThruCacheDirectory ( NormalizeFilename ( newname ), - backend->intermediateDirectory ); + PassThruCacheDirectory ( NormalizeFilename ( newname ), + backend->intermediateDirectory ); + return new FileLocation ( backend->intermediateDirectory, NormalizeFilename ( newname ) ); } else - return filename; + return new FileLocation ( fileLocation->directory, filename ); } string @@ -304,6 +316,21 @@ MingwModuleHandler::GetExtraDependencies ( return ""; } +string +MingwModuleHandler::GetCompilationUnitDependencies ( + const CompilationUnit& compilationUnit ) const +{ + if ( compilationUnit.files.size () <= 1 ) + return ""; + vector sourceFiles; + for ( size_t i = 0; i < compilationUnit.files.size (); i++ ) + { + File& file = *compilationUnit.files[i]; + sourceFiles.push_back ( NormalizeFilename ( file.name ) ); + } + return v2s ( sourceFiles, 10 ); +} + string MingwModuleHandler::GetModuleArchiveFilename () const { @@ -393,7 +420,10 @@ MingwModuleHandler::GetSourceFilenames ( string_list& list, { if ( includeGeneratedFiles || !compilationUnits[i]->IsGeneratedFile () ) { - list.push_back ( GetActualSourceFilename ( compilationUnits[i]->GetFilename () ) ); + FileLocation* sourceFileLocation = GetActualSourceFilename ( + compilationUnits[i]->GetFilename ( backend->intermediateDirectory ) ); + list.push_back ( PassThruCacheDirectory ( sourceFileLocation->filename, + sourceFileLocation->directory ) ); } } // intentionally make a copy so that we can append more work in @@ -412,7 +442,12 @@ MingwModuleHandler::GetSourceFilenames ( string_list& list, { CompilationUnit& compilationUnit = *compilationUnits[j]; if ( includeGeneratedFiles || !compilationUnit.IsGeneratedFile () ) - list.push_back ( GetActualSourceFilename ( compilationUnit.GetFilename () ) ); + { + FileLocation* sourceFileLocation = GetActualSourceFilename ( + compilationUnit.GetFilename ( backend->intermediateDirectory ) ); + list.push_back ( PassThruCacheDirectory ( sourceFileLocation->filename, + sourceFileLocation->directory ) ); + } } } } @@ -426,11 +461,11 @@ MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( string MingwModuleHandler::GetObjectFilename ( - const string& sourceFilename, + const FileLocation* sourceFileLocation, string_list* pclean_files ) const { + string sourceFilename = sourceFileLocation->filename; Directory* directoryTree; - string newExtension; string extension = GetExtension ( sourceFilename ); if ( extension == ".rc" || extension == ".RC" ) @@ -550,7 +585,7 @@ MingwModuleHandler::GetObjectFilenames () { if ( objectFilenames.size () > 0 ) objectFilenames += " "; - objectFilenames += GetObjectFilename ( compilationUnits[i]->GetFilename (), NULL ); + objectFilenames += GetObjectFilename ( compilationUnits[i]->GetFilename ( backend->intermediateDirectory ), NULL ); } return objectFilenames; } @@ -851,7 +886,7 @@ MingwModuleHandler::GenerateObjectMacros ( fprintf ( fMakefile, "%s := %s $(%s)\n", objectsMacro.c_str(), - GetObjectFilename ( compilationUnit.GetFilename (), NULL ).c_str (), + GetObjectFilename ( compilationUnit.GetFilename ( backend->intermediateDirectory ), NULL ).c_str (), objectsMacro.c_str() ); } } @@ -869,7 +904,7 @@ MingwModuleHandler::GenerateObjectMacros ( fMakefile, "%s%s", ( i%10 == 9 ? " \\\n\t" : " " ), - GetObjectFilename ( compilationUnit.GetFilename (), NULL ).c_str () ); + GetObjectFilename ( compilationUnit.GetFilename ( backend->intermediateDirectory ), NULL ).c_str () ); } } fprintf ( fMakefile, "\n" ); @@ -910,7 +945,7 @@ MingwModuleHandler::GenerateObjectMacros ( fMakefile, "%s += %s\n", objectsMacro.c_str(), - GetObjectFilename ( sourceCompilationUnits[i]->GetFilename (), NULL ).c_str () ); + GetObjectFilename ( sourceCompilationUnits[i]->GetFilename ( backend->intermediateDirectory ), NULL ).c_str () ); } CleanupCompilationUnitVector ( sourceCompilationUnits ); } @@ -925,11 +960,12 @@ MingwModuleHandler::GetPrecompiledHeaderFilename () const void MingwModuleHandler::GenerateGccCommand ( - const string& sourceFilename, + const FileLocation* sourceFileLocation, const string& extraDependencies, const string& cc, const string& cflagsMacro ) { + string sourceFilename = PassThruCacheDirectory ( sourceFileLocation ); string dependencies = sourceFilename; if ( extraDependencies != "" ) dependencies += " " + extraDependencies; @@ -943,7 +979,7 @@ MingwModuleHandler::GenerateGccCommand ( dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); string objectFilename = GetObjectFilename ( - sourceFilename, &clean_files ); + sourceFileLocation, &clean_files ); fprintf ( fMakefile, "%s: %s | %s\n", objectFilename.c_str (), @@ -958,14 +994,15 @@ MingwModuleHandler::GenerateGccCommand ( void MingwModuleHandler::GenerateGccAssemblerCommand ( - const string& sourceFilename, + const FileLocation* sourceFileLocation, const string& cc, const string& cflagsMacro ) { + string sourceFilename = PassThruCacheDirectory ( sourceFileLocation ); string dependencies = sourceFilename; dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); string objectFilename = GetObjectFilename ( - sourceFilename, &clean_files ); + sourceFileLocation, &clean_files ); fprintf ( fMakefile, "%s: %s | %s\n", objectFilename.c_str (), @@ -980,13 +1017,14 @@ MingwModuleHandler::GenerateGccAssemblerCommand ( void MingwModuleHandler::GenerateNasmCommand ( - const string& sourceFilename, + const FileLocation* sourceFileLocation, const string& nasmflagsMacro ) { + string sourceFilename = PassThruCacheDirectory ( sourceFileLocation ); string dependencies = sourceFilename; dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); string objectFilename = GetObjectFilename ( - sourceFilename, &clean_files ); + sourceFileLocation, &clean_files ); fprintf ( fMakefile, "%s: %s | %s\n", objectFilename.c_str (), @@ -1001,13 +1039,13 @@ MingwModuleHandler::GenerateNasmCommand ( void MingwModuleHandler::GenerateWindresCommand ( - const string& sourceFilename, + const FileLocation* sourceFileLocation, const string& windresflagsMacro ) { + string sourceFilename = PassThruCacheDirectory ( sourceFileLocation ); string dependencies = sourceFilename; dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); - string objectFilename = - GetObjectFilename ( sourceFilename, &clean_files ); + string objectFilename = GetObjectFilename ( sourceFileLocation, &clean_files ); string sourceFilenamePart = ReplaceExtension ( GetFilename ( sourceFilename ), "" ); string rciFilename = ros_temp + module.name + "." + sourceFilenamePart + ".rci.tmp"; string resFilename = ros_temp + module.name + "." + sourceFilenamePart + ".res.tmp"; @@ -1056,8 +1094,9 @@ MingwModuleHandler::GenerateWindresCommand ( void MingwModuleHandler::GenerateWinebuildCommands ( - const string& sourceFilename ) + const FileLocation* sourceFileLocation ) { + string sourceFilename = PassThruCacheDirectory ( sourceFileLocation ); string dependencies = sourceFilename; dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); @@ -1113,7 +1152,8 @@ MingwModuleHandler::GenerateWidlCommandsServer ( const CompilationUnit& compilationUnit, const string& widlflagsMacro ) { - string filename = compilationUnit.GetFilename (); + FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory ); + string filename = sourceFileLocation->filename; string dependencies = filename; dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); @@ -1156,7 +1196,8 @@ MingwModuleHandler::GenerateWidlCommandsClient ( const CompilationUnit& compilationUnit, const string& widlflagsMacro ) { - string filename = compilationUnit.GetFilename (); + FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory ); + string filename = sourceFileLocation->filename; string dependencies = filename; dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); @@ -1210,12 +1251,13 @@ MingwModuleHandler::GenerateCommands ( const string& windresflagsMacro, const string& widlflagsMacro ) { - string filename = compilationUnit.GetFilename (); + FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory ); + string filename = sourceFileLocation->filename; string extension = GetExtension ( filename ); if ( extension == ".c" || extension == ".C" ) { - GenerateGccCommand ( filename, - "", + GenerateGccCommand ( sourceFileLocation, + GetCompilationUnitDependencies ( compilationUnit ), cc, cflagsMacro ); return; @@ -1224,35 +1266,35 @@ MingwModuleHandler::GenerateCommands ( extension == ".cpp" || extension == ".CPP" || extension == ".cxx" || extension == ".CXX" ) { - GenerateGccCommand ( filename, - "", + GenerateGccCommand ( sourceFileLocation, + GetCompilationUnitDependencies ( compilationUnit ), cppc, cflagsMacro ); return; } else if ( extension == ".s" || extension == ".S" ) { - GenerateGccAssemblerCommand ( filename, + GenerateGccAssemblerCommand ( sourceFileLocation, cc, cflagsMacro ); return; } else if ( extension == ".asm" || extension == ".ASM" ) { - GenerateNasmCommand ( filename, + GenerateNasmCommand ( sourceFileLocation, nasmflagsMacro ); return; } else if ( extension == ".rc" || extension == ".RC" ) { - GenerateWindresCommand ( filename, + GenerateWindresCommand ( sourceFileLocation, windresflagsMacro ); return; } else if ( extension == ".spec" || extension == ".SPEC" ) { - GenerateWinebuildCommands ( filename ); - GenerateGccCommand ( GetActualSourceFilename ( filename ), + GenerateWinebuildCommands ( sourceFileLocation ); + GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation ), "", cc, cflagsMacro ); @@ -1262,7 +1304,7 @@ MingwModuleHandler::GenerateCommands ( { GenerateWidlCommands ( compilationUnit, widlflagsMacro ); - GenerateGccCommand ( GetActualSourceFilename ( filename ), + GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation ), GetExtraDependencies ( filename ), cc, cflagsMacro ); @@ -1369,7 +1411,7 @@ MingwModuleHandler::GetObjectsVector ( const IfableData& data, for ( size_t i = 0; i < data.compilationUnits.size (); i++ ) { CompilationUnit& compilationUnit = *data.compilationUnits[i]; - objectFiles.push_back ( GetObjectFilename ( compilationUnit.GetFilename (), NULL ) ); + objectFiles.push_back ( GetObjectFilename ( compilationUnit.GetFilename ( backend->intermediateDirectory ), NULL ) ); } } @@ -1701,11 +1743,11 @@ MingwModuleHandler::GetRpcHeaderDependencies ( for ( size_t j = 0; j < library.importedModule->non_if_data.compilationUnits.size (); j++ ) { CompilationUnit& compilationUnit = *library.importedModule->non_if_data.compilationUnits[j]; - string filename = compilationUnit.GetFilename (); - string extension = GetExtension ( filename ); + FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory ); + string extension = GetExtension ( sourceFileLocation->filename ); if ( extension == ".idl" || extension == ".IDL" ) { - string basename = GetBasename ( filename ); + string basename = GetBasename ( sourceFileLocation->filename ); if ( library.importedModule->type == RpcServer ) dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) ); if ( library.importedModule->type == RpcClient ) @@ -1739,10 +1781,10 @@ MingwModuleHandler::GenerateOtherMacros () for ( size_t i = 0; i < compilationUnits.size (); i++ ) { CompilationUnit& compilationUnit = *compilationUnits[i]; - string filename = compilationUnit.GetFilename (); - string extension = GetExtension ( filename ); + FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory ); + string extension = GetExtension ( sourceFileLocation->filename ); if ( extension == ".spec" || extension == ".SPEC" ) - GetSpecObjectDependencies ( s, filename ); + GetSpecObjectDependencies ( s, sourceFileLocation->filename ); } } if ( s.size () > 0 ) @@ -2094,12 +2136,12 @@ MingwModuleHandler::GetDefinitionDependencies ( for ( size_t i = 0; i < compilationUnits.size (); i++ ) { CompilationUnit& compilationUnit = *compilationUnits[i]; - string filename = compilationUnit.GetFilename (); - string extension = GetExtension ( filename ); + FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory ); + string extension = GetExtension ( sourceFileLocation->filename ); if ( extension == ".spec" || extension == ".SPEC" ) - GetSpecObjectDependencies ( dependencies, filename ); + GetSpecObjectDependencies ( dependencies, sourceFileLocation->filename ); if ( extension == ".idl" || extension == ".IDL" ) - GetWidlObjectDependencies ( dependencies, filename ); + GetWidlObjectDependencies ( dependencies, sourceFileLocation->filename ); } } diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index 2786f837983..9bc19e5306f 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -45,6 +45,8 @@ public: const std::string &f, Directory* directoryTree ); + static std::string PassThruCacheDirectory (const FileLocation* fileLocation ); + static Directory* GetTargetDirectoryTree ( const Module& module ); @@ -84,8 +86,9 @@ protected: virtual void GetModuleSpecificCompilationUnits ( std::vector& compilationUnits ); std::string GetWorkingDirectory () const; std::string GetBasename ( const std::string& filename ) const; - std::string GetActualSourceFilename ( const std::string& filename ) const; + FileLocation* GetActualSourceFilename ( const FileLocation* fileLocation ) const; std::string GetExtraDependencies ( const std::string& filename ) const; + std::string MingwModuleHandler::GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const; std::string GetModuleArchiveFilename () const; bool IsGeneratedFile ( const File& file ) const; std::string GetImportLibraryDependency ( const Module& importedModule ); @@ -96,7 +99,7 @@ protected: void GetSourceFilenames ( string_list& list, bool includeGeneratedFiles ) const; void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const; - std::string GetObjectFilename ( const std::string& sourceFilename, + std::string GetObjectFilename ( const FileLocation* sourceFileLocation, string_list* pclean_files ) const; std::string GetObjectFilenames (); @@ -144,18 +147,18 @@ private: std::string GenerateGccParameters () const; std::string GenerateNasmParameters () const; std::string MingwModuleHandler::GetPrecompiledHeaderFilename () const; - void GenerateGccCommand ( const std::string& sourceFilename, + void GenerateGccCommand ( const FileLocation* sourceFileLocation, const std::string& extraDependencies, const std::string& cc, const std::string& cflagsMacro ); - void GenerateGccAssemblerCommand ( const std::string& sourceFilename, + void GenerateGccAssemblerCommand ( const FileLocation* sourceFileLocation, const std::string& cc, const std::string& cflagsMacro ); - void GenerateNasmCommand ( const std::string& sourceFilename, + void GenerateNasmCommand ( const FileLocation* sourceFileLocation, const std::string& nasmflagsMacro ); - void GenerateWindresCommand ( const std::string& sourceFilename, + void GenerateWindresCommand ( const FileLocation* sourceFileLocation, const std::string& windresflagsMacro ); - void GenerateWinebuildCommands ( const std::string& sourceFilename ); + void GenerateWinebuildCommands ( const FileLocation* sourceFileLocation ); std::string GetWidlFlags ( const CompilationUnit& compilationUnit ); void GenerateWidlCommandsServer ( const CompilationUnit& compilationUnit, diff --git a/reactos/tools/rbuild/compilationunit.cpp b/reactos/tools/rbuild/compilationunit.cpp index 11888cbf9c7..2ac65499c7a 100644 --- a/reactos/tools/rbuild/compilationunit.cpp +++ b/reactos/tools/rbuild/compilationunit.cpp @@ -28,6 +28,7 @@ CompilationUnit::CompilationUnit ( File* file ) module(NULL), node(NULL) { + name = file->name; files.push_back ( file ); } @@ -38,6 +39,9 @@ CompilationUnit::CompilationUnit ( const Project* project, module(module), node(node) { + const XMLAttribute* att = node->GetAttribute ( "name", true ); + assert(att); + name = module->GetBasePath () + cSep + att->value; } CompilationUnit::~CompilationUnit () @@ -83,28 +87,25 @@ bool CompilationUnit::IsFirstFile () const { if ( files.size () == 0 || files.size () > 1 ) -{ -printf("fs:'%d'\n", files.size ()); - throw InvalidOperationException ( __FILE__, __LINE__ ); -} + return false; File* file = files[0]; return file->first; } -std::string -CompilationUnit::GetFilename () const +FileLocation* +CompilationUnit::GetFilename ( Directory* intermediateDirectory ) const { if ( files.size () == 0 || files.size () > 1 ) - throw InvalidOperationException ( __FILE__, __LINE__ ); + return new FileLocation ( intermediateDirectory, name ); File* file = files[0]; - return file->name; + return new FileLocation ( NULL, file->name ); } std::string CompilationUnit::GetSwitches () const { if ( files.size () == 0 || files.size () > 1 ) - throw InvalidOperationException ( __FILE__, __LINE__ ); + return ""; File* file = files[0]; return file->switches; } diff --git a/reactos/tools/rbuild/compilationunitsupportcode.cpp b/reactos/tools/rbuild/compilationunitsupportcode.cpp new file mode 100644 index 00000000000..c7541abdad6 --- /dev/null +++ b/reactos/tools/rbuild/compilationunitsupportcode.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2005 Casper S. Hornstrup + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "pch.h" +#include + +#include "rbuild.h" + +using std::string; +using std::vector; + +CompilationUnitSupportCode::CompilationUnitSupportCode ( const Project& project ) + : project ( project ) +{ +} + +CompilationUnitSupportCode::~CompilationUnitSupportCode () +{ +} + +void +CompilationUnitSupportCode::Generate ( bool verbose ) +{ + for ( size_t i = 0; i < project.modules.size (); i++ ) + { + GenerateForModule ( *project.modules[i], + verbose ); + } +} + +void +CompilationUnitSupportCode::GenerateForModule ( Module& module, + bool verbose ) +{ + if ( verbose ) + { + printf ( "\nGenerating compilation unit support code for %s", + module.name.c_str () ); + } + + for ( size_t i = 0; i < module.non_if_data.compilationUnits.size () ; i++ ) + { + CompilationUnit& compilationUnit = *module.non_if_data.compilationUnits[i]; + if ( compilationUnit.files.size () <= 1 ) + continue; + WriteCompilationUnitFile ( module, compilationUnit ); + } +} + +string +CompilationUnitSupportCode::GetCompilationUnitFilename ( Module& module, + CompilationUnit& compilationUnit ) +{ + return NormalizeFilename ( Environment::GetIntermediatePath () + sSep + compilationUnit.name ); +} + +void +CompilationUnitSupportCode::WriteCompilationUnitFile ( Module& module, + CompilationUnit& compilationUnit ) +{ + char* buf; + char* s; + + buf = (char*) malloc ( 512*1024 ); + if ( buf == NULL ) + throw OutOfMemoryException (); + + s = buf; + s = s + sprintf ( s, "/* This file is automatically generated. */\n" ); + s = s + sprintf ( s, "#define ONE_COMPILATION_UNIT\n" ); + if ( module.pch ) + s = s + sprintf ( s, "#include <%s>\n", NormalizeFilename ( module.pch->file.name ).c_str () ); + + for ( size_t i = 0; i < compilationUnit.files.size () ; i++ ) + { + File& file = *compilationUnit.files[i]; + s = s + sprintf ( s, "#include \"%s\"\n", file.name.c_str () ); + } + + s = s + sprintf ( s, "\n" ); + + FileSupportCode::WriteIfChanged ( buf, GetCompilationUnitFilename ( module, compilationUnit ) ); + + free ( buf ); +} diff --git a/reactos/tools/rbuild/doc/rbuild.txt b/reactos/tools/rbuild/doc/rbuild.txt index 832212f1c56..75cf87c9368 100644 --- a/reactos/tools/rbuild/doc/rbuild.txt +++ b/reactos/tools/rbuild/doc/rbuild.txt @@ -195,12 +195,12 @@ CompilationUnit element A compilationunit element specifies that one or more source code files are to be compiled as a single compilation unit. Syntax: - + ... Attributes: - None. + name - Name of generated source code file. Value: None. diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index 297a63e175a..e796dd84674 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -72,6 +72,15 @@ ParseContext::ParseContext () { } + +FileLocation::FileLocation ( Directory* directory, + std::string filename ) + : directory (directory), + filename (filename) +{ +} + + Project::Project ( const string& filename ) : xmlfile (filename), node (NULL), diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index 78d9eacf84a..e3d9c4d0f5c 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -93,6 +93,7 @@ class PchFile; class StubbedComponent; class StubbedSymbol; class CompilationUnit; +class FileLocation; class SourceFileTest; @@ -817,6 +818,7 @@ public: const Project* project; const Module* module; const XMLElement* node; + std::string name; std::vector files; CompilationUnit ( File* file ); @@ -828,11 +830,39 @@ public: bool IsGeneratedFile () const; bool HasFileWithExtension ( const std::string& extension ) const; bool IsFirstFile () const; - std::string GetFilename () const; + FileLocation* GetFilename ( Directory* intermediateDirectory ) const; std::string GetSwitches () const; }; +class CompilationUnitSupportCode +{ +public: + const Project& project; + + CompilationUnitSupportCode ( const Project& project ); + ~CompilationUnitSupportCode (); + void Generate ( bool verbose ); +private: + void GenerateForModule ( Module& module, + bool verbose ); + std::string GetCompilationUnitFilename ( Module& module, + CompilationUnit& compilationUnit ); + void WriteCompilationUnitFile ( Module& module, + CompilationUnit& compilationUnit ); +}; + + +class FileLocation +{ +public: + Directory* directory; + std::string filename; + FileLocation ( Directory* directory, + std::string filename ); +}; + + extern void InitializeEnvironment (); diff --git a/reactos/tools/rbuild/rbuild.mak b/reactos/tools/rbuild/rbuild.mak index 0743b1b43e2..94cfb69dc24 100644 --- a/reactos/tools/rbuild/rbuild.mak +++ b/reactos/tools/rbuild/rbuild.mak @@ -157,6 +157,7 @@ RBUILD_COMMON_SOURCES = \ bootstrap.cpp \ cdfile.cpp \ compilationunit.cpp \ + compilationunitsupportcode.cpp \ compilerflag.cpp \ configuration.cpp \ define.cpp \ @@ -280,6 +281,10 @@ $(RBUILD_INT_)compilationunit.o: $(RBUILD_BASE_)compilationunit.cpp $(RBUILD_HEA $(ECHO_CC) ${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@ +$(RBUILD_INT_)compilationunitsupportcode.o: $(RBUILD_BASE_)compilationunitsupportcode.cpp $(RBUILD_HEADERS) | $(RBUILD_INT) + $(ECHO_CC) + ${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@ + $(RBUILD_INT_)compilerflag.o: $(RBUILD_BASE_)compilerflag.cpp $(RBUILD_HEADERS) | $(RBUILD_INT) $(ECHO_CC) ${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@ diff --git a/reactos/tools/rbuild/testsupportcode.cpp b/reactos/tools/rbuild/testsupportcode.cpp index 53db1c0ddd5..bf7442c12b7 100644 --- a/reactos/tools/rbuild/testsupportcode.cpp +++ b/reactos/tools/rbuild/testsupportcode.cpp @@ -297,7 +297,8 @@ TestSupportCode::GetSourceFilenames ( string_list& list, const vector& compilationUnits = module.non_if_data.compilationUnits; for ( i = 0; i < compilationUnits.size (); i++ ) { - string filename = compilationUnits[i]->GetFilename(); + FileLocation* sourceFileLocation = compilationUnits[i]->GetFilename ( NULL ); + string filename = sourceFileLocation->filename; if ( !compilationUnits[i]->IsGeneratedFile () && IsTestFile ( filename ) ) list.push_back ( filename ); } @@ -316,7 +317,8 @@ TestSupportCode::GetSourceFilenames ( string_list& list, for ( j = 0; j < compilationUnits.size (); j++ ) { CompilationUnit& compilationUnit = *compilationUnits[j]; - string filename = compilationUnits[j]->GetFilename(); + FileLocation* sourceFileLocation = compilationUnits[j]->GetFilename ( NULL ); + string filename = sourceFileLocation->filename; if ( !compilationUnit.IsGeneratedFile () && IsTestFile ( filename ) ) list.push_back ( filename ); } -- 2.17.1