Commit ef7cffc2 authored by Jarek Kobus's avatar Jarek Kobus
Browse files

Quote paths when needed inside addLibraryWizard.



Task-number: QTCREATORBUG-15140
Change-Id: Ieda19112ed74d81fa113e8526a50f49ab964f819
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 57ae7506
......@@ -41,6 +41,7 @@
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <utils/hostosinfo.h>
#include <utils/qtcprocess.h>
#include <QFileInfo>
#include <QDir>
......@@ -393,11 +394,12 @@ void LibraryDetailsController::slotAddSuffixChanged(bool ena)
}
}
static QString appendSpaceIfNotEmpty(const QString &aString)
// quote only when the string contains spaces
static QString smartQuote(const QString &aString)
{
if (aString.isEmpty())
return aString;
return aString + QLatin1Char(' ');
// The OS type is not important in that case, but use always the same
// in order not to generate different quoting depending on host platform
return Utils::QtcProcess::quoteArg(aString, Utils::OsTypeLinux);
}
static QString appendSeparator(const QString &aString)
......@@ -459,17 +461,8 @@ static QString generateLibsSnippet(AddLibraryWizard::Platforms platforms,
const QString &targetRelativePath, const QString &pwd,
bool useSubfolders, bool addSuffix, bool generateLibPath)
{
// if needed it contains: $$[pwd]/_PATH_
const QString libraryPathSnippet = generateLibPath ?
QLatin1String("$$") + pwd + QLatin1Char('/') +
targetRelativePath : QString();
// if needed it contains: -L$$[pwd]/_PATH_
const QString simpleLibraryPathSnippet = generateLibPath ?
QLatin1String("-L") + libraryPathSnippet : QString();
// if needed it contains: -F$$[pwd]/_PATH_
const QString macLibraryPathSnippet = generateLibPath ?
QLatin1String("-F") + libraryPathSnippet : QString();
// it contains: $$[pwd]/
const QString libraryPathSnippet = QLatin1String("$$") + pwd + QLatin1Char('/');
AddLibraryWizard::Platforms commonPlatforms = platforms;
if (macLibraryType == AddLibraryWizard::FrameworkType) // we will generate a separate -F -framework line
......@@ -489,31 +482,45 @@ static QString generateLibsSnippet(AddLibraryWizard::Platforms platforms,
if (windowsPlatforms) {
QString windowsString = windowsScopes(windowsPlatforms);
str << windowsString << ":CONFIG(release, debug|release): LIBS += ";
if (useSubfolders)
str << simpleLibraryPathSnippet << "release/ " << "-l" << libName << "\n";
else if (addSuffix)
str << appendSpaceIfNotEmpty(simpleLibraryPathSnippet) << "-l" << libName << "\n";
if (useSubfolders) {
if (generateLibPath)
str << "-L" << libraryPathSnippet << smartQuote(targetRelativePath + QLatin1String("release/")) << ' ';
str << "-l" << libName << "\n";
} else if (addSuffix) {
if (generateLibPath)
str << "-L" << libraryPathSnippet << smartQuote(targetRelativePath) << ' ';
str << "-l" << libName << "\n";
}
str << "else:" << windowsString << ":CONFIG(debug, debug|release): LIBS += ";
if (useSubfolders)
str << simpleLibraryPathSnippet << "debug/ " << "-l" << libName << "\n";
else if (addSuffix)
str << appendSpaceIfNotEmpty(simpleLibraryPathSnippet) << "-l" << libName << "d\n";
if (useSubfolders) {
if (generateLibPath)
str << "-L" << libraryPathSnippet << smartQuote(targetRelativePath + QLatin1String("debug/")) << ' ';
str << "-l" << libName << "\n";
} else if (addSuffix) {
if (generateLibPath)
str << "-L" << libraryPathSnippet << smartQuote(targetRelativePath) << ' ';
str << "-l" << libName << "d\n";
}
generatedPlatforms |= windowsPlatforms;
}
if (diffPlatforms & AddLibraryWizard::MacPlatform) {
if (generatedPlatforms)
str << "else:";
str << "mac: LIBS += " << appendSpaceIfNotEmpty(macLibraryPathSnippet)
<< "-framework " << libName << "\n";
str << "mac: LIBS += ";
if (generateLibPath)
str << "-F" << libraryPathSnippet << smartQuote(targetRelativePath) << ' ';
str << "-framework " << libName << "\n";
generatedPlatforms |= AddLibraryWizard::MacPlatform;
}
if (commonPlatforms) {
if (generatedPlatforms)
str << "else:";
str << commonScopes(commonPlatforms, generatedPlatforms) << ": LIBS += "
<< appendSpaceIfNotEmpty(simpleLibraryPathSnippet) << "-l" << libName << "\n";
str << commonScopes(commonPlatforms, generatedPlatforms) << ": LIBS += ";
if (generateLibPath)
str << "-L" << libraryPathSnippet << smartQuote(targetRelativePath) << ' ';
str << "-l" << libName << "\n";
}
return snippetMessage;
}
......@@ -521,9 +528,9 @@ static QString generateLibsSnippet(AddLibraryWizard::Platforms platforms,
static QString generateIncludePathSnippet(const QString &includeRelativePath)
{
return QLatin1String("\nINCLUDEPATH += $$PWD/")
+ includeRelativePath + QLatin1Char('\n')
+ smartQuote(includeRelativePath) + QLatin1Char('\n')
+ QLatin1String("DEPENDPATH += $$PWD/")
+ includeRelativePath + QLatin1Char('\n');
+ smartQuote(includeRelativePath) + QLatin1Char('\n');
}
static QString generatePreTargetDepsSnippet(AddLibraryWizard::Platforms platforms,
......@@ -535,9 +542,9 @@ static QString generatePreTargetDepsSnippet(AddLibraryWizard::Platforms platform
if (linkageType != AddLibraryWizard::StaticLinkage)
return QString();
// if needed it contains: PRE_TARGETDEPS += $$[pwd]/_PATH_TO_LIB_WITHOUT_LIB_NAME_
// it contains: PRE_TARGETDEPS += $$[pwd]/
const QString preTargetDepsSnippet = QLatin1String("PRE_TARGETDEPS += $$") +
pwd + QLatin1Char('/') + targetRelativePath;
pwd + QLatin1Char('/');
QString snippetMessage;
QTextStream str(&snippetMessage);
......@@ -555,16 +562,16 @@ static QString generatePreTargetDepsSnippet(AddLibraryWizard::Platforms platform
str << "win32-g++:CONFIG(release, debug|release): "
<< preTargetDepsSnippet;
if (useSubfolders)
str << "release/" << "lib" << libName << ".a\n";
str << smartQuote(targetRelativePath + QLatin1String("release/lib") + libName + QLatin1String(".a")) << '\n';
else if (addSuffix)
str << "lib" << libName << ".a\n";
str << smartQuote(targetRelativePath + QLatin1String("lib") + libName + QLatin1String(".a")) << '\n';
str << "else:win32-g++:CONFIG(debug, debug|release): "
<< preTargetDepsSnippet;
if (useSubfolders)
str << "debug/" << "lib" << libName << ".a\n";
str << smartQuote(targetRelativePath + QLatin1String("debug/lib") + libName + QLatin1String(".a")) << '\n';
else if (addSuffix)
str << "lib" << libName << "d.a\n";
str << smartQuote(targetRelativePath + QLatin1String("lib") + libName + QLatin1String("d.a")) << '\n';
}
if (windowsPlatforms & AddLibraryWizard::WindowsMSVCPlatform) {
if (windowsPlatforms & AddLibraryWizard::WindowsMinGWPlatform)
......@@ -572,21 +579,22 @@ static QString generatePreTargetDepsSnippet(AddLibraryWizard::Platforms platform
str << "win32:!win32-g++:CONFIG(release, debug|release): "
<< preTargetDepsSnippet;
if (useSubfolders)
str << "release/" << libName << ".lib\n";
str << smartQuote(targetRelativePath + QLatin1String("release/") + libName + QLatin1String(".lib")) << '\n';
else if (addSuffix)
str << libName << ".lib\n";
str << smartQuote(targetRelativePath + libName + QLatin1String(".lib")) << '\n';
str << "else:win32:!win32-g++:CONFIG(debug, debug|release): "
<< preTargetDepsSnippet;
if (useSubfolders)
str << "debug/" << libName << ".lib\n";
str << smartQuote(targetRelativePath + QLatin1String("debug/") + libName + QLatin1String(".lib")) << '\n';
else if (addSuffix)
str << libName << "d.lib\n";
str << smartQuote(targetRelativePath + libName + QLatin1String("d.lib")) << '\n';
}
generatedPlatforms |= windowsPlatforms;
} else {
if (windowsPlatforms & AddLibraryWizard::WindowsMSVCPlatform) {
str << "win32:!win32-g++: " << preTargetDepsSnippet << libName << ".lib\n";
str << "win32:!win32-g++: " << preTargetDepsSnippet
<< smartQuote(targetRelativePath + libName + QLatin1String(".lib")) << "\n";
generatedPlatforms |= AddLibraryWizard::WindowsMSVCPlatform; // mingw will be handled with common scopes
}
// mingw not generated yet, will be joined with unix like
......@@ -596,7 +604,7 @@ static QString generatePreTargetDepsSnippet(AddLibraryWizard::Platforms platform
if (generatedPlatforms)
str << "else:";
str << commonScopes(commonPlatforms, generatedPlatforms) << ": "
<< preTargetDepsSnippet << "lib" << libName << ".a\n";
<< preTargetDepsSnippet << smartQuote(targetRelativePath + QLatin1String("lib") + libName + QLatin1String(".a")) << "\n";
}
return snippetMessage;
}
......@@ -788,8 +796,6 @@ QString NonInternalLibraryDetailsController::snippet() const
libName = fi.completeBaseName().mid(3); // cut the "lib" prefix
}
QString targetRelativePath;
QString includeRelativePath;
bool useSubfolders = false;
bool addSuffix = false;
if (isWindowsGroupVisible()) {
......@@ -803,6 +809,9 @@ QString NonInternalLibraryDetailsController::snippet() const
if (platforms() & (AddLibraryWizard::WindowsMinGWPlatform | AddLibraryWizard::WindowsMSVCPlatform))
addSuffix = libraryDetailsWidget()->addSuffixCheckBox->isChecked() || removeSuffix;
}
QString targetRelativePath;
QString includeRelativePath;
if (isIncludePathVisible()) { // generate also the path to lib
QFileInfo pfi(proFile());
QDir pdir = pfi.absoluteDir();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment