diff --git a/reactos/tools/rbuild/automaticdependency.cpp b/reactos/tools/rbuild/automaticdependency.cpp index 84174a94431..17685196916 100644 --- a/reactos/tools/rbuild/automaticdependency.cpp +++ b/reactos/tools/rbuild/automaticdependency.cpp @@ -336,12 +336,33 @@ void AutomaticDependency::ParseFile ( const Module& module, const File& file ) { - string normalizedFilename = NormalizeFilename ( file.name ); + string normalizedFilename = NormalizeFilename ( file.GetFullPath () ); RetrieveFromCacheOrParse ( module, normalizedFilename, NULL ); } +string +AutomaticDependency::ReplaceVariable ( const string& name, + const string& value, + string path ) +{ + size_t i = path.find ( name ); + if ( i != string::npos ) + return path.replace ( i, name.length (), value ); + else + return path; +} + +string +AutomaticDependency::ResolveVariablesInPath ( const string& path ) +{ + string s = ReplaceVariable ( "$(INTERMEDIATE)", Environment::GetIntermediatePath (), path ); + s = ReplaceVariable ( "$(OUTPUT)", Environment::GetOutputPath (), s ); + s = ReplaceVariable ( "$(INSTALL)", Environment::GetInstallPath (), s ); + return s; +} + bool AutomaticDependency::LocateIncludedFile ( const string& directory, const string& includedFilename, @@ -423,7 +444,7 @@ AutomaticDependency::RetrieveFromCacheOrParse ( const Module& module, { sourceFile = new SourceFile ( this, module, - filename, + ResolveVariablesInPath ( filename ), parentSourceFile, false ); sourcefile_map[filename] = sourceFile; diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index bf6b925acff..e55aec74727 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -766,7 +766,7 @@ MingwBackend::GetVersionString ( const string& versionCommand ) char separators[] = " "; char *token; char *prevtoken = NULL; - + string version; token = strtok ( buffer, separators ); @@ -865,11 +865,11 @@ MingwBackend::GetBinutilsVersionDate ( const string& binutilsCommand ) } buffer[i] = '\0'; pclose ( fp ); - + char separators[] = " "; char *token; char *prevtoken = NULL; - + token = strtok ( buffer, separators ); while ( token != NULL ) { diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index b1035ae884f..03d63f6536a 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -466,7 +466,7 @@ MingwModuleHandler::GetSourceFilenames ( string_list& list, FileLocation* sourceFileLocation = GetActualSourceFilename ( compilationUnits[i]->GetFilename ( backend->intermediateDirectory ) ); list.push_back ( PassThruCacheDirectory ( sourceFileLocation->filename, - sourceFileLocation->directory ) ); + sourceFileLocation->directory ) ); } } // intentionally make a copy so that we can append more work in @@ -693,9 +693,9 @@ MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector 0 ) parameters += " "; if ( include.root == "intermediate" ) - path_prefix = backend->intermediateDirectory->name + cSep; + path_prefix = "$(INTERMEDIATE)" + sSep; else if (include.root == "output" ) - path_prefix = backend->outputDirectory->name + cSep; + path_prefix = "$(OUTPUT)" + sSep; else path_prefix = ""; @@ -811,14 +811,14 @@ MingwModuleHandler::GenerateMacro ( include.baseModule->type == RpcClient || include.baseModule->type == IdlHeader) ) includeDirectory = PassThruCacheDirectory ( NormalizeFilename ( include.directory ), - backend->intermediateDirectory ); + backend->intermediateDirectory ); else includeDirectory = include.directory; if ( include.root == "intermediate" ) - path_prefix = backend->intermediateDirectory->name + cSep; + path_prefix = "$(INTERMEDIATE)" + sSep; else if (include.root == "output" ) - path_prefix = backend->outputDirectory->name + cSep; + path_prefix = "$(OUTPUT)" + sSep; else path_prefix = ""; @@ -1281,13 +1281,12 @@ MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib ( GetDirectory ( EmbeddedTypeLibFilename ).c_str () ); fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" ); fprintf ( fMakefile, - //"\t%s %s %s -t -T $@ %s\n", - "\t%s %s %s -t -T %s %s\n", + "\t%s %s %s -t -T %s %s\n", "$(Q)$(WIDL_TARGET)", GetWidlFlags ( compilationUnit ).c_str (), widlflagsMacro.c_str (), - EmbeddedTypeLibFilename.c_str(), - filename.c_str () ); + EmbeddedTypeLibFilename.c_str(), + filename.c_str () ); } void @@ -2003,8 +2002,9 @@ MingwModuleHandler::GenerateOtherMacros () fprintf ( fMakefile, - "%s += $(PROJECT_WIDLFLAGS)\n", - widlflagsMacro.c_str () ); + "%s += $(PROJECT_WIDLFLAGS) -I%s\n", + widlflagsMacro.c_str (), + module.GetBasePath ().c_str () ); fprintf ( fMakefile, diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index 105738eb53a..44ac9b2b6d8 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -98,7 +98,7 @@ protected: void GetModuleDependencies ( string_list& dependencies ); std::string GetAllDependencies () const; void GetSourceFilenames ( string_list& list, - bool includeGeneratedFiles ) const; + bool includeGeneratedFiles ) const; void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const; std::string GetObjectFilename ( const FileLocation* sourceFileLocation, string_list* pclean_files ) const; @@ -213,7 +213,7 @@ private: void GetRpcHeaderDependencies ( std::vector& dependencies ) const; std::string GetRpcServerHeaderFilename ( std::string basename ) const; std::string GetRpcClientHeaderFilename ( std::string basename ) const; - std::string GetIdlHeaderFilename ( std::string basename ) const; + std::string GetIdlHeaderFilename ( std::string basename ) const; std::string GetModuleCleanTarget ( const Module& module ) const; void GetReferencedObjectLibraryModuleCleanTargets ( std::vector& moduleNames ) const; public: @@ -334,8 +334,8 @@ public: MingwWin32DLLModuleHandler ( const Module& module ); virtual HostType DefaultHost() { return HostFalse; } virtual void Process (); - std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; } - void AddImplicitLibraries ( Module& module ); + std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; } + void AddImplicitLibraries ( Module& module ); private: void GenerateWin32DLLModuleTarget (); }; @@ -347,8 +347,8 @@ public: MingwWin32OCXModuleHandler ( const Module& module ); virtual HostType DefaultHost() { return HostFalse; } virtual void Process (); - std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; } - void AddImplicitLibraries ( Module& module ); + std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; } + void AddImplicitLibraries ( Module& module ); private: void GenerateWin32OCXModuleTarget (); }; @@ -361,7 +361,7 @@ public: virtual HostType DefaultHost() { return HostFalse; } virtual void Process (); std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; } - void AddImplicitLibraries ( Module& module ); + void AddImplicitLibraries ( Module& module ); private: void GenerateWin32CUIModuleTarget (); }; @@ -374,7 +374,7 @@ public: virtual HostType DefaultHost() { return HostFalse; } virtual void Process (); std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; } - void AddImplicitLibraries ( Module& module ); + void AddImplicitLibraries ( Module& module ); private: void GenerateWin32GUIModuleTarget (); }; diff --git a/reactos/tools/rbuild/compilationunit.cpp b/reactos/tools/rbuild/compilationunit.cpp index 2ac65499c7a..022a43911c6 100644 --- a/reactos/tools/rbuild/compilationunit.cpp +++ b/reactos/tools/rbuild/compilationunit.cpp @@ -98,7 +98,10 @@ CompilationUnit::GetFilename ( Directory* intermediateDirectory ) const if ( files.size () == 0 || files.size () > 1 ) return new FileLocation ( intermediateDirectory, name ); File* file = files[0]; - return new FileLocation ( NULL, file->name ); + if (file->path_prefix.length() > 0) + return new FileLocation ( intermediateDirectory, file->name ); + else + return new FileLocation ( NULL, file->name ); } std::string diff --git a/reactos/tools/rbuild/directory.cpp b/reactos/tools/rbuild/directory.cpp index 8212c89e0fd..9531348947c 100644 --- a/reactos/tools/rbuild/directory.cpp +++ b/reactos/tools/rbuild/directory.cpp @@ -53,6 +53,14 @@ Directory::Add ( const char* subdir ) } const char* p = strpbrk ( subdir, "/\\" ); + if ( subdir == p || ( *subdir && subdir[1] == ':' ) ) + { + throw InvalidOperationException ( __FILE__, + __LINE__, + "Invalid relative path '%s'", + subdir ); + } + if ( !p ) p = subdir + strlen(subdir); string s ( subdir, p-subdir ); @@ -109,8 +117,8 @@ Directory::CreateDirectory ( string path ) } string -Directory::ReplaceVariable ( string name, - string value, +Directory::ReplaceVariable ( const string& name, + const string& value, string path ) { size_t i = path.find ( name ); @@ -122,7 +130,7 @@ Directory::ReplaceVariable ( string name, void Directory::ResolveVariablesInPath ( char* buf, - string path ) + const string& path ) { string s = ReplaceVariable ( "$(INTERMEDIATE)", Environment::GetIntermediatePath (), path ); s = ReplaceVariable ( "$(OUTPUT)", Environment::GetOutputPath (), s ); @@ -140,7 +148,10 @@ Directory::GenerateTree ( const string& parent, { char buf[256]; - path = parent + sSep + name; + if ( name.size () > 0 ) + path = parent + sSep + name; + else + path = parent; ResolveVariablesInPath ( buf, path ); if ( CreateDirectory ( buf ) && verbose ) printf ( "Created %s\n", buf ); diff --git a/reactos/tools/rbuild/installfile.cpp b/reactos/tools/rbuild/installfile.cpp index f048fa96088..538e413a141 100644 --- a/reactos/tools/rbuild/installfile.cpp +++ b/reactos/tools/rbuild/installfile.cpp @@ -45,9 +45,9 @@ InstallFile::InstallFile ( const Project& project_, if ( att != NULL) { if ( att->value == "intermediate" ) - this->path = Environment::GetIntermediatePath () + sSep + path; + this->path = "$(INTERMEDIATE)" + sSep + path; else if ( att->value == "output" ) - this->path = Environment::GetOutputPath () + sSep + path; + this->path = "$(OUTPUT)" + sSep + path; else { throw InvalidAttributeValueException ( diff --git a/reactos/tools/rbuild/module.cpp b/reactos/tools/rbuild/module.cpp index e35cfd3a631..4dae12bcb53 100644 --- a/reactos/tools/rbuild/module.cpp +++ b/reactos/tools/rbuild/module.cpp @@ -121,7 +121,6 @@ GetSubPath ( const Project& project, const string& location, const string& path, - const XMLAttribute* root, const string& att_value ) { if ( !att_value.size() ) @@ -135,25 +134,7 @@ GetSubPath ( if ( !path.size() ) return att_value; - string path_prefix; - if ( root ) - { - if ( root->value == "intermediate" ) - path_prefix = Environment::GetIntermediatePath() + cSep; - else if ( root->value == "output" ) - path_prefix = Environment::GetOutputPath() + cSep; - else - { - throw InvalidAttributeValueException ( - location, - "root", - root->value ); - } - } - else - path_prefix = ""; - - return FixSeparator(path_prefix + path + cSep + att_value); + return FixSeparator(path + cSep + att_value); } string @@ -540,7 +521,7 @@ Module::ProcessXML() for ( i = 0; i < node.subElements.size(); i++ ) { ParseContext parseContext; - ProcessXMLSubElement ( *node.subElements[i], path, parseContext ); + ProcessXMLSubElement ( *node.subElements[i], path, "", parseContext ); } for ( i = 0; i < invocations.size(); i++ ) invocations[i]->ProcessXML (); @@ -564,12 +545,14 @@ Module::ProcessXML() void Module::ProcessXMLSubElement ( const XMLElement& e, const string& path, + const string& path_prefix, ParseContext& parseContext ) { If* pOldIf = parseContext.ifData; CompilationUnit* pOldCompilationUnit = parseContext.compilationUnit; bool subs_invalid = false; string subpath ( path ); + string subpath_prefix ( "" ); if ( e.name == "file" && e.value.size () > 0 ) { bool first = false; @@ -601,6 +584,7 @@ Module::ProcessXMLSubElement ( const XMLElement& e, cplusplus = true; } File* pFile = new File ( FixSeparator ( path + cSep + e.value ), + path_prefix, first, switches, false ); @@ -638,9 +622,23 @@ Module::ProcessXMLSubElement ( const XMLElement& e, else if ( e.name == "directory" ) { const XMLAttribute* att = e.GetAttribute ( "name", true ); - const XMLAttribute* base = e.GetAttribute ( "root", false ); + const XMLAttribute* root = e.GetAttribute ( "root", false ); assert(att); - subpath = GetSubPath ( this->project, e.location, path, base, att->value ); + if ( root ) + { + if ( root->value == "intermediate" ) + subpath_prefix = "$(INTERMEDIATE)"; + else if ( root->value == "output" ) + subpath_prefix = "$(OUTPUT)"; + else + { + throw InvalidAttributeValueException ( + e.location, + "root", + root->value ); + } + } + subpath = GetSubPath ( this->project, e.location, path, att->value ); } else if ( e.name == "include" ) { @@ -809,7 +807,7 @@ Module::ProcessXMLSubElement ( const XMLElement& e, e.name.c_str() ); } for ( size_t i = 0; i < e.subElements.size (); i++ ) - ProcessXMLSubElement ( *e.subElements[i], subpath, parseContext ); + ProcessXMLSubElement ( *e.subElements[i], subpath, subpath_prefix, parseContext ); parseContext.ifData = pOldIf; parseContext.compilationUnit = pOldCompilationUnit; } @@ -1206,10 +1204,26 @@ Module::InvokeModule () const } -File::File ( const string& _name, bool _first, +File::File ( const string& _name, + bool _first, std::string _switches, bool _isPreCompiledHeader ) : name(_name), + path_prefix(""), + first(_first), + switches(_switches), + isPreCompiledHeader(_isPreCompiledHeader) +{ +} + + +File::File ( const string& _name, + const string& _path_prefix, + bool _first, + std::string _switches, + bool _isPreCompiledHeader ) + : name(_name), + path_prefix(_path_prefix), first(_first), switches(_switches), isPreCompiledHeader(_isPreCompiledHeader) @@ -1222,6 +1236,15 @@ File::ProcessXML() } +std::string File::GetFullPath () const +{ + if ( path_prefix.length () > 0 ) + return path_prefix + sSep + name; + else + return name; +} + + Library::Library ( const XMLElement& _node, const Module& _module, const string& _name ) diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index 5b961ffc960..104f5a74bd0 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -391,9 +391,8 @@ Project::ProcessXMLSubElement ( const XMLElement& e, else if ( e.name == "directory" ) { const XMLAttribute* att = e.GetAttribute ( "name", true ); - const XMLAttribute* base = e.GetAttribute ( "root", false ); assert(att); - subpath = GetSubPath ( *this, e.location, path, base, att->value ); + subpath = GetSubPath ( *this, e.location, path, att->value ); } else if ( e.name == "include" ) { diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index d84969a553c..dd1e237bec2 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -119,12 +119,12 @@ public: const std::string& parent ); private: bool mkdir_p ( const char* path ); - std::string ReplaceVariable ( std::string name, - std::string value, + std::string ReplaceVariable ( const std::string& name, + const std::string& value, std::string path ); std::string GetEnvironmentVariable ( const std::string& name ); void ResolveVariablesInPath ( char* buf, - std::string path ); + const std::string& path ); bool CreateDirectory ( std::string path ); }; @@ -354,6 +354,7 @@ private: std::string entrypoint; void ProcessXMLSubElement ( const XMLElement& e, const std::string& path, + const std::string& path_prefix, ParseContext& parseContext ); }; @@ -388,10 +389,10 @@ class Define public: const Project& project; const Module* module; - const XMLElement* node; + const XMLElement* node; std::string name; std::string value; - std::string backend; + std::string backend; Define ( const Project& project, const XMLElement& defineNode ); @@ -413,6 +414,7 @@ class File { public: std::string name; + std::string path_prefix; bool first; std::string switches; bool isPreCompiledHeader; @@ -422,7 +424,14 @@ public: std::string _switches, bool _isPreCompiledHeader ); + File ( const std::string& _name, + const std::string& _path_prefix, + bool _first, + std::string _switches, + bool _isPreCompiledHeader ); + void ProcessXML(); + std::string GetFullPath () const; }; @@ -629,11 +638,11 @@ private: void WriteHooksFile ( Module& module ); std::string GetStubsFilename ( Module& module ); char* WriteStubbedSymbolToStubsFile ( char* buffer, - const StubbedComponent& component, + const StubbedComponent& component, const StubbedSymbol& symbol, int stubIndex ); char* WriteStubbedComponentToStubsFile ( char* buffer, - const StubbedComponent& component, + const StubbedComponent& component, int* stubIndex ); void WriteStubsFile ( Module& module ); std::string GetStartupFilename ( Module& module ); @@ -641,9 +650,9 @@ private: std::string GetTestDispatcherName ( std::string filename ); bool IsTestFile ( std::string& filename ) const; void GetSourceFilenames ( string_list& list, - Module& module ) const; + Module& module ) const; char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer, - Module& module ); + Module& module ); char* WriteRegisterTestsFunctionToStartupFile ( char* buffer, Module& module ); void WriteStartupFile ( Module& module ); @@ -740,18 +749,22 @@ public: private: void GetModulesToCheck ( Module& module, std::vector& modules ); void CheckAutomaticDependencies ( const Module& module, - bool verbose ); + bool verbose ); void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile ); void GetIncludeDirectories ( std::vector& includes, const Module& module, - Include& currentDirectory, - bool searchCurrentDirectory ); + Include& currentDirectory, + bool searchCurrentDirectory ); void GetModuleFiles ( const Module& module, - std::vector& files ) const; + std::vector& files ) const; void ParseFiles (); void ParseFiles ( const Module& module ); void ParseFile ( const Module& module, const File& file ); + std::string ReplaceVariable ( const std::string& name, + const std::string& value, + std::string path ); + std::string ResolveVariablesInPath ( const std::string& path ); std::map sourcefile_map; }; @@ -994,7 +1007,6 @@ GetSubPath ( const Project& project, const std::string& location, const std::string& path, - const XMLAttribute* root, const std::string& att_value ); extern std::string diff --git a/reactos/tools/rbuild/wineresource.cpp b/reactos/tools/rbuild/wineresource.cpp index b69e829c82a..1ee82cb2bf2 100644 --- a/reactos/tools/rbuild/wineresource.cpp +++ b/reactos/tools/rbuild/wineresource.cpp @@ -111,7 +111,7 @@ WineResource::UnpackResourcesInModule ( Module& module, NormalizeFilename ( resourceFilename ).c_str () ); string command = FixSeparatorForSystemCommand(bin2res) + " " + parameters; - Directory( outputDirectory ).GenerateTree( ".", false ); + Directory( relativeDirectory ).GenerateTree( Environment::GetIntermediatePath(), false ); int exitcode = system ( command.c_str () ); if ( exitcode != 0 )