Support absolute paths for intermediate/output directories

Never put real intermediate/output directory names in generated makefile, use $(INTERMEDIATE) and $(OUTPUT) instead

svn path=/trunk/; revision=28218
This commit is contained in:
Hervé Poussineau 2007-08-07 15:08:09 +00:00
parent ebb26326a5
commit 434e1ef9df
11 changed files with 143 additions and 74 deletions

View file

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

View file

@ -693,9 +693,9 @@ MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Includ
if ( parameters.length () > 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 = "";
@ -816,9 +816,9 @@ MingwModuleHandler::GenerateMacro (
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,7 +1281,6 @@ 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",
"$(Q)$(WIDL_TARGET)",
GetWidlFlags ( compilationUnit ).c_str (),
@ -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,

View file

@ -98,6 +98,9 @@ CompilationUnit::GetFilename ( Directory* intermediateDirectory ) const
if ( files.size () == 0 || files.size () > 1 )
return new FileLocation ( intermediateDirectory, name );
File* file = files[0];
if (file->path_prefix.length() > 0)
return new FileLocation ( intermediateDirectory, file->name );
else
return new FileLocation ( NULL, file->name );
}

View file

@ -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];
if ( name.size () > 0 )
path = parent + sSep + name;
else
path = parent;
ResolveVariablesInPath ( buf, path );
if ( CreateDirectory ( buf ) && verbose )
printf ( "Created %s\n", buf );

View file

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

View file

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

View file

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

View file

@ -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 );
};
@ -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;
};
@ -752,6 +761,10 @@ private:
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<std::string, SourceFile*> 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

View file

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