summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2023-05-04 13:59:48 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2023-05-05 06:52:05 +0000
commit9131082b2b217f8aca715081f9e91a870a4fa313 (patch)
tree258f0fb9718fd17e807ac4a55a63400667734229
parente149a0cb116005f3c400285bac3b6d057d8e36ac (diff)
downloadqbs-9131082b2b217f8aca715081f9e91a870a4fa313.tar.gz
Loader: Move out the setupProjectFilePath() method
... into SetupProjectParameters, where it belongs. Change-Id: I5cae2842200a053827739b947d1cd06e1bbe5ef9 Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
-rw-r--r--src/lib/corelib/buildgraph/buildgraphloader.cpp3
-rw-r--r--src/lib/corelib/loader/loader.cpp40
-rw-r--r--src/lib/corelib/loader/loader.h2
-rw-r--r--src/lib/corelib/tools/setupprojectparameters.cpp51
-rw-r--r--src/lib/corelib/tools/setupprojectparameters.h1
-rw-r--r--tests/auto/language/tst_language.cpp2
6 files changed, 50 insertions, 49 deletions
diff --git a/src/lib/corelib/buildgraph/buildgraphloader.cpp b/src/lib/corelib/buildgraph/buildgraphloader.cpp
index f1759bd70..f0db5f81f 100644
--- a/src/lib/corelib/buildgraph/buildgraphloader.cpp
+++ b/src/lib/corelib/buildgraph/buildgraphloader.cpp
@@ -39,7 +39,6 @@
#include "buildgraphloader.h"
#include "buildgraph.h"
-#include "cycledetector.h"
#include "emptydirectoriesremover.h"
#include "productbuilddata.h"
#include "projectbuilddata.h"
@@ -220,7 +219,7 @@ bool BuildGraphLoader::checkBuildGraphCompatibility(const TopLevelProjectConstPt
if (m_parameters.projectFilePath().isEmpty())
m_parameters.setProjectFilePath(project->location.filePath());
else
- Loader::setupProjectFilePath(m_parameters);
+ m_parameters.finalizeProjectFilePath();
if (QFileInfo(project->location.filePath()) == QFileInfo(m_parameters.projectFilePath()))
return true;
QString message = Tr::tr("Stored build graph at '%1' is for project file '%2', but "
diff --git a/src/lib/corelib/loader/loader.cpp b/src/lib/corelib/loader/loader.cpp
index af91ab046..47108ffdf 100644
--- a/src/lib/corelib/loader/loader.cpp
+++ b/src/lib/corelib/loader/loader.cpp
@@ -110,7 +110,7 @@ TopLevelProjectPtr Loader::loadProject(const SetupProjectParameters &_parameters
parameters.expandBuildConfiguration();
}
- setupProjectFilePath(parameters);
+ parameters.finalizeProjectFilePath();
QBS_CHECK(QFileInfo(parameters.projectFilePath()).isAbsolute());
m_logger.qbsDebug() << "Using project file '"
<< QDir::toNativeSeparators(parameters.projectFilePath()) << "'.";
@@ -156,43 +156,5 @@ TopLevelProjectPtr Loader::loadProject(const SetupProjectParameters &_parameters
return project;
}
-void Loader::setupProjectFilePath(SetupProjectParameters &parameters)
-{
- QString projectFilePath = parameters.projectFilePath();
- if (projectFilePath.isEmpty())
- projectFilePath = QDir::currentPath();
- const QFileInfo projectFileInfo(projectFilePath);
- if (!projectFileInfo.exists())
- throw ErrorInfo(Tr::tr("Project file '%1' cannot be found.").arg(projectFilePath));
- if (projectFileInfo.isRelative())
- projectFilePath = projectFileInfo.absoluteFilePath();
- if (projectFileInfo.isFile()) {
- parameters.setProjectFilePath(projectFilePath);
- return;
- }
- if (!projectFileInfo.isDir())
- throw ErrorInfo(Tr::tr("Project file '%1' has invalid type.").arg(projectFilePath));
-
- const QStringList &actualFileNames
- = QDir(projectFilePath).entryList(StringConstants::qbsFileWildcards(), QDir::Files);
- if (actualFileNames.empty()) {
- QString error;
- if (parameters.projectFilePath().isEmpty())
- error = Tr::tr("No project file given and none found in current directory.\n");
- else
- error = Tr::tr("No project file found in directory '%1'.").arg(projectFilePath);
- throw ErrorInfo(error);
- }
- if (actualFileNames.size() > 1) {
- throw ErrorInfo(Tr::tr("More than one project file found in directory '%1'.")
- .arg(projectFilePath));
- }
- projectFilePath.append(QLatin1Char('/')).append(actualFileNames.front());
-
- projectFilePath = QDir::current().filePath(projectFilePath);
- projectFilePath = QDir::cleanPath(projectFilePath);
- parameters.setProjectFilePath(projectFilePath);
-}
-
} // namespace Internal
} // namespace qbs
diff --git a/src/lib/corelib/loader/loader.h b/src/lib/corelib/loader/loader.h
index 2c9b2b7b9..227b5cdd9 100644
--- a/src/lib/corelib/loader/loader.h
+++ b/src/lib/corelib/loader/loader.h
@@ -67,8 +67,6 @@ public:
void setStoredModuleProviderInfo(const StoredModuleProviderInfo &providerInfo);
TopLevelProjectPtr loadProject(const SetupProjectParameters &parameters);
- static void setupProjectFilePath(SetupProjectParameters &parameters);
-
private:
Logger m_logger;
ProgressObserver *m_progressObserver;
diff --git a/src/lib/corelib/tools/setupprojectparameters.cpp b/src/lib/corelib/tools/setupprojectparameters.cpp
index 564ebe873..bc07acfef 100644
--- a/src/lib/corelib/tools/setupprojectparameters.cpp
+++ b/src/lib/corelib/tools/setupprojectparameters.cpp
@@ -47,6 +47,7 @@
#include <tools/qbsassert.h>
#include <tools/scripttools.h>
#include <tools/settings.h>
+#include <tools/stringconstants.h>
#include <QtCore/qdir.h>
#include <QtCore/qfileinfo.h>
@@ -104,7 +105,9 @@ public:
} // namespace Internal
-SetupProjectParameters::SetupProjectParameters() : d(new Internal::SetupProjectParametersPrivate)
+using namespace Internal;
+
+SetupProjectParameters::SetupProjectParameters() : d(new SetupProjectParametersPrivate)
{
}
@@ -226,6 +229,44 @@ void SetupProjectParameters::setProjectFilePath(const QString &projectFilePath)
d->projectFilePath = canonicalProjectFilePath;
}
+void SetupProjectParameters::finalizeProjectFilePath()
+{
+ QString filePath = projectFilePath();
+ if (filePath.isEmpty())
+ filePath = QDir::currentPath();
+ const QFileInfo projectFileInfo(filePath);
+ if (!projectFileInfo.exists())
+ throw ErrorInfo(Tr::tr("Project file '%1' cannot be found.").arg(filePath));
+ if (projectFileInfo.isRelative())
+ filePath = projectFileInfo.absoluteFilePath();
+ if (projectFileInfo.isFile()) {
+ setProjectFilePath(filePath);
+ return;
+ }
+ if (!projectFileInfo.isDir())
+ throw ErrorInfo(Tr::tr("Project file '%1' has invalid type.").arg(filePath));
+
+ const QStringList &actualFileNames
+ = QDir(filePath).entryList(StringConstants::qbsFileWildcards(), QDir::Files);
+ if (actualFileNames.empty()) {
+ QString error;
+ if (projectFilePath().isEmpty())
+ error = Tr::tr("No project file given and none found in current directory.\n");
+ else
+ error = Tr::tr("No project file found in directory '%1'.").arg(filePath);
+ throw ErrorInfo(error);
+ }
+ if (actualFileNames.size() > 1) {
+ throw ErrorInfo(Tr::tr("More than one project file found in directory '%1'.")
+ .arg(filePath));
+ }
+ filePath.append(QLatin1Char('/')).append(actualFileNames.front());
+
+ filePath = QDir::current().filePath(filePath);
+ filePath = QDir::cleanPath(filePath);
+ setProjectFilePath(filePath);
+}
+
/*!
* \brief Returns the base path of where to put the build artifacts and store the build graph.
*/
@@ -250,7 +291,7 @@ void SetupProjectParameters::setBuildRoot(const QString &buildRoot)
// Calling mkpath() may be necessary to get the canonical build root, but if we do it,
// it must be reverted immediately afterwards as not to create directories needlessly,
// e.g in the case of a dry run build.
- Internal::DirectoryManager dirManager(buildRoot, Internal::Logger());
+ DirectoryManager dirManager(buildRoot, Logger());
// We don't do error checking here, as this is not a convenient place to report an error.
// If creation of the build directory is not possible, we will get sensible error messages
@@ -361,7 +402,7 @@ static void provideValuesTree(const QVariantMap &values, QVariantMap *valueTree)
const QStringList nameElements = (idx == -1)
? QStringList() << name
: QStringList() << name.left(idx) << name.mid(idx + 1);
- Internal::setConfigProperty(*valueTree, nameElements, it.value());
+ setConfigProperty(*valueTree, nameElements, it.value());
}
}
@@ -402,7 +443,7 @@ static QVariantMap expandedBuildConfigurationInternal(const Profile &profile,
if (err.hasError())
throw err;
if (profileKeys.empty())
- throw ErrorInfo(Internal::Tr::tr("Unknown or empty profile '%1'.").arg(profile.name()));
+ throw ErrorInfo(Tr::tr("Unknown or empty profile '%1'.").arg(profile.name()));
for (const QString &profileKey : profileKeys) {
buildConfig.insert(profileKey, profile.value(profileKey, QVariant(), &err));
if (err.hasError())
@@ -412,7 +453,7 @@ static QVariantMap expandedBuildConfigurationInternal(const Profile &profile,
// (2) Build configuration name.
if (configurationName.isEmpty())
- throw ErrorInfo(Internal::Tr::tr("No build configuration name set."));
+ throw ErrorInfo(Tr::tr("No build configuration name set."));
buildConfig.insert(QStringLiteral("qbs.configurationName"), configurationName);
return buildConfig;
}
diff --git a/src/lib/corelib/tools/setupprojectparameters.h b/src/lib/corelib/tools/setupprojectparameters.h
index 5c7bf3715..67bb5298a 100644
--- a/src/lib/corelib/tools/setupprojectparameters.h
+++ b/src/lib/corelib/tools/setupprojectparameters.h
@@ -82,6 +82,7 @@ public:
QString projectFilePath() const;
void setProjectFilePath(const QString &projectFilePath);
+ void finalizeProjectFilePath();
QString buildRoot() const;
void setBuildRoot(const QString &buildRoot);
diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp
index 5bfa51824..c81017f26 100644
--- a/tests/auto/language/tst_language.cpp
+++ b/tests/auto/language/tst_language.cpp
@@ -2486,7 +2486,7 @@ void TestLanguage::projectFileLookup()
try {
SetupProjectParameters params;
params.setProjectFilePath(projectFileInput);
- Loader::setupProjectFilePath(params);
+ params.finalizeProjectFilePath();
QVERIFY(!failureExpected);
QCOMPARE(params.projectFilePath(), projectFileOutput);
} catch (const ErrorInfo &) {