* Run build tools after parsing build files

* Generate roscfg.h


svn path=/branches/xmlbuildsystem/; revision=13496
This commit is contained in:
Casper Hornstrup 2005-02-11 19:13:01 +00:00
parent 63b4ab39e4
commit 760ebcb3e3
13 changed files with 354 additions and 63 deletions

View file

@ -862,8 +862,6 @@ DriverEntry(
DueTime.QuadPart = -(LONGLONG)IP_TIMEOUT * 10000;
KeSetTimerEx(&IPTimer, DueTime, IP_TIMEOUT, &IPTimeoutDpc);
PREPARE_TESTS
return STATUS_SUCCESS;
}

View file

@ -176,8 +176,6 @@ DllMain(HANDLE hDll,
break;
}
PREPARE_TESTS
return TRUE;
}

View file

@ -330,8 +330,6 @@ DriverEntry (
CreateStockObjects();
CreateSysColorObjects();
PREPARE_TESTS
return STATUS_SUCCESS;
}

View file

@ -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 ()
{

View file

@ -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;
};

View file

@ -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];

View file

@ -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;
};

View file

@ -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;
}

View file

@ -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 */

View file

@ -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 )

View file

@ -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];
}

View file

@ -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 ();

View file

@ -13,6 +13,7 @@
#include <sys/utime.h>
#else
#include <utime.h>
#include <process.h>
#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 );