forked from qt-creator/qt-creator
CMake: Use Utils::FileName where appropriate
Change-Id: I3ab0a68920e27ebcf4e1dd58180a72ded58b892e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -269,13 +269,13 @@ QSet<Core::Id> BuildDirManager::updateCodeModel(CppTools::ProjectPartBuilder &pp
|
||||
// So remove the toolchain include paths, so that at least those end up in the correct
|
||||
// place.
|
||||
QStringList cxxflags = getCXXFlagsFor(cbt, targetDataCache);
|
||||
QSet<QString> tcIncludes;
|
||||
QSet<Utils::FileName> tcIncludes;
|
||||
foreach (const HeaderPath &hp, tc->systemHeaderPaths(cxxflags, sysroot))
|
||||
tcIncludes.insert(hp.path());
|
||||
tcIncludes.insert(Utils::FileName::fromString(hp.path()));
|
||||
QStringList includePaths;
|
||||
foreach (const QString &i, cbt.includeFiles) {
|
||||
foreach (const Utils::FileName &i, cbt.includeFiles) {
|
||||
if (!tcIncludes.contains(i))
|
||||
includePaths.append(i);
|
||||
includePaths.append(i.toString());
|
||||
}
|
||||
includePaths += buildDirectory().toString();
|
||||
ppBuilder.setIncludePaths(includePaths);
|
||||
@@ -285,7 +285,8 @@ QSet<Core::Id> BuildDirManager::updateCodeModel(CppTools::ProjectPartBuilder &pp
|
||||
ppBuilder.setDisplayName(cbt.title);
|
||||
|
||||
const QSet<Core::Id> partLanguages
|
||||
= QSet<Core::Id>::fromList(ppBuilder.createProjectPartsForFiles(cbt.files));
|
||||
= QSet<Core::Id>::fromList(ppBuilder.createProjectPartsForFiles(
|
||||
Utils::transform(cbt.files, [](const Utils::FileName &fn) { return fn.toString(); })));
|
||||
|
||||
languages.unite(partLanguages);
|
||||
}
|
||||
@@ -424,10 +425,10 @@ void BuildDirManager::extractData()
|
||||
// Do not insert topCMake into m_cmakeFiles: The project already watches that!
|
||||
|
||||
// Find cbp file
|
||||
QString cbpFile = CMakeManager::findCbpFile(workDirectory().toString());
|
||||
Utils::FileName cbpFile = Utils::FileName::fromString(CMakeManager::findCbpFile(workDirectory().toString()));
|
||||
if (cbpFile.isEmpty())
|
||||
return;
|
||||
m_cmakeFiles.insert(Utils::FileName::fromString(cbpFile));
|
||||
m_cmakeFiles.insert(cbpFile);
|
||||
|
||||
// Add CMakeCache.txt file:
|
||||
Utils::FileName cacheFile = workDirectory();
|
||||
@@ -439,7 +440,7 @@ void BuildDirManager::extractData()
|
||||
CMakeCbpParser cbpparser;
|
||||
CMakeTool *cmake = CMakeKitInformation::cmakeTool(kit());
|
||||
// Parsing
|
||||
if (!cbpparser.parseCbpFile(cmake->pathMapper(), cbpFile, sourceDirectory().toString()))
|
||||
if (!cbpparser.parseCbpFile(cmake->pathMapper(), cbpFile, sourceDirectory()))
|
||||
return;
|
||||
|
||||
m_projectName = cbpparser.projectName();
|
||||
@@ -612,7 +613,7 @@ QStringList BuildDirManager::getCXXFlagsFor(const CMakeBuildTarget &buildTarget,
|
||||
bool BuildDirManager::extractCXXFlagsFromMake(const CMakeBuildTarget &buildTarget,
|
||||
QHash<QString, QStringList> &cache)
|
||||
{
|
||||
QString makeCommand = QDir::fromNativeSeparators(buildTarget.makeCommand);
|
||||
QString makeCommand = buildTarget.makeCommand.toString();
|
||||
int startIndex = makeCommand.indexOf('\"');
|
||||
int endIndex = makeCommand.indexOf('\"', startIndex + 1);
|
||||
if (startIndex != -1 && endIndex != -1) {
|
||||
@@ -650,7 +651,7 @@ bool BuildDirManager::extractCXXFlagsFromNinja(const CMakeBuildTarget &buildTarg
|
||||
// found
|
||||
// Get "all" target's working directory
|
||||
QByteArray ninjaFile;
|
||||
QString buildNinjaFile = QDir::fromNativeSeparators(buildTargets().at(0).workingDirectory);
|
||||
QString buildNinjaFile = buildTargets().at(0).workingDirectory.toString();
|
||||
buildNinjaFile += "/build.ninja";
|
||||
QFile buildNinja(buildNinjaFile);
|
||||
if (buildNinja.exists()) {
|
||||
|
||||
@@ -45,10 +45,10 @@ namespace Internal {
|
||||
////
|
||||
|
||||
namespace {
|
||||
int distance(const QString &targetDirectory, const FileName &fileName)
|
||||
int distance(const FileName &targetDirectory, const FileName &fileName)
|
||||
{
|
||||
const QString commonParent = commonPath(QStringList() << targetDirectory << fileName.toString());
|
||||
return targetDirectory.mid(commonParent.size()).count('/')
|
||||
const QString commonParent = commonPath(QStringList({ targetDirectory.toString(), fileName.toString() }));
|
||||
return targetDirectory.toString().mid(commonParent.size()).count('/')
|
||||
+ fileName.toString().mid(commonParent.size()).count('/');
|
||||
}
|
||||
} // namespace
|
||||
@@ -102,7 +102,7 @@ void CMakeCbpParser::sortFiles()
|
||||
foreach (const QString &unitTarget, unitTargets) {
|
||||
int index = indexOf(m_buildTargets, equal(&CMakeBuildTarget::title, unitTarget));
|
||||
if (index != -1) {
|
||||
m_buildTargets[index].files.append(fileName.toString());
|
||||
m_buildTargets[index].files.append(fileName);
|
||||
qCDebug(log) << " into" << m_buildTargets[index].title << "(target attribute)";
|
||||
continue;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ void CMakeCbpParser::sortFiles()
|
||||
// fallback for cmake < 3.3:
|
||||
if (fileName.parentDir() == parentDirectory && last) {
|
||||
// easy case, same parent directory as last file
|
||||
last->files.append(fileName.toString());
|
||||
last->files.append(fileName);
|
||||
qCDebug(log) << " into" << last->title << "(same parent)";
|
||||
} else {
|
||||
int bestDistance = std::numeric_limits<int>::max();
|
||||
@@ -141,7 +141,7 @@ void CMakeCbpParser::sortFiles()
|
||||
}
|
||||
|
||||
if (bestIndex != -1) {
|
||||
m_buildTargets[bestIndex].files.append(fileName.toString());
|
||||
m_buildTargets[bestIndex].files.append(fileName);
|
||||
last = &m_buildTargets[bestIndex];
|
||||
parentDirectory = fileName.parentDir();
|
||||
qCDebug(log) << " into" << last->title;
|
||||
@@ -156,14 +156,15 @@ void CMakeCbpParser::sortFiles()
|
||||
qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles << target.defines << target.files << "\n";
|
||||
}
|
||||
|
||||
bool CMakeCbpParser::parseCbpFile(CMakeTool::PathMapper mapper, const QString &fileName,
|
||||
const QString &sourceDirectory)
|
||||
bool CMakeCbpParser::parseCbpFile(CMakeTool::PathMapper mapper, const FileName &fileName,
|
||||
const FileName &sourceDirectory)
|
||||
{
|
||||
|
||||
m_pathMapper = mapper;
|
||||
m_buildDirectory = QFileInfo(fileName).absolutePath();
|
||||
m_buildDirectory = FileName::fromString(fileName.toFileInfo().absolutePath());
|
||||
m_sourceDirectory = sourceDirectory;
|
||||
|
||||
QFile fi(fileName);
|
||||
QFile fi(fileName.toString());
|
||||
if (fi.exists() && fi.open(QFile::ReadOnly)) {
|
||||
setDevice(&fi);
|
||||
|
||||
@@ -267,7 +268,7 @@ void CMakeCbpParser::parseBuildTarget()
|
||||
void CMakeCbpParser::parseBuildTargetOption()
|
||||
{
|
||||
if (attributes().hasAttribute("output")) {
|
||||
m_buildTarget.executable = m_pathMapper(attributes().value("output").toString());
|
||||
m_buildTarget.executable = m_pathMapper(FileName::fromString(attributes().value("output").toString()));
|
||||
} else if (attributes().hasAttribute("type")) {
|
||||
const QStringRef value = attributes().value("type");
|
||||
if (value == "0" || value == "1")
|
||||
@@ -279,9 +280,9 @@ void CMakeCbpParser::parseBuildTargetOption()
|
||||
else
|
||||
m_buildTarget.targetType = UtilityType;
|
||||
} else if (attributes().hasAttribute("working_dir")) {
|
||||
m_buildTarget.workingDirectory = attributes().value("working_dir").toString();
|
||||
m_buildTarget.workingDirectory = FileName::fromUserInput(attributes().value("working_dir").toString());
|
||||
|
||||
QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory
|
||||
QFile cmakeSourceInfoFile(m_buildTarget.workingDirectory.toString()
|
||||
+ QStringLiteral("/CMakeFiles/CMakeDirectoryInformation.cmake"));
|
||||
if (cmakeSourceInfoFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream stream(&cmakeSourceInfoFile);
|
||||
@@ -289,18 +290,19 @@ void CMakeCbpParser::parseBuildTargetOption()
|
||||
while (!stream.atEnd()) {
|
||||
const QString lineTopSource = stream.readLine().trimmed();
|
||||
if (lineTopSource.startsWith(searchSource, Qt::CaseInsensitive)) {
|
||||
m_buildTarget.sourceDirectory = lineTopSource.mid(searchSource.size());
|
||||
m_buildTarget.sourceDirectory.chop(2); // cut off ")
|
||||
QString src = lineTopSource.mid(searchSource.size());
|
||||
src.chop(2);
|
||||
m_buildTarget.sourceDirectory = FileName::fromString(src);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_buildTarget.sourceDirectory.isEmpty()) {
|
||||
QDir dir(m_buildDirectory);
|
||||
const QString relative = dir.relativeFilePath(m_buildTarget.workingDirectory);
|
||||
m_buildTarget.sourceDirectory
|
||||
= FileName::fromString(m_sourceDirectory).appendPath(relative).toString();
|
||||
QDir dir(m_buildDirectory.toString());
|
||||
const QString relative = dir.relativeFilePath(m_buildTarget.workingDirectory.toString());
|
||||
m_buildTarget.sourceDirectory = m_sourceDirectory;
|
||||
m_buildTarget.sourceDirectory.appendPath(relative).toString();
|
||||
}
|
||||
}
|
||||
while (!atEnd()) {
|
||||
@@ -352,7 +354,7 @@ void CMakeCbpParser::parseMakeCommands()
|
||||
void CMakeCbpParser::parseBuildTargetBuild()
|
||||
{
|
||||
if (attributes().hasAttribute("command"))
|
||||
m_buildTarget.makeCommand = m_pathMapper(attributes().value("command").toString());
|
||||
m_buildTarget.makeCommand = m_pathMapper(FileName::fromUserInput(attributes().value("command").toString()));
|
||||
while (!atEnd()) {
|
||||
readNext();
|
||||
if (isEndElement())
|
||||
@@ -391,7 +393,8 @@ void CMakeCbpParser::parseAdd()
|
||||
// CMake only supports <Add option=\> and <Add directory=\>
|
||||
const QXmlStreamAttributes addAttributes = attributes();
|
||||
|
||||
QString includeDirectory = m_pathMapper(addAttributes.value("directory").toString());
|
||||
FileName includeDirectory
|
||||
= m_pathMapper(FileName::fromString(addAttributes.value("directory").toString()));
|
||||
|
||||
// allow adding multiple times because order happens
|
||||
if (!includeDirectory.isEmpty())
|
||||
@@ -424,8 +427,7 @@ void CMakeCbpParser::parseAdd()
|
||||
void CMakeCbpParser::parseUnit()
|
||||
{
|
||||
FileName fileName =
|
||||
FileName::fromString(m_pathMapper(FileName::fromUserInput(attributes().value("filename")
|
||||
.toString()).toString()));
|
||||
m_pathMapper(FileName::fromUserInput(attributes().value("filename").toString()));
|
||||
|
||||
m_parsingCMakeUnit = false;
|
||||
m_unitTargets.clear();
|
||||
|
||||
@@ -47,8 +47,8 @@ namespace Internal {
|
||||
class CMakeCbpParser : public QXmlStreamReader
|
||||
{
|
||||
public:
|
||||
bool parseCbpFile(CMakeTool::PathMapper mapper, const QString &fileName,
|
||||
const QString &sourceDirectory);
|
||||
bool parseCbpFile(CMakeTool::PathMapper mapper, const Utils::FileName &fileName,
|
||||
const Utils::FileName &sourceDirectory);
|
||||
QList<ProjectExplorer::FileNode *> fileList();
|
||||
QList<ProjectExplorer::FileNode *> cmakeFileList();
|
||||
QList<CMakeBuildTarget> buildTargets();
|
||||
@@ -84,8 +84,8 @@ private:
|
||||
QList<CMakeBuildTarget> m_buildTargets;
|
||||
QString m_projectName;
|
||||
QString m_compiler;
|
||||
QString m_sourceDirectory;
|
||||
QString m_buildDirectory;
|
||||
Utils::FileName m_sourceDirectory;
|
||||
Utils::FileName m_buildDirectory;
|
||||
QStringList m_unitTargets;
|
||||
};
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ void CMakeProject::updateTargetRunConfigurations(Target *t)
|
||||
auto btIt = buildTargetHash.constFind(cmakeRc->title());
|
||||
cmakeRc->setEnabled(btIt != buildTargetHash.constEnd());
|
||||
if (btIt != buildTargetHash.constEnd()) {
|
||||
cmakeRc->setExecutable(btIt.value()->executable);
|
||||
cmakeRc->setExecutable(btIt.value()->executable.toString());
|
||||
cmakeRc->setBaseWorkingDirectory(btIt.value()->workingDirectory);
|
||||
}
|
||||
}
|
||||
@@ -434,12 +434,10 @@ void CMakeProject::updateApplicationAndDeploymentTargets()
|
||||
continue;
|
||||
|
||||
if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType)
|
||||
deploymentData.addFile(ct.executable, deploymentPrefix + buildDir.relativeFilePath(QFileInfo(ct.executable).dir().path()), DeployableFile::TypeExecutable);
|
||||
deploymentData.addFile(ct.executable.toString(), deploymentPrefix + buildDir.relativeFilePath(ct.executable.toFileInfo().dir().path()), DeployableFile::TypeExecutable);
|
||||
if (ct.targetType == ExecutableType) {
|
||||
// TODO: Put a path to corresponding .cbp file into projectFilePath?
|
||||
appTargetList.list << BuildTargetInfo(ct.title,
|
||||
FileName::fromString(ct.executable),
|
||||
FileName::fromString(ct.executable));
|
||||
appTargetList.list << BuildTargetInfo(ct.title, ct.executable, ct.executable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,17 +58,17 @@ class CMAKE_EXPORT CMakeBuildTarget
|
||||
{
|
||||
public:
|
||||
QString title;
|
||||
QString executable; // TODO: rename to output?
|
||||
Utils::FileName executable; // TODO: rename to output?
|
||||
TargetType targetType = UtilityType;
|
||||
QString workingDirectory;
|
||||
QString sourceDirectory;
|
||||
QString makeCommand;
|
||||
Utils::FileName workingDirectory;
|
||||
Utils::FileName sourceDirectory;
|
||||
Utils::FileName makeCommand;
|
||||
|
||||
// code model
|
||||
QStringList includeFiles;
|
||||
QList<Utils::FileName> includeFiles;
|
||||
QStringList compilerOptions;
|
||||
QByteArray defines;
|
||||
QStringList files;
|
||||
QList<Utils::FileName> files;
|
||||
|
||||
void clear();
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ const char TITLE_KEY[] = "CMakeProjectManager.CMakeRunConfiguation.Title";
|
||||
} // namespace
|
||||
|
||||
CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, Core::Id id, const QString &target,
|
||||
const QString &workingDirectory, const QString &title) :
|
||||
const Utils::FileName &workingDirectory, const QString &title) :
|
||||
RunConfiguration(parent, id),
|
||||
m_buildTarget(target),
|
||||
m_title(title)
|
||||
@@ -70,7 +70,7 @@ CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, Core::Id id, const
|
||||
addExtraAspect(new TerminalAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.UseTerminal")));
|
||||
|
||||
auto wd = new WorkingDirectoryAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"));
|
||||
wd->setDefaultWorkingDirectory(Utils::FileName::fromString(workingDirectory));
|
||||
wd->setDefaultWorkingDirectory(workingDirectory);
|
||||
addExtraAspect(wd);
|
||||
|
||||
ctor();
|
||||
@@ -119,10 +119,9 @@ void CMakeRunConfiguration::setExecutable(const QString &executable)
|
||||
m_buildTarget = executable;
|
||||
}
|
||||
|
||||
void CMakeRunConfiguration::setBaseWorkingDirectory(const QString &wd)
|
||||
void CMakeRunConfiguration::setBaseWorkingDirectory(const Utils::FileName &wd)
|
||||
{
|
||||
extraAspect<WorkingDirectoryAspect>()
|
||||
->setDefaultWorkingDirectory(Utils::FileName::fromString(wd));
|
||||
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(wd);
|
||||
}
|
||||
|
||||
QVariantMap CMakeRunConfiguration::toMap() const
|
||||
@@ -246,7 +245,7 @@ RunConfiguration *CMakeRunConfigurationFactory::doCreate(Target *parent, Core::I
|
||||
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
||||
const QString title(buildTargetFromId(id));
|
||||
const CMakeBuildTarget &ct = project->buildTargetForTitle(title);
|
||||
return new CMakeRunConfiguration(parent, id, ct.executable, ct.workingDirectory, ct.title);
|
||||
return new CMakeRunConfiguration(parent, id, ct.executable.toString(), ct.workingDirectory, ct.title);
|
||||
}
|
||||
|
||||
bool CMakeRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
|
||||
@@ -273,7 +272,7 @@ bool CMakeRunConfigurationFactory::canRestore(Target *parent, const QVariantMap
|
||||
|
||||
RunConfiguration *CMakeRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &map)
|
||||
{
|
||||
return new CMakeRunConfiguration(parent, idFromMap(map), QString(), QString(), QString());
|
||||
return new CMakeRunConfiguration(parent, idFromMap(map), QString(), Utils::FileName(), QString());
|
||||
}
|
||||
|
||||
QString CMakeRunConfigurationFactory::buildTargetFromId(Core::Id id)
|
||||
|
||||
@@ -39,13 +39,13 @@ class CMakeRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||
|
||||
public:
|
||||
CMakeRunConfiguration(ProjectExplorer::Target *parent, Core::Id id, const QString &target,
|
||||
const QString &workingDirectory, const QString &title);
|
||||
const Utils::FileName &workingDirectory, const QString &title);
|
||||
|
||||
ProjectExplorer::Runnable runnable() const override;
|
||||
QWidget *createConfigurationWidget() override;
|
||||
|
||||
void setExecutable(const QString &executable);
|
||||
void setBaseWorkingDirectory(const QString &workingDirectory);
|
||||
void setBaseWorkingDirectory(const Utils::FileName &workingDirectory);
|
||||
|
||||
QString title() const;
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ CMakeTool::PathMapper CMakeTool::pathMapper() const
|
||||
{
|
||||
if (m_pathMapper)
|
||||
return m_pathMapper;
|
||||
return [](const QString &s) { return s; };
|
||||
return [](const Utils::FileName &fn) { return fn; };
|
||||
}
|
||||
|
||||
void CMakeTool::readInformation(CMakeTool::QueryType type) const
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
bool matches(const QString &n, const QString &ex) const;
|
||||
};
|
||||
|
||||
typedef std::function<QString (const QString &)> PathMapper;
|
||||
typedef std::function<Utils::FileName (const Utils::FileName &)> PathMapper;
|
||||
|
||||
explicit CMakeTool(Detection d, const Core::Id &id);
|
||||
explicit CMakeTool(const QVariantMap &map, bool fromSdk);
|
||||
|
||||
Reference in New Issue
Block a user