Continue rbuild cleanup (Include class)

svn path=/trunk/; revision=28986
This commit is contained in:
Hervé Poussineau 2007-09-10 06:52:07 +00:00
parent f53a2fd07d
commit 621618fbbb
11 changed files with 132 additions and 126 deletions

View file

@ -367,11 +367,36 @@ AutomaticDependency::ResolveVariablesInPath ( const string& path )
} }
bool bool
AutomaticDependency::LocateIncludedFile ( const string& directory, AutomaticDependency::LocateIncludedFile ( const FileLocation& directory,
const string& includedFilename, const string& includedFilename,
string& resolvedFilename ) string& resolvedFilename )
{ {
string normalizedFilename = NormalizeFilename ( directory + sSep + includedFilename ); string path;
switch ( directory.directory )
{
case SourceDirectory:
path = "";
break;
case IntermediateDirectory:
path = Environment::GetIntermediatePath ();
break;
case OutputDirectory:
path = Environment::GetOutputPath ();
break;
default:
throw InvalidOperationException ( __FILE__,
__LINE__,
"Invalid directory %d.",
directory.directory );
}
if ( directory.relative_path.length () > 0 )
{
if ( path.length () > 0 )
path += sSep;
path += directory.relative_path;
}
string normalizedFilename = NormalizeFilename ( path + sSep + includedFilename );
FILE* f = fopen ( normalizedFilename.c_str (), "rb" ); FILE* f = fopen ( normalizedFilename.c_str (), "rb" );
if ( f != NULL ) if ( f != NULL )
{ {
@ -418,12 +443,12 @@ AutomaticDependency::LocateIncludedFile ( SourceFile* sourceFile,
string& resolvedFilename ) string& resolvedFilename )
{ {
vector<Include*> includes; vector<Include*> includes;
Include currentDirectory ( module.project, ".", sourceFile->directoryPart ); Include currentDirectory ( module.project, SourceDirectory, sourceFile->directoryPart );
GetIncludeDirectories ( includes, module, currentDirectory, searchCurrentDirectory ); GetIncludeDirectories ( includes, module, currentDirectory, searchCurrentDirectory );
for ( size_t j = 0; j < includes.size (); j++ ) for ( size_t j = 0; j < includes.size (); j++ )
{ {
Include& include = *includes[j]; Include& include = *includes[j];
if ( LocateIncludedFile ( include.directory, if ( LocateIncludedFile ( *include.directory,
includedFilename, includedFilename,
resolvedFilename ) ) resolvedFilename ) )
{ {
@ -433,6 +458,9 @@ AutomaticDependency::LocateIncludedFile ( SourceFile* sourceFile,
return true; return true;
} }
} }
/*printf ( "Unable to find %s, included in %s.\n",
includedFilename.c_str (),
sourceFile->filename.c_str () );*/
resolvedFilename = ""; resolvedFilename = "";
return false; return false;
} }

View file

@ -429,7 +429,7 @@ CBBackend::_generate_cbproj ( const Module& module )
for ( i = 0; i < incs.size(); i++ ) for ( i = 0; i < incs.size(); i++ )
{ {
string path = Path::RelativeFromDirectory ( string path = Path::RelativeFromDirectory (
incs[i]->directory, incs[i]->directory->relative_path,
module.output->relative_path ); module.output->relative_path );
includes.push_back ( path ); includes.push_back ( path );

View file

@ -105,6 +105,8 @@ MingwModuleHandler::PassThruCacheDirectory (const FileLocation* file )
{ {
switch ( file->directory ) switch ( file->directory )
{ {
case SourceDirectory:
break;
case IntermediateDirectory: case IntermediateDirectory:
backend->AddDirectoryTarget ( file->relative_path, backend->intermediateDirectory ); backend->AddDirectoryTarget ( file->relative_path, backend->intermediateDirectory );
break; break;
@ -670,14 +672,7 @@ MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Includ
Include& include = *includes[i]; Include& include = *includes[i];
if ( parameters.length () > 0 ) if ( parameters.length () > 0 )
parameters += " "; parameters += " ";
if ( include.root == "intermediate" ) parameters += "-I" + strDirectory ( include.directory );;
path_prefix = "$(INTERMEDIATE)" + sSep;
else if (include.root == "output" )
path_prefix = "$(OUTPUT)" + sSep;
else
path_prefix = "";
parameters += "-I" + path_prefix + include.directory;
} }
return parameters; return parameters;
} }
@ -783,33 +778,11 @@ MingwModuleHandler::GenerateMacro (
for ( i = 0; i < data.includes.size(); i++ ) for ( i = 0; i < data.includes.size(); i++ )
{ {
const Include& include = *data.includes[i]; const Include& include = *data.includes[i];
string includeDirectory, path_prefix; const FileLocation* includeDirectory = include.directory;
if ( include.baseModule != NULL &&
( include.baseModule->type == RpcServer ||
include.baseModule->type == RpcClient ||
include.baseModule->type == IdlHeader) )
{
path_prefix = "$(INTERMEDIATE)" + sSep;
includeDirectory = NormalizeFilename ( include.directory );
}
else
includeDirectory = include.directory;
if ( include.root == "intermediate" )
path_prefix = "$(INTERMEDIATE)" + sSep;
else if (include.root == "output" )
path_prefix = "$(OUTPUT)" + sSep;
else if ( include.root != "" )
throw InvalidOperationException ( __FILE__,
__LINE__,
"Unsupported root prefix '%s'",
include.root.c_str () );
fprintf ( fprintf (
fMakefile, fMakefile,
" -I%s%s", " -I%s",
path_prefix.c_str(), strDirectory ( includeDirectory ).c_str() );
includeDirectory.c_str() );
} }
for ( i = 0; i < data.defines.size(); i++ ) for ( i = 0; i < data.defines.size(); i++ )
{ {

View file

@ -120,7 +120,7 @@ MsBuildBackend::_generate_sources ( const Module& module )
for ( i = 0; i < incs.size(); i++ ) for ( i = 0; i < incs.size(); i++ )
{ {
string path = Path::RelativeFromDirectory ( string path = Path::RelativeFromDirectory (
incs[i]->directory, incs[i]->directory->relative_path,
module.output->relative_path ); module.output->relative_path );
includes.push_back ( path ); includes.push_back ( path );

View file

@ -118,15 +118,15 @@ MSVCBackend::_generate_dsp ( const Module& module )
{ {
// explicitly omit win32api directories // explicitly omit win32api directories
if ( !strncmp(incs[i]->directory.c_str(), "w32api", 6 ) ) if ( !strncmp(incs[i]->directory->relative_path.c_str(), "w32api", 6 ) )
continue; continue;
// explicitly omit include/wine directories // explicitly omit include/wine directories
if ( !strncmp(incs[i]->directory.c_str(), "include\\wine", 12 ) ) if ( !strncmp(incs[i]->directory->relative_path.c_str(), "include\\wine", 12 ) )
continue; continue;
string path = Path::RelativeFromDirectory ( string path = Path::RelativeFromDirectory (
incs[i]->directory, incs[i]->directory->relative_path,
module.output->relative_path ); module.output->relative_path );
includes.push_back ( path ); includes.push_back ( path );
} }

View file

@ -171,7 +171,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
for ( i = 0; i < incs.size(); i++ ) for ( i = 0; i < incs.size(); i++ )
{ {
string path = Path::RelativeFromDirectory ( string path = Path::RelativeFromDirectory (
incs[i]->directory, incs[i]->directory->relative_path,
module.output->relative_path ); module.output->relative_path );
if ( module.type != RpcServer && module.type != RpcClient ) if ( module.type != RpcServer && module.type != RpcClient )
{ {
@ -182,12 +182,12 @@ MSVCBackend::_generate_vcproj ( const Module& module )
} }
} }
// add to another list win32api and include/wine directories // add to another list win32api and include/wine directories
if ( !strncmp(incs[i]->directory.c_str(), "include\\ddk", 11 ) || if ( !strncmp(incs[i]->directory->relative_path.c_str(), "include\\ddk", 11 ) ||
!strncmp(incs[i]->directory.c_str(), "include\\crt", 11 ) || !strncmp(incs[i]->directory->relative_path.c_str(), "include\\crt", 11 ) ||
!strncmp(incs[i]->directory.c_str(), "include\\GL", 10 ) || !strncmp(incs[i]->directory->relative_path.c_str(), "include\\GL", 10 ) ||
!strncmp(incs[i]->directory.c_str(), "include\\ddk", 11 ) || !strncmp(incs[i]->directory->relative_path.c_str(), "include\\ddk", 11 ) ||
!strncmp(incs[i]->directory.c_str(), "include\\psdk", 12 ) || !strncmp(incs[i]->directory->relative_path.c_str(), "include\\psdk", 12 ) ||
!strncmp(incs[i]->directory.c_str(), "include\\reactos\\wine", 20 ) ) !strncmp(incs[i]->directory->relative_path.c_str(), "include\\reactos\\wine", 20 ) )
{ {
includes_ros.push_back ( path ); includes_ros.push_back ( path );
} }

View file

@ -25,33 +25,30 @@ using std::vector;
Include::Include ( const Project& project, Include::Include ( const Project& project,
const XMLElement* includeNode ) const XMLElement* includeNode )
: project ( project ), : directory ( NULL ),
module ( NULL ), project ( project ),
node ( includeNode ), node ( includeNode ),
baseModule ( NULL ) module ( NULL )
{ {
} }
Include::Include ( const Project& project, Include::Include ( const Project& project,
const Module* module, const XMLElement* includeNode,
const XMLElement* includeNode ) const Module* module )
: project ( project ), : directory ( NULL ),
module ( module ), project ( project ),
node ( includeNode ), node ( includeNode ),
baseModule ( NULL ) module ( module )
{ {
} }
Include::Include ( const Project& project, Include::Include ( const Project& project,
string directory, DirectoryLocation root,
string basePath ) const std::string& relative_path )
: project ( project ), : project ( project ),
module ( NULL ), node ( NULL )
node ( NULL ),
baseModule ( NULL )
{ {
this->directory = NormalizeFilename ( basePath + sSep + directory ); directory = new FileLocation ( root, relative_path, "" );
this->basePath = NormalizeFilename ( basePath );
} }
Include::~Include() Include::~Include()
@ -61,59 +58,65 @@ Include::~Include ()
void void
Include::ProcessXML () Include::ProcessXML ()
{ {
const XMLAttribute* att; DirectoryLocation root = SourceDirectory;
att = node->GetAttribute ( "base", false );
string relative_path;
const XMLAttribute* att = node->GetAttribute ( "base", false );
if ( att ) if ( att )
{ {
bool referenceResolved = false;
if ( !module ) if ( !module )
{
throw XMLInvalidBuildFileException ( throw XMLInvalidBuildFileException (
node->location, node->location,
"'base' attribute illegal from global <include>" ); "'base' attribute illegal from global <include>" );
}
if ( !referenceResolved )
{
if ( att->value == project.name ) if ( att->value == project.name )
{ {
basePath = "."; relative_path = node->value;
referenceResolved = true;
} }
else else
{ {
const Module* base = project.LocateModule ( att->value ); const Module* base = project.LocateModule ( att->value );
if ( base != NULL ) if ( !base )
{
baseModule = base;
basePath = base->output->relative_path;
referenceResolved = true;
}
}
}
if ( !referenceResolved )
throw XMLInvalidBuildFileException ( throw XMLInvalidBuildFileException (
node->location, node->location,
"<include> attribute 'base' references non-existant project or module '%s'", "<include> attribute 'base' references non-existant project or module '%s'",
att->value.c_str() ); att->value.c_str() );
directory = NormalizeFilename ( basePath + sSep + node->value ); root = GetDefaultDirectoryTree ( base );
relative_path = base->output->relative_path;
if ( node->value.length () > 0 && node->value != "." )
relative_path += sSep + node->value;
}
} }
else else
directory = NormalizeFilename ( node->value ); relative_path = node->value;
att = node->GetAttribute ( "root", false ); att = node->GetAttribute ( "root", false );
if ( att ) if ( att )
{ {
if ( att->value != "intermediate" && att->value != "output" ) if ( att->value == "intermediate" )
{ root = IntermediateDirectory;
throw InvalidAttributeValueException ( else if ( att->value == "output" )
node->location, root = OutputDirectory;
else
throw InvalidAttributeValueException ( node->location,
"root", "root",
att->value ); att->value );
} }
root = att->value; directory = new FileLocation ( root,
relative_path,
"" );
} }
DirectoryLocation
Include::GetDefaultDirectoryTree ( const Module* module ) const
{
if ( module != NULL &&
( module->type == RpcServer ||
module->type == RpcClient ||
module->type == IdlHeader) )
return IntermediateDirectory;
else
return SourceDirectory;
} }

View file

@ -289,6 +289,10 @@ Module::Module ( const Project& project,
else else
extension = GetDefaultModuleExtension (); extension = GetDefaultModuleExtension ();
output = new FileLocation ( GetTargetDirectoryTree (),
modulePath,
name + extension );
att = moduleNode.GetAttribute ( "unicode", false ); att = moduleNode.GetAttribute ( "unicode", false );
if ( att != NULL ) if ( att != NULL )
{ {
@ -485,9 +489,6 @@ Module::Module ( const Project& project,
} }
} }
output = new FileLocation ( GetTargetDirectoryTree (),
modulePath,
name + extension );
SetImportLibrary ( NULL ); SetImportLibrary ( NULL );
} }
@ -658,7 +659,7 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
} }
else if ( e.name == "include" ) else if ( e.name == "include" )
{ {
Include* include = new Include ( project, this, &e ); Include* include = new Include ( project, &e, this );
if ( parseContext.ifData ) if ( parseContext.ifData )
parseContext.ifData->data.includes.push_back ( include ); parseContext.ifData->data.includes.push_back ( include );
else else
@ -948,7 +949,9 @@ Module::GetTargetDirectoryTree () const
return IntermediateDirectory; return IntermediateDirectory;
} }
throw InvalidOperationException ( __FILE__, throw InvalidOperationException ( __FILE__,
__LINE__ ); __LINE__,
"Invalid module type %d.",
type );
} }
string string

View file

@ -110,7 +110,8 @@ FileLocation::FileLocation ( const DirectoryLocation directory,
relative_path[0] == '\\' || relative_path[0] == '\\' ||
relative_path.find ( '$' ) != string::npos || relative_path.find ( '$' ) != string::npos ||
( relative_path.length () > 1 && ( relative_path[1] == ':' || ( relative_path.length () > 1 && ( relative_path[1] == ':' ||
relative_path.find_last_of ( "/\\" ) == relative_path.length () - 1 ) ) relative_path.find_last_of ( "/\\" ) == relative_path.length () - 1 ) ) ||
( relative_path.length () > 3 && relative_path.find ( ':' ) != string::npos )
) )
{ {
throw InvalidOperationException ( __FILE__, throw InvalidOperationException ( __FILE__,
@ -119,7 +120,7 @@ FileLocation::FileLocation ( const DirectoryLocation directory,
relative_path.c_str () ); relative_path.c_str () );
} }
if ( strpbrk ( name.c_str (), "/\\:" ) ) if ( name.find_first_of ( "/\\:" ) != string::npos )
{ {
throw InvalidOperationException ( __FILE__, throw InvalidOperationException ( __FILE__,
__LINE__, __LINE__,

View file

@ -386,25 +386,23 @@ private:
class Include class Include
{ {
public: public:
const Project& project; FileLocation *directory;
const Module* module;
const XMLElement* node;
const Module* baseModule;
std::string directory;
std::string basePath;
std::string root;
Include ( const Project& project, Include ( const Project& project,
const XMLElement* includeNode ); const XMLElement* includeNode );
Include ( const Project& project, Include ( const Project& project,
const Module* module, const XMLElement* includeNode,
const XMLElement* includeNode ); const Module* module );
Include ( const Project& project, Include ( const Project& project,
std::string directory, DirectoryLocation directory,
std::string basePath ); const std::string& relative_path );
~Include (); ~Include ();
void ProcessXML (); void ProcessXML ();
private: private:
const Project& project;
const XMLElement* node;
const Module* module;
DirectoryLocation GetDefaultDirectoryTree ( const Module* module ) const;
}; };
@ -769,7 +767,7 @@ public:
AutomaticDependency ( const Project& project ); AutomaticDependency ( const Project& project );
~AutomaticDependency (); ~AutomaticDependency ();
std::string GetFilename ( const std::string& filename ); std::string GetFilename ( const std::string& filename );
bool LocateIncludedFile ( const std::string& directory, bool LocateIncludedFile ( const FileLocation& directory,
const std::string& includedFilename, const std::string& includedFilename,
std::string& resolvedFilename ); std::string& resolvedFilename );
bool LocateIncludedFile ( SourceFile* sourceFile, bool LocateIncludedFile ( SourceFile* sourceFile,

View file

@ -120,6 +120,6 @@ WineResource::UnpackResourcesInModule ( Module& module,
exitcode ); exitcode );
} }
module.non_if_data.includes.push_back( new Include ( module.project, module.non_if_data.includes.push_back( new Include ( module.project,
module.output->relative_path, IntermediateDirectory,
"$(INTERMEDIATE)" ) ); module.output->relative_path ) );
} }