Test every environment variable when doing substitution to remove more directories
CHANGED: Use the environment variable that removes the most directories Fixes https://gitlab.com/kicad/code/kicad/issues/2500
This commit is contained in:
parent
36de20a0a7
commit
43514a18bb
|
@ -64,11 +64,15 @@ static bool normalizeAbsolutePaths( const wxFileName& aPathA,
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars,
|
||||
const wxString& aProjectPath )
|
||||
{
|
||||
wxFileName envPath;
|
||||
wxString tmp, varName, normalizedFullPath;
|
||||
wxString varName;
|
||||
wxString remainingPath;
|
||||
wxString normalizedFullPath;
|
||||
int pathDepth = 0;
|
||||
|
||||
if( aEnvVars )
|
||||
{
|
||||
|
@ -81,10 +85,18 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
|
|||
|
||||
envPath.SetPath( entry.second.GetValue() );
|
||||
|
||||
wxString tmp;
|
||||
if( normalizeAbsolutePaths( envPath, aFilePath, &tmp ) )
|
||||
{
|
||||
varName = entry.first;
|
||||
break;
|
||||
int newDepth = envPath.GetDirs().GetCount();
|
||||
|
||||
// Only use the variable if it removes more directories than the previous ones
|
||||
if( newDepth > pathDepth )
|
||||
{
|
||||
pathDepth = newDepth;
|
||||
varName = entry.first;
|
||||
remainingPath = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +106,7 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
|
|||
{
|
||||
envPath.SetPath( aProjectPath );
|
||||
|
||||
if( normalizeAbsolutePaths( envPath, aFilePath, &tmp ) )
|
||||
if( normalizeAbsolutePaths( envPath, aFilePath, &remainingPath ) )
|
||||
varName = PROJECT_VAR_NAME;
|
||||
}
|
||||
|
||||
|
@ -102,8 +114,8 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
|
|||
{
|
||||
normalizedFullPath = wxString::Format( "${%s}/", varName );
|
||||
|
||||
if( !tmp.IsEmpty() )
|
||||
normalizedFullPath += tmp;
|
||||
if( !remainingPath.IsEmpty() )
|
||||
normalizedFullPath += remainingPath;
|
||||
|
||||
normalizedFullPath += aFilePath.GetFullName();
|
||||
}
|
||||
|
@ -111,6 +123,7 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
|
|||
return normalizedFullPath;
|
||||
}
|
||||
|
||||
|
||||
wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars,
|
||||
const PROJECT* aProject )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue