forked from qt-creator/qt-creator
Utils: Use FilePath in TemporaryDirectory API
This helps to lower impedance in the using code. Even though TemporaryDirectory will very likely always stay on the local host, this is one of the entry points into path related string manipulation that we want to base on FilePath nowadays. Change-Id: I302016b8d65e54df94296659a54a93935d9e4627 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -567,7 +567,7 @@ int main(int argc, char **argv)
|
|||||||
temporaryCleanSettingsDir.reset(new Utils::TemporaryDirectory("qtc-test-settings"));
|
temporaryCleanSettingsDir.reset(new Utils::TemporaryDirectory("qtc-test-settings"));
|
||||||
if (!temporaryCleanSettingsDir->isValid())
|
if (!temporaryCleanSettingsDir->isValid())
|
||||||
return 1;
|
return 1;
|
||||||
options.settingsPath = temporaryCleanSettingsDir->path();
|
options.settingsPath = temporaryCleanSettingsDir->path().path();
|
||||||
}
|
}
|
||||||
if (!options.settingsPath.isEmpty())
|
if (!options.settingsPath.isEmpty())
|
||||||
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, options.settingsPath);
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, options.settingsPath);
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "temporarydirectory.h"
|
#include "temporarydirectory.h"
|
||||||
|
|
||||||
|
#include "fileutils.h"
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
@@ -64,4 +66,14 @@ QString TemporaryDirectory::masterDirectoryPath()
|
|||||||
return m_masterTemporaryDir->path();
|
return m_masterTemporaryDir->path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePath TemporaryDirectory::path() const
|
||||||
|
{
|
||||||
|
return FilePath::fromString(QTemporaryDir::path());
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath TemporaryDirectory::filePath(const QString &fileName) const
|
||||||
|
{
|
||||||
|
return FilePath::fromString(QTemporaryDir::filePath(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
class FilePath;
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT TemporaryDirectory : public QTemporaryDir
|
class QTCREATOR_UTILS_EXPORT TemporaryDirectory : public QTemporaryDir
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -39,6 +41,9 @@ public:
|
|||||||
static QTemporaryDir *masterTemporaryDirectory();
|
static QTemporaryDir *masterTemporaryDirectory();
|
||||||
static void setMasterTemporaryDirectory(const QString &pattern);
|
static void setMasterTemporaryDirectory(const QString &pattern);
|
||||||
static QString masterDirectoryPath();
|
static QString masterDirectoryPath();
|
||||||
|
|
||||||
|
FilePath path() const;
|
||||||
|
FilePath filePath(const QString &fileName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -183,7 +183,7 @@ class JLSInterface : public LanguageClient::StdIOClientInterface
|
|||||||
public:
|
public:
|
||||||
JLSInterface() = default;
|
JLSInterface() = default;
|
||||||
|
|
||||||
QString workspaceDir() const { return m_workspaceDir.path(); }
|
QString workspaceDir() const { return m_workspaceDir.path().path(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TemporaryDirectory m_workspaceDir = TemporaryDirectory("QtCreator-jls-XXXXXX");
|
TemporaryDirectory m_workspaceDir = TemporaryDirectory("QtCreator-jls-XXXXXX");
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
@@ -62,7 +63,7 @@ QString UiHeaderOnDiskManager::remove(const QString &filePath)
|
|||||||
|
|
||||||
QString UiHeaderOnDiskManager::directoryPath() const
|
QString UiHeaderOnDiskManager::directoryPath() const
|
||||||
{
|
{
|
||||||
return m_temporaryDir.path();
|
return m_temporaryDir.path().path();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UiHeaderOnDiskManager::mapPath(const QString &filePath) const
|
QString UiHeaderOnDiskManager::mapPath(const QString &filePath) const
|
||||||
|
@@ -445,7 +445,7 @@ template<class T>
|
|||||||
ClangToolRunner *ClangToolRunWorker::createRunner()
|
ClangToolRunner *ClangToolRunWorker::createRunner()
|
||||||
{
|
{
|
||||||
auto runner = new T(m_diagnosticConfig, this);
|
auto runner = new T(m_diagnosticConfig, this);
|
||||||
runner->init(m_temporaryDir.path(), m_environment);
|
runner->init(m_temporaryDir.path().path(), m_environment);
|
||||||
connect(runner, &ClangToolRunner::finishedWithSuccess,
|
connect(runner, &ClangToolRunner::finishedWithSuccess,
|
||||||
this, &ClangToolRunWorker::onRunnerFinishedWithSuccess);
|
this, &ClangToolRunWorker::onRunnerFinishedWithSuccess);
|
||||||
connect(runner, &ClangToolRunner::finishedWithFailure,
|
connect(runner, &ClangToolRunner::finishedWithFailure,
|
||||||
|
@@ -391,7 +391,7 @@ ClangToolRunner *DocumentClangToolRunner::createRunner(const CppTools::ClangDiag
|
|||||||
const Utils::Environment &env)
|
const Utils::Environment &env)
|
||||||
{
|
{
|
||||||
auto runner = new T(config, this);
|
auto runner = new T(config, this);
|
||||||
runner->init(m_temporaryDir.path(), env);
|
runner->init(m_temporaryDir.path().path(), env);
|
||||||
connect(runner, &ClangToolRunner::finishedWithSuccess,
|
connect(runner, &ClangToolRunner::finishedWithSuccess,
|
||||||
this, &DocumentClangToolRunner::onSuccess);
|
this, &DocumentClangToolRunner::onSuccess);
|
||||||
connect(runner, &ClangToolRunner::finishedWithFailure,
|
connect(runner, &ClangToolRunner::finishedWithFailure,
|
||||||
|
@@ -42,7 +42,7 @@ namespace Internal {
|
|||||||
|
|
||||||
VirtualFileSystemOverlay::VirtualFileSystemOverlay(const QString &rootPattern)
|
VirtualFileSystemOverlay::VirtualFileSystemOverlay(const QString &rootPattern)
|
||||||
: m_root(rootPattern)
|
: m_root(rootPattern)
|
||||||
, m_overlayFilePath(Utils::FilePath::fromString(m_root.filePath("vfso.yaml")))
|
, m_overlayFilePath(m_root.filePath("vfso.yaml"))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void VirtualFileSystemOverlay::update()
|
void VirtualFileSystemOverlay::update()
|
||||||
@@ -64,8 +64,7 @@ void VirtualFileSystemOverlay::update()
|
|||||||
saved.path.removeRecursively();
|
saved.path.removeRecursively();
|
||||||
saved.revision = document->document()->revision();
|
saved.revision = document->document()->revision();
|
||||||
QString error;
|
QString error;
|
||||||
saved.path = Utils::FilePath::fromString(m_root.path())
|
saved.path = m_root.filePath(doc->filePath().fileName() + ".auto");
|
||||||
.pathAppended(doc->filePath().fileName() + ".auto");
|
|
||||||
while (saved.path.exists())
|
while (saved.path.exists())
|
||||||
saved.path = saved.path + ".1";
|
saved.path = saved.path + ".1";
|
||||||
if (!doc->save(&error, saved.path, true)) {
|
if (!doc->save(&error, saved.path, true)) {
|
||||||
|
@@ -162,7 +162,7 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config)
|
|||||||
// Run a CMake project that would do qmake probing
|
// Run a CMake project that would do qmake probing
|
||||||
TemporaryDirectory qtcQMakeProbeDir("qtc-cmake-qmake-probe-XXXXXXXX");
|
TemporaryDirectory qtcQMakeProbeDir("qtc-cmake-qmake-probe-XXXXXXXX");
|
||||||
|
|
||||||
QFile cmakeListTxt(qtcQMakeProbeDir.path() + "/CMakeLists.txt");
|
QFile cmakeListTxt(qtcQMakeProbeDir.filePath("CMakeLists.txt").toString());
|
||||||
if (!cmakeListTxt.open(QIODevice::WriteOnly)) {
|
if (!cmakeListTxt.open(QIODevice::WriteOnly)) {
|
||||||
return FilePath();
|
return FilePath();
|
||||||
}
|
}
|
||||||
@@ -219,9 +219,9 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config)
|
|||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args.push_back("-S");
|
args.push_back("-S");
|
||||||
args.push_back(qtcQMakeProbeDir.path());
|
args.push_back(qtcQMakeProbeDir.path().path());
|
||||||
args.push_back("-B");
|
args.push_back("-B");
|
||||||
args.push_back(qtcQMakeProbeDir.path() + "/build");
|
args.push_back(qtcQMakeProbeDir.filePath("build").path());
|
||||||
args.push_back("-G");
|
args.push_back("-G");
|
||||||
args.push_back(cmakeGenerator);
|
args.push_back(cmakeGenerator);
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ static FilePath qmakeFromCMakeCache(const CMakeConfig &config)
|
|||||||
cmake.setCommand({cmakeExecutable, args});
|
cmake.setCommand({cmakeExecutable, args});
|
||||||
cmake.runBlocking();
|
cmake.runBlocking();
|
||||||
|
|
||||||
QFile qmakeLocationTxt(qtcQMakeProbeDir.path() + "/qmake-location.txt");
|
QFile qmakeLocationTxt(qtcQMakeProbeDir.filePath("qmake-location.txt").path());
|
||||||
if (!qmakeLocationTxt.open(QIODevice::ReadOnly)) {
|
if (!qmakeLocationTxt.open(QIODevice::ReadOnly)) {
|
||||||
return FilePath();
|
return FilePath();
|
||||||
}
|
}
|
||||||
|
@@ -200,14 +200,14 @@ public:
|
|||||||
m_canceled = false;
|
m_canceled = false;
|
||||||
|
|
||||||
m_tempDir = std::make_unique<TemporaryDirectory>("plugininstall");
|
m_tempDir = std::make_unique<TemporaryDirectory>("plugininstall");
|
||||||
m_data->extractedPath = FilePath::fromString(m_tempDir->path());
|
m_data->extractedPath = m_tempDir->path();
|
||||||
m_label->setText(PluginInstallWizard::tr("Checking archive..."));
|
m_label->setText(PluginInstallWizard::tr("Checking archive..."));
|
||||||
m_label->setType(InfoLabel::None);
|
m_label->setType(InfoLabel::None);
|
||||||
|
|
||||||
m_cancelButton->setVisible(true);
|
m_cancelButton->setVisible(true);
|
||||||
m_output->clear();
|
m_output->clear();
|
||||||
|
|
||||||
m_archive = Archive::unarchive(m_data->sourcePath, FilePath::fromString(m_tempDir->path()));
|
m_archive = Archive::unarchive(m_data->sourcePath, m_tempDir->path());
|
||||||
|
|
||||||
if (!m_archive) {
|
if (!m_archive) {
|
||||||
m_label->setType(InfoLabel::Error);
|
m_label->setType(InfoLabel::Error);
|
||||||
@@ -271,7 +271,7 @@ public:
|
|||||||
PluginSpec *coreplugin = CorePlugin::instance()->pluginSpec();
|
PluginSpec *coreplugin = CorePlugin::instance()->pluginSpec();
|
||||||
|
|
||||||
// look for plugin
|
// look for plugin
|
||||||
QDirIterator it(m_tempDir->path(),
|
QDirIterator it(m_tempDir->path().path(),
|
||||||
libraryNameFilter(),
|
libraryNameFilter(),
|
||||||
QDir::Files | QDir::NoSymLinks,
|
QDir::Files | QDir::NoSymLinks,
|
||||||
QDirIterator::Subdirectories);
|
QDirIterator::Subdirectories);
|
||||||
|
@@ -312,7 +312,7 @@ QString TemporaryDir::createFile(const QByteArray &relativePath, const QByteArra
|
|||||||
if (relativePathString.isEmpty() || QFileInfo(relativePathString).isAbsolute())
|
if (relativePathString.isEmpty() || QFileInfo(relativePathString).isAbsolute())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
const QString filePath = m_temporaryDir.path() + QLatin1Char('/') + relativePathString;
|
const QString filePath = m_temporaryDir.filePath(relativePathString).path();
|
||||||
if (!TestCase::writeFile(filePath, contents))
|
if (!TestCase::writeFile(filePath, contents))
|
||||||
return QString();
|
return QString();
|
||||||
return filePath;
|
return filePath;
|
||||||
@@ -368,7 +368,7 @@ TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath)
|
|||||||
|
|
||||||
QString TemporaryCopiedDir::absolutePath(const QByteArray &relativePath) const
|
QString TemporaryCopiedDir::absolutePath(const QByteArray &relativePath) const
|
||||||
{
|
{
|
||||||
return m_temporaryDir.path() + QLatin1Char('/') + QString::fromUtf8(relativePath);
|
return m_temporaryDir.filePath(QString::fromUtf8(relativePath)).path();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileWriterAndRemover::FileWriterAndRemover(const QString &filePath, const QByteArray &contents)
|
FileWriterAndRemover::FileWriterAndRemover(const QString &filePath, const QByteArray &contents)
|
||||||
|
@@ -155,7 +155,7 @@ public:
|
|||||||
TemporaryDir();
|
TemporaryDir();
|
||||||
|
|
||||||
bool isValid() const { return m_isValid; }
|
bool isValid() const { return m_isValid; }
|
||||||
QString path() const { return m_temporaryDir.path(); }
|
QString path() const { return m_temporaryDir.path().path(); }
|
||||||
|
|
||||||
QString createFile(const QByteArray &relativePath, const QByteArray &contents);
|
QString createFile(const QByteArray &relativePath, const QByteArray &contents);
|
||||||
|
|
||||||
|
@@ -321,7 +321,7 @@ bool PuppetCreator::build(const QString &qmlPuppetProjectFilePath) const
|
|||||||
qmakeArguments.append("CONFIG+=release");
|
qmakeArguments.append("CONFIG+=release");
|
||||||
#endif
|
#endif
|
||||||
qmakeArguments.append(qmlPuppetProjectFilePath);
|
qmakeArguments.append(qmlPuppetProjectFilePath);
|
||||||
buildSucceeded = startBuildProcess(buildDirectory.path(), qmakeCommand(), qmakeArguments, &progressDialog);
|
buildSucceeded = startBuildProcess(buildDirectory.path().path(), qmakeCommand(), qmakeArguments, &progressDialog);
|
||||||
if (buildSucceeded) {
|
if (buildSucceeded) {
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
QString buildingCommand = buildCommand();
|
QString buildingCommand = buildCommand();
|
||||||
@@ -330,7 +330,7 @@ bool PuppetCreator::build(const QString &qmlPuppetProjectFilePath) const
|
|||||||
buildArguments.append("-j");
|
buildArguments.append("-j");
|
||||||
buildArguments.append(idealProcessCount());
|
buildArguments.append(idealProcessCount());
|
||||||
}
|
}
|
||||||
buildSucceeded = startBuildProcess(buildDirectory.path(), buildingCommand, buildArguments, &progressDialog);
|
buildSucceeded = startBuildProcess(buildDirectory.path().path(), buildingCommand, buildArguments, &progressDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buildSucceeded) {
|
if (!buildSucceeded) {
|
||||||
|
@@ -48,8 +48,8 @@ QScxmlcGenerator::QScxmlcGenerator(const Project *project,
|
|||||||
m_tmpdir("qscxmlgenerator")
|
m_tmpdir("qscxmlgenerator")
|
||||||
{
|
{
|
||||||
QTC_ASSERT(targets.count() == 2, return);
|
QTC_ASSERT(targets.count() == 2, return);
|
||||||
m_header = m_tmpdir.path() + QLatin1Char('/') + targets[0].fileName();
|
m_header = m_tmpdir.filePath(targets[0].fileName()).toString();
|
||||||
m_impl = m_tmpdir.path() + QLatin1Char('/') + targets[1].fileName();
|
m_impl = m_tmpdir.filePath(targets[1].fileName()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
||||||
@@ -97,7 +97,7 @@ QStringList QScxmlcGenerator::arguments() const
|
|||||||
|
|
||||||
Utils::FilePath QScxmlcGenerator::workingDirectory() const
|
Utils::FilePath QScxmlcGenerator::workingDirectory() const
|
||||||
{
|
{
|
||||||
return Utils::FilePath::fromString(m_tmpdir.path());
|
return m_tmpdir.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
|
bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
|
||||||
|
@@ -380,8 +380,8 @@ void QtSupportPlugin::testQtProjectImporter_oneProject()
|
|||||||
SysRootKitAspect::setSysRoot(kitTemplates[2], Utils::FilePath::fromString("/some/other/path"));
|
SysRootKitAspect::setSysRoot(kitTemplates[2], Utils::FilePath::fromString("/some/other/path"));
|
||||||
|
|
||||||
QVector<Utils::FilePath> qmakePaths = {defaultQt->qmakeCommand(),
|
QVector<Utils::FilePath> qmakePaths = {defaultQt->qmakeCommand(),
|
||||||
setupQmake(defaultQt, tempDir1.path()),
|
setupQmake(defaultQt, tempDir1.path().path()),
|
||||||
setupQmake(defaultQt, tempDir2.path())};
|
setupQmake(defaultQt, tempDir2.path().path())};
|
||||||
|
|
||||||
for (int i = 1; i < qmakePaths.count(); ++i)
|
for (int i = 1; i < qmakePaths.count(); ++i)
|
||||||
QVERIFY(!QtVersionManager::version(Utils::equal(&BaseQtVersion::qmakeCommand, qmakePaths.at(i))));
|
QVERIFY(!QtVersionManager::version(Utils::equal(&BaseQtVersion::qmakeCommand, qmakePaths.at(i))));
|
||||||
@@ -412,7 +412,7 @@ void QtSupportPlugin::testQtProjectImporter_oneProject()
|
|||||||
|
|
||||||
// Finally set up importer:
|
// Finally set up importer:
|
||||||
// Copy the directoryData so that importer is free to delete it later.
|
// Copy the directoryData so that importer is free to delete it later.
|
||||||
TestQtProjectImporter importer(Utils::FilePath::fromString(tempDir1.path()),
|
TestQtProjectImporter importer(tempDir1.path(),
|
||||||
Utils::transform(testData, [](DirectoryData *i) {
|
Utils::transform(testData, [](DirectoryData *i) {
|
||||||
return static_cast<void *>(new DirectoryData(*i));
|
return static_cast<void *>(new DirectoryData(*i));
|
||||||
}));
|
}));
|
||||||
@@ -425,7 +425,7 @@ void QtSupportPlugin::testQtProjectImporter_oneProject()
|
|||||||
const QList<BuildInfo> buildInfo = importer.import(Utils::FilePath::fromString(appDir), true);
|
const QList<BuildInfo> buildInfo = importer.import(Utils::FilePath::fromString(appDir), true);
|
||||||
|
|
||||||
// VALIDATE: Basic TestImporter state:
|
// VALIDATE: Basic TestImporter state:
|
||||||
QCOMPARE(importer.projectFilePath().toString(), tempDir1.path());
|
QCOMPARE(importer.projectFilePath(), tempDir1.path());
|
||||||
QCOMPARE(importer.allDeleted(), true);
|
QCOMPARE(importer.allDeleted(), true);
|
||||||
|
|
||||||
// VALIDATE: Result looks reasonable:
|
// VALIDATE: Result looks reasonable:
|
||||||
@@ -529,7 +529,7 @@ void QtSupportPlugin::testQtProjectImporter_oneProject()
|
|||||||
QCOMPARE(newKitId, newKitIdAfterImport);
|
QCOMPARE(newKitId, newKitIdAfterImport);
|
||||||
|
|
||||||
// VALIDATE: Importer state
|
// VALIDATE: Importer state
|
||||||
QCOMPARE(importer.projectFilePath().toString(), tempDir1.path());
|
QCOMPARE(importer.projectFilePath(), tempDir1.path());
|
||||||
QCOMPARE(importer.allDeleted(), true);
|
QCOMPARE(importer.allDeleted(), true);
|
||||||
|
|
||||||
if (kitIsPersistent) {
|
if (kitIsPersistent) {
|
||||||
|
Reference in New Issue
Block a user