ENH: Refactor passing of max length object dir

When computing the maximum length full path to the build directory under
which object files will be placed, pass the actual path instead of just
its length.  This will be useful for error message generation.
This commit is contained in:
Brad King 2008-12-16 09:14:40 -05:00
parent 63e186a8e6
commit 3cf9265fa7
5 changed files with 44 additions and 43 deletions

View File

@ -645,10 +645,10 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
!sf->GetPropertyAsBool("HEADER_FILE_ONLY") && !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
!sf->GetPropertyAsBool("EXTERNAL_OBJECT")) !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
{ {
std::string::size_type dir_len = 0; std::string dir_max;
dir_len += strlen(this->Makefile->GetCurrentOutputDirectory()); dir_max += this->Makefile->GetCurrentOutputDirectory();
dir_len += 1; dir_max += "/";
std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_len); std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
if(!obj.empty()) if(!obj.empty())
{ {
std::string ofname = this->Makefile->GetCurrentOutputDirectory(); std::string ofname = this->Makefile->GetCurrentOutputDirectory();
@ -2475,7 +2475,7 @@ bool cmLocalGeneratorCheckObjectName(std::string& objName,
std::string& std::string&
cmLocalGenerator cmLocalGenerator
::CreateSafeUniqueObjectFileName(const char* sin, ::CreateSafeUniqueObjectFileName(const char* sin,
std::string::size_type dir_len) std::string const& dir_max)
{ {
// Look for an existing mapped name for this object file. // Look for an existing mapped name for this object file.
std::map<cmStdString,cmStdString>::iterator it = std::map<cmStdString,cmStdString>::iterator it =
@ -2536,9 +2536,10 @@ cmLocalGenerator
} }
#if defined(CM_LG_ENCODE_OBJECT_NAMES) #if defined(CM_LG_ENCODE_OBJECT_NAMES)
cmLocalGeneratorCheckObjectName(ssin, dir_len, this->ObjectPathMax); cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
this->ObjectPathMax);
#else #else
(void)dir_len; (void)dir_max;
#endif #endif
// Insert the newly mapped object file name. // Insert the newly mapped object file name.
@ -2554,7 +2555,7 @@ cmLocalGenerator
std::string std::string
cmLocalGenerator cmLocalGenerator
::GetObjectFileNameWithoutTarget(const cmSourceFile& source, ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
std::string::size_type dir_len, std::string const& dir_max,
bool* hasSourceExtension) bool* hasSourceExtension)
{ {
// Construct the object file name using the full path to the source // Construct the object file name using the full path to the source
@ -2642,7 +2643,7 @@ cmLocalGenerator
} }
// Convert to a safe name. // Convert to a safe name.
return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_len); return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -340,10 +340,10 @@ protected:
// Compute object file names. // Compute object file names.
std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source, std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
std::string::size_type dir_len, std::string const& dir_max,
bool* hasSourceExtension = 0); bool* hasSourceExtension = 0);
std::string& CreateSafeUniqueObjectFileName(const char* sin, std::string& CreateSafeUniqueObjectFileName(const char* sin,
std::string::size_type dir_len); std::string const& dir_max);
void ConfigureRelativePaths(); void ConfigureRelativePaths();
std::string FindRelativePathTopSource(); std::string FindRelativePathTopSource();

View File

@ -1928,12 +1928,12 @@ cmLocalUnixMakefileGenerator3
obj += "/"; obj += "/";
// Get the object file name without the target directory. // Get the object file name without the target directory.
std::string::size_type dir_len = 0; std::string dir_max;
dir_len += strlen(this->Makefile->GetCurrentOutputDirectory()); dir_max += this->Makefile->GetCurrentOutputDirectory();
dir_len += 1; dir_max += "/";
dir_len += obj.size(); dir_max += obj;
std::string objectName = std::string objectName =
this->GetObjectFileNameWithoutTarget(source, dir_len, this->GetObjectFileNameWithoutTarget(source, dir_max,
hasSourceExtension); hasSourceExtension);
if(nameWithoutTargetDir) if(nameWithoutTargetDir)
{ {

View File

@ -372,27 +372,27 @@ void cmLocalVisualStudio6Generator
this->WriteDSPBeginGroup(fout, name.c_str(), ""); this->WriteDSPBeginGroup(fout, name.c_str(), "");
} }
// Compute the maximum length of a configuration name. // Compute the maximum length configuration name.
std::string::size_type config_len_max = 0; std::string config_max;
for(std::vector<std::string>::iterator i = this->Configurations.begin(); for(std::vector<std::string>::iterator i = this->Configurations.begin();
i != this->Configurations.end(); ++i) i != this->Configurations.end(); ++i)
{ {
// Strip the subdirectory name out of the configuration name. // Strip the subdirectory name out of the configuration name.
std::string config = this->GetConfigName(*i); std::string config = this->GetConfigName(*i);
if(config.size() > config_len_max) if(config.size() > config_max.size())
{ {
config_len_max = config.size(); config_max = config;
} }
} }
// Compute the maximum length of the full path to the intermediate // Compute the maximum length full path to the intermediate
// files directory for any configuration. This is used to construct // files directory for any configuration. This is used to construct
// object file names that do not produce paths that are too long. // object file names that do not produce paths that are too long.
std::string::size_type dir_len = 0; std::string dir_max;
dir_len += strlen(this->Makefile->GetCurrentOutputDirectory()); dir_max += this->Makefile->GetCurrentOutputDirectory();
dir_len += 1; dir_max += "/";
dir_len += config_len_max; dir_max += config_max;
dir_len += 1; dir_max += "/";
// Loop through each source in the source group. // Loop through each source in the source group.
for(std::vector<const cmSourceFile *>::const_iterator sf = for(std::vector<const cmSourceFile *>::const_iterator sf =
@ -408,7 +408,7 @@ void cmLocalVisualStudio6Generator
{ {
objectNameDir = objectNameDir =
cmSystemTools::GetFilenamePath( cmSystemTools::GetFilenamePath(
this->GetObjectFileNameWithoutTarget(*(*sf), dir_len)); this->GetObjectFileNameWithoutTarget(*(*sf), dir_max));
} }
// Add per-source file flags. // Add per-source file flags.

View File

@ -1226,7 +1226,7 @@ public:
cmTarget& target, cmTarget& target,
cmSourceFile const& sf, cmSourceFile const& sf,
std::vector<std::string>* configs, std::vector<std::string>* configs,
std::string::size_type dir_len); std::string const& dir_max);
std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap; std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
}; };
@ -1235,12 +1235,12 @@ cmLocalVisualStudio7GeneratorFCInfo
cmTarget& target, cmTarget& target,
cmSourceFile const& sf, cmSourceFile const& sf,
std::vector<std::string>* configs, std::vector<std::string>* configs,
std::string::size_type dir_len) std::string const& dir_max)
{ {
std::string objectName; std::string objectName;
if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end()) if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end())
{ {
objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_len); objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_max);
} }
// Compute per-source, per-config information. // Compute per-source, per-config information.
@ -1358,27 +1358,27 @@ void cmLocalVisualStudio7Generator
this->WriteVCProjBeginGroup(fout, name.c_str(), ""); this->WriteVCProjBeginGroup(fout, name.c_str(), "");
} }
// Compute the maximum length of a configuration name. // Compute the maximum length configuration name.
std::string::size_type config_len_max = 0; std::string config_max;
for(std::vector<std::string>::iterator i = configs->begin(); for(std::vector<std::string>::iterator i = configs->begin();
i != configs->end(); ++i) i != configs->end(); ++i)
{ {
if(i->size() > config_len_max) if(i->size() > config_max.size())
{ {
config_len_max = i->size(); config_max = *i;
} }
} }
// Compute the maximum length of the full path to the intermediate // Compute the maximum length full path to the intermediate
// files directory for any configuration. This is used to construct // files directory for any configuration. This is used to construct
// object file names that do not produce paths that are too long. // object file names that do not produce paths that are too long.
std::string::size_type dir_len = 0; std::string dir_max;
dir_len += strlen(this->Makefile->GetCurrentOutputDirectory()); dir_max += this->Makefile->GetCurrentOutputDirectory();
dir_len += 1; dir_max += "/";
dir_len += this->GetTargetDirectory(target).size(); dir_max += this->GetTargetDirectory(target);
dir_len += 1; dir_max += "/";
dir_len += config_len_max; dir_max += config_max;
dir_len += 1; dir_max += "/";
// Loop through each source in the source group. // Loop through each source in the source group.
std::string objectName; std::string objectName;
@ -1386,7 +1386,7 @@ void cmLocalVisualStudio7Generator
sourceFiles.begin(); sf != sourceFiles.end(); ++sf) sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
{ {
std::string source = (*sf)->GetFullPath(); std::string source = (*sf)->GetFullPath();
FCInfo fcinfo(this, target, *(*sf), configs, dir_len); FCInfo fcinfo(this, target, *(*sf), configs, dir_max);
if (source != libName || target.GetType() == cmTarget::UTILITY || if (source != libName || target.GetType() == cmTarget::UTILITY ||
target.GetType() == cmTarget::GLOBAL_TARGET ) target.GetType() == cmTarget::GLOBAL_TARGET )