diff --git a/reactos/drivers/net/tcpip/tcpip/main.c b/reactos/drivers/net/tcpip/tcpip/main.c index ddbceccb7d8..9853b02ccfa 100644 --- a/reactos/drivers/net/tcpip/tcpip/main.c +++ b/reactos/drivers/net/tcpip/tcpip/main.c @@ -862,8 +862,6 @@ DriverEntry( DueTime.QuadPart = -(LONGLONG)IP_TIMEOUT * 10000; KeSetTimerEx(&IPTimer, DueTime, IP_TIMEOUT, &IPTimeoutDpc); - PREPARE_TESTS - return STATUS_SUCCESS; } diff --git a/reactos/lib/kernel32/misc/dllmain.c b/reactos/lib/kernel32/misc/dllmain.c index 8a808c16a25..95fd91cb64d 100644 --- a/reactos/lib/kernel32/misc/dllmain.c +++ b/reactos/lib/kernel32/misc/dllmain.c @@ -176,8 +176,6 @@ DllMain(HANDLE hDll, break; } - PREPARE_TESTS - return TRUE; } diff --git a/reactos/subsys/win32k/main/dllmain.c b/reactos/subsys/win32k/main/dllmain.c index 07961a01a37..f6410dcbf70 100644 --- a/reactos/subsys/win32k/main/dllmain.c +++ b/reactos/subsys/win32k/main/dllmain.c @@ -330,8 +330,6 @@ DriverEntry ( CreateStockObjects(); CreateSysColorObjects(); - PREPARE_TESTS - return STATUS_SUCCESS; } diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index db0367946d9..bc9c2585576 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -30,6 +30,7 @@ MingwBackend::Process () GenerateHeader (); GenerateGlobalVariables (); GenerateAllTarget (); + GenerateInitTarget (); for ( size_t i = 0; i < ProjectNode.modules.size (); i++ ) { Module& module = *ProjectNode.modules[i]; @@ -167,6 +168,7 @@ MingwBackend::GenerateGlobalVariables () const fprintf ( fMakefile, "host_ar = ar\n" ); fprintf ( fMakefile, "host_objcopy = objcopy\n" ); #ifdef WIN32 + fprintf ( fMakefile, "nmkdir = mkdir\n" ); fprintf ( fMakefile, "rm = del /f /q\n" ); fprintf ( fMakefile, "gcc = gcc\n" ); fprintf ( fMakefile, "gpp = g++\n" ); @@ -176,6 +178,7 @@ MingwBackend::GenerateGlobalVariables () const fprintf ( fMakefile, "dlltool = dlltool\n" ); fprintf ( fMakefile, "windres = windres\n" ); #else + fprintf ( fMakefile, "nmkdir = mkdir -p\n" ); fprintf ( fMakefile, "rm = rm -f\n" ); fprintf ( fMakefile, "gcc = mingw32-gcc\n" ); fprintf ( fMakefile, "gpp = mingw32-g++\n" ); @@ -235,6 +238,53 @@ MingwBackend::GenerateAllTarget () const fprintf ( fMakefile, "\n\t\n\n" ); } +string +MingwBackend::GetBuildToolDependencies () const +{ + string dependencies; + for ( size_t i = 0; i < ProjectNode.modules.size (); i++ ) + { + Module& module = *ProjectNode.modules[i]; + if ( module.type == BuildTool ) + { + if ( dependencies.length () > 0 ) + dependencies += " "; + dependencies += module.GetDependencyPath (); + } + } + return dependencies; +} + +void +MingwBackend::GenerateInitTarget () const +{ + fprintf ( fMakefile, + "init:"); + fprintf ( fMakefile, + " $(ROS_INTERMEDIATE)." SSEP "tools" ); + fprintf ( fMakefile, + " %s", + GetBuildToolDependencies ().c_str () ); + fprintf ( fMakefile, + " %s", + "include" SSEP "reactos" SSEP "buildno.h" ); + fprintf ( fMakefile, + "\n\t\n\n" ); + + fprintf ( fMakefile, + "$(ROS_INTERMEDIATE)." SSEP "tools:\n" ); + fprintf ( fMakefile, + "ifneq ($(ROS_INTERMEDIATE),)\n" ); + fprintf ( fMakefile, + "\t${nmkdir} $(ROS_INTERMEDIATE)\n" ); + fprintf ( fMakefile, + "endif\n" ); + fprintf ( fMakefile, + "\t${nmkdir} $(ROS_INTERMEDIATE)." SSEP "tools\n" ); + fprintf ( fMakefile, + "\n" ); +} + void MingwBackend::CheckAutomaticDependencies () { diff --git a/reactos/tools/rbuild/backend/mingw/mingw.h b/reactos/tools/rbuild/backend/mingw/mingw.h index 336244ac2b7..6f70fd1fbf6 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.h +++ b/reactos/tools/rbuild/backend/mingw/mingw.h @@ -28,6 +28,8 @@ private: void GenerateGlobalVariables () const; bool IncludeInAllTarget ( const Module& module ) const; void GenerateAllTarget () const; + std::string GetBuildToolDependencies () const; + void GenerateInitTarget () const; void CheckAutomaticDependencies (); FILE* fMakefile; }; diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index 68d2aa68296..a9dc3a14bc7 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -257,6 +257,15 @@ MingwModuleHandler::GetObjectFilenames ( const Module& module ) const return objectFilenames; } +bool +MingwModuleHandler::IncludeDirectoryTarget ( const string& directory ) const +{ + if ( directory == "$(ROS_INTERMEDIATE)." SSEP "tools") + return false; + else + return true; +} + void MingwModuleHandler::GenerateDirectoryTargets () const { @@ -270,7 +279,12 @@ MingwModuleHandler::GenerateDirectoryTargets () const i != directory_set.end (); i++ ) { - fprintf ( fMakefile, " %s", i->c_str () ); + if ( IncludeDirectoryTarget ( *i ) ) + { + fprintf ( fMakefile, + " %s", + i->c_str () ); + } } fprintf ( fMakefile, "\n\n" ); @@ -279,7 +293,12 @@ MingwModuleHandler::GenerateDirectoryTargets () const i != directory_set.end (); i++ ) { - fprintf ( fMakefile, "%s ", i->c_str () ); + if ( IncludeDirectoryTarget ( *i ) ) + { + fprintf ( fMakefile, + "%s ", + i->c_str () ); + } } fprintf ( fMakefile, @@ -1069,40 +1088,6 @@ MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const return dependencies; } -string -MingwModuleHandler::GetInvocationParameters ( const Invoke& invoke ) const -{ - string parameters ( "" ); - size_t i; - for (i = 0; i < invoke.output.size (); i++) - { - if (parameters.length () > 0) - parameters += " "; - InvokeFile& invokeFile = *invoke.output[i]; - if (invokeFile.switches.length () > 0) - { - parameters += invokeFile.switches; - parameters += " "; - } - parameters += invokeFile.name; - } - - for (i = 0; i < invoke.input.size (); i++) - { - if (parameters.length () > 0) - parameters += " "; - InvokeFile& invokeFile = *invoke.input[i]; - if (invokeFile.switches.length () > 0) - { - parameters += invokeFile.switches; - parameters += " "; - } - parameters += invokeFile.name ; - } - - return parameters; -} - void MingwModuleHandler::GenerateInvocations ( const Module& module ) const { @@ -1134,7 +1119,7 @@ MingwModuleHandler::GenerateInvocations ( const Module& module ) const fprintf ( fMakefile, "\t%s %s\n\n", FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (), - GetInvocationParameters ( invoke ).c_str () ); + invoke.GetParameters ().c_str () ); } } @@ -1145,13 +1130,31 @@ MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) con module.name.c_str () ); } +string +MingwModuleHandler::GetDefaultDependencies ( const Module& module ) const +{ + /* Avoid circular dependency */ + if ( module.type == BuildTool || module.name == "zlib" ) + return "$(ROS_INTERMEDIATE)." SSEP "tools $(ROS_INTERMEDIATE)." SSEP "lib" SSEP "zlib"; + else + return "init"; +} + void MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) const { string preconditionDependenciesName = GetPreconditionDependenciesName ( module ); string sourceFilenames = GetSourceFilenamesWithoutGeneratedFiles ( module ); - string dependencies = GetModuleDependencies ( module ); - string s = GetInvocationDependencies ( module ); + string dependencies = GetDefaultDependencies ( module ); + string s = GetModuleDependencies ( module ); + if ( s.length () > 0 ) + { + if ( dependencies.length () > 0 ) + dependencies += " "; + dependencies += s; + } + + s = GetInvocationDependencies ( module ); if ( s.length () > 0 ) { if ( dependencies.length () > 0 ) @@ -1223,6 +1226,9 @@ string MingwModuleHandler::GetDefinitionDependencies ( const Module& module ) const { string dependencies; + string dkNkmLibNoFixup = "dk/nkm/lib"; + dependencies += FixupTargetFilename ( dkNkmLibNoFixup ); + PassThruCacheDirectory ( dkNkmLibNoFixup + SSEP ); for ( size_t i = 0; i < module.files.size (); i++ ) { File& file = *module.files[i]; diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index 94b56dc576a..717921bf019 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -21,6 +21,7 @@ public: static MingwModuleHandler* LookupHandler ( const std::string& location, ModuleType moduletype_ ); virtual void Process ( const Module& module ) = 0; + bool IncludeDirectoryTarget ( const std::string& directory ) const; void GenerateDirectoryTargets () const; static std::string GetObjectFilename ( const std::string& sourceFilename ); protected: @@ -46,7 +47,6 @@ protected: const std::string* cflags, const std::string* nasmflags ) const; std::string GetInvocationDependencies ( const Module& module ) const; - std::string GetInvocationParameters ( const Invoke& invoke ) const; void GenerateInvocations ( const Module& module ) const; std::string GetPreconditionDependenciesName ( const Module& module ) const; @@ -149,6 +149,7 @@ private: const std::string* clags, const std::string* nasmflags ) const; std::string GetSpecObjectDependencies ( const std::string& filename ) const; + std::string GetDefaultDependencies ( const Module& module ) const; }; diff --git a/reactos/tools/rbuild/exception.cpp b/reactos/tools/rbuild/exception.cpp index 3927e2d81f1..47e0d32109c 100644 --- a/reactos/tools/rbuild/exception.cpp +++ b/reactos/tools/rbuild/exception.cpp @@ -33,6 +33,12 @@ void Exception::SetMessage ( const char* message, } +OutOfMemoryException::OutOfMemoryException () + : Exception ( "Out of memory" ) +{ +} + + InvalidOperationException::InvalidOperationException ( const char* filename, const int linenumber ) { @@ -147,6 +153,7 @@ UnknownBackendException::UnknownBackendException ( const string& name ) { } + UnknownModuleTypeException::UnknownModuleTypeException ( const string& location, int moduletype ) : InvalidBuildFileException ( location, @@ -154,3 +161,14 @@ UnknownModuleTypeException::UnknownModuleTypeException ( const string& location, moduletype ) { } + + +InvocationFailedException::InvocationFailedException ( const std::string& command, + int exitcode ) + : Exception ( "Failed to execute '%s' (exit code %d)", + command.c_str (), + exitcode ) +{ + Command = command; + ExitCode = exitcode; +} diff --git a/reactos/tools/rbuild/exception.h b/reactos/tools/rbuild/exception.h index 5574d63f7a8..2adc4380eb9 100644 --- a/reactos/tools/rbuild/exception.h +++ b/reactos/tools/rbuild/exception.h @@ -29,6 +29,13 @@ public: }; +class OutOfMemoryException : public Exception +{ +public: + OutOfMemoryException (); +}; + + class FileNotFoundException : public Exception { public: @@ -105,4 +112,14 @@ public: int moduletype ); }; + +class InvocationFailedException : public Exception +{ +public: + InvocationFailedException ( const std::string& command, + int exitcode ); + std::string Command; + int ExitCode; +}; + #endif /* __EXCEPTION_H */ diff --git a/reactos/tools/rbuild/module.cpp b/reactos/tools/rbuild/module.cpp index 22040680bbe..7f2770248d8 100644 --- a/reactos/tools/rbuild/module.cpp +++ b/reactos/tools/rbuild/module.cpp @@ -451,6 +451,21 @@ Module::HasFileWithExtensions ( const std::string& extension1, return false; } +void +Module::InvokeModule () const +{ + for ( size_t i = 0; i < invocations.size (); i++ ) + { + Invoke& invoke = *invocations[i]; + string command = invoke.invokeModule->GetPath () + " " + invoke.GetParameters (); + printf ( "Executing '%s'\n\n", command.c_str () ); + int exitcode = system ( command.c_str () ); + if ( exitcode != 0 ) + throw InvocationFailedException ( command, + exitcode ); + } +} + File::File ( const string& _name, bool _first ) : name(_name), first(_first) @@ -581,6 +596,40 @@ Invoke::GetTargets () const return targets; } +string +Invoke::GetParameters () const +{ + string parameters ( "" ); + size_t i; + for ( i = 0; i < output.size (); i++ ) + { + if ( parameters.length () > 0) + parameters += " "; + InvokeFile& invokeFile = *output[i]; + if ( invokeFile.switches.length () > 0 ) + { + parameters += invokeFile.switches; + parameters += " "; + } + parameters += invokeFile.name; + } + + for ( i = 0; i < input.size (); i++ ) + { + if ( parameters.length () > 0 ) + parameters += " "; + InvokeFile& invokeFile = *input[i]; + if ( invokeFile.switches.length () > 0 ) + { + parameters += invokeFile.switches; + parameters += " "; + } + parameters += invokeFile.name ; + } + + return parameters; +} + InvokeFile::InvokeFile ( const XMLElement& _node, const string& _name ) diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index 6d8a4840674..9800323838e 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -7,15 +7,10 @@ using std::string; using std::vector; -/*Project::Project() - : node(NULL), head(NULL) -{ -}*/ - Project::Project ( const string& filename ) - : xmlfile(filename), - node(NULL), - head(NULL) + : xmlfile (filename), + node (NULL), + head (NULL) { ReadXml(); } @@ -25,26 +20,170 @@ Project::~Project () size_t i; for ( i = 0; i < modules.size (); i++ ) delete modules[i]; - for ( i = 0; i < includes.size(); i++ ) + for ( i = 0; i < includes.size (); i++ ) delete includes[i]; - for ( i = 0; i < defines.size(); i++ ) + for ( i = 0; i < defines.size (); i++ ) delete defines[i]; - for ( i = 0; i < linkerFlags.size(); i++ ) + for ( i = 0; i < linkerFlags.size (); i++ ) delete linkerFlags[i]; - for ( i = 0; i < properties.size(); i++ ) + for ( i = 0; i < properties.size (); i++ ) delete properties[i]; - for ( i = 0; i < ifs.size(); i++ ) + for ( i = 0; i < ifs.size (); i++ ) delete ifs[i]; delete head; } +const Property* +Project::LookupProperty ( const string& name ) const +{ + for ( size_t i = 0; i < properties.size (); i++ ) + { + const Property* property = properties[i]; + if ( property->name == name ) + return property; + } + return NULL; +} + void -Project::ReadXml() +Project::WriteIfChanged ( char* outbuf, + string filename ) +{ + FILE* out; + unsigned int end; + char* cmpbuf; + unsigned int stat; + + out = fopen ( filename.c_str (), "rb" ); + if ( out == NULL ) + { + out = fopen ( filename.c_str (), "wb" ); + if ( out == NULL ) + throw AccessDeniedException ( filename ); + fputs ( outbuf, out ); + fclose ( out ); + return; + } + + fseek ( out, 0, SEEK_END ); + end = ftell ( out ); + cmpbuf = (char*) malloc ( end ); + if ( cmpbuf == NULL ) + { + fclose ( out ); + throw OutOfMemoryException (); + } + + fseek ( out, 0, SEEK_SET ); + stat = fread ( cmpbuf, 1, end, out ); + if ( stat != end ) + { + free ( cmpbuf ); + fclose ( out ); + throw AccessDeniedException ( filename ); + } + if ( end == strlen ( outbuf ) && memcmp ( cmpbuf, outbuf, end ) == 0 ) + { + free ( cmpbuf ); + fclose ( out ); + return; + } + + free ( cmpbuf ); + fclose ( out ); + out = fopen ( filename.c_str (), "wb" ); + if ( out == NULL ) + { + throw AccessDeniedException ( filename ); + } + + stat = fwrite ( outbuf, 1, strlen ( outbuf ), out); + if ( strlen ( outbuf ) != stat ) + { + fclose ( out ); + throw AccessDeniedException ( filename ); + } + + fclose ( out ); +} + +void +Project::SetConfigurationOption ( char* s, + string name, + string* alternativeName ) +{ + const Property* property = LookupProperty ( name ); + if ( property != NULL && property->value.length () > 0 ) + { + s = s + sprintf ( s, + "#define %s=%s\n", + property->name.c_str (), + property->value.c_str () ); + } + else if ( property != NULL ) + { + s = s + sprintf ( s, + "#define %s\n", + property->name.c_str () ); + } + else if ( alternativeName != NULL ) + { + s = s + sprintf ( s, + "#define %s\n", + alternativeName->c_str () ); + } +} + +void +Project::SetConfigurationOption ( char* s, + string name ) +{ + SetConfigurationOption ( s, name, NULL ); +} + +void +Project::WriteConfigurationFile () +{ + char* buf; + char* s; + + buf = (char*) malloc ( 10*1024 ); + if ( buf == NULL ) + throw OutOfMemoryException (); + + s = buf; + s = s + sprintf ( s, "/* Automatically generated. " ); + s = s + sprintf ( s, "Edit config.xml to change configuration */\n" ); + s = s + sprintf ( s, "#ifndef __INCLUDE_CONFIG_H\n" ); + s = s + sprintf ( s, "#define __INCLUDE_CONFIG_H\n" ); + + SetConfigurationOption ( s, "ARCH" ); + SetConfigurationOption ( s, "OPTIMIZED" ); + SetConfigurationOption ( s, "MP", new string ( "UP" ) ); + SetConfigurationOption ( s, "ACPI" ); + SetConfigurationOption ( s, "_3GB" ); + + s = s + sprintf ( s, "#endif /* __INCLUDE_CONFIG_H */\n" ); + + WriteIfChanged ( buf, "include" SSEP "roscfg.h" ); + + free ( buf ); +} + +void +Project::ExecuteInvocations () +{ + for ( size_t i = 0; i < modules.size (); i++ ) + modules[i]->InvokeModule (); +} + +void +Project::ReadXml () { Path path; head = XMLLoadFile ( xmlfile, path ); node = NULL; - for ( size_t i = 0; i < head->subElements.size(); i++ ) + for ( size_t i = 0; i < head->subElements.size (); i++ ) { if ( head->subElements[i]->name == "project" ) { @@ -189,7 +328,7 @@ Project::LocateModule ( const string& name ) const { for ( size_t i = 0; i < modules.size (); i++ ) { - if (modules[i]->name == name) + if ( modules[i]->name == name ) return modules[i]; } diff --git a/reactos/tools/rbuild/rbuild.cpp b/reactos/tools/rbuild/rbuild.cpp index 992cdeef203..06457920c4a 100644 --- a/reactos/tools/rbuild/rbuild.cpp +++ b/reactos/tools/rbuild/rbuild.cpp @@ -30,6 +30,8 @@ main ( int argc, char** argv ) { string projectFilename ( "ReactOS.xml" ); Project project ( projectFilename ); + project.WriteConfigurationFile (); + project.ExecuteInvocations (); Backend* backend = Backend::Factory::Create ( buildtarget, project ); backend->Process (); diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index 54ef478c3ec..c68f28aa17b 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -13,6 +13,7 @@ #include #else #include +#include #endif #include "ssprintf.h" @@ -67,10 +68,20 @@ public: Project ( const std::string& filename ); ~Project (); + void WriteConfigurationFile (); + void ExecuteInvocations (); void ProcessXML ( const std::string& path ); Module* LocateModule ( const std::string& name ); const Module* LocateModule ( const std::string& name ) const; private: + const Property* LookupProperty ( const std::string& name ) const; + void SetConfigurationOption ( char* s, + std::string name, + std::string* alternativeName ); + void SetConfigurationOption ( char* s, + std::string name ); + void WriteIfChanged ( char* outbuf, + std::string filename ); void ReadXml (); void ProcessXMLSubElement ( const XMLElement& e, const std::string& path, @@ -139,7 +150,8 @@ public: std::string GetInvocationTarget ( const int index ) const; bool HasFileWithExtensions ( const std::string& extension1, const std::string& extension2 ) const; - void ProcessXML(); + void InvokeModule () const; + void ProcessXML (); private: std::string GetDefaultModuleExtension () const; std::string GetDefaultModuleEntrypoint () const; @@ -232,6 +244,7 @@ public: void ProcessXML(); std::string GetTargets () const; + std::string GetParameters () const; private: void ProcessXMLSubElement ( const XMLElement& e ); void ProcessXMLSubElementInput ( const XMLElement& e );