diff options
Diffstat (limited to 'src/lib/corelib/tools/setupprojectparameters.cpp')
-rw-r--r-- | src/lib/corelib/tools/setupprojectparameters.cpp | 122 |
1 files changed, 98 insertions, 24 deletions
diff --git a/src/lib/corelib/tools/setupprojectparameters.cpp b/src/lib/corelib/tools/setupprojectparameters.cpp index a06ffc4bd..e9212c165 100644 --- a/src/lib/corelib/tools/setupprojectparameters.cpp +++ b/src/lib/corelib/tools/setupprojectparameters.cpp @@ -38,6 +38,8 @@ ****************************************************************************/ #include "setupprojectparameters.h" +#include "buildoptions.h" + #include <logging/logger.h> #include <logging/translator.h> #include <tools/buildgraphlocker.h> @@ -45,8 +47,10 @@ #include <tools/jsonhelper.h> #include <tools/profile.h> #include <tools/qbsassert.h> +#include <tools/qttools.h> #include <tools/scripttools.h> #include <tools/settings.h> +#include <tools/stringconstants.h> #include <QtCore/qdir.h> #include <QtCore/qfileinfo.h> @@ -89,21 +93,24 @@ public: mutable QVariantMap buildConfigurationTree; mutable QVariantMap overriddenValuesTree; mutable QVariantMap finalBuildConfigTree; + int maxJobCount = 0; bool overrideBuildGraphData; bool dryRun; bool logElapsedTime; bool forceProbeExecution; bool waitLockBuildGraph; - bool fallbackProviderEnabled = true; SetupProjectParameters::RestoreBehavior restoreBehavior; ErrorHandlingMode propertyCheckingMode; ErrorHandlingMode productErrorMode; + DeprecationWarningMode deprecationWarningMode = defaultDeprecationWarningMode(); QProcessEnvironment environment; }; } // namespace Internal -SetupProjectParameters::SetupProjectParameters() : d(new Internal::SetupProjectParametersPrivate) +using namespace Internal; + +SetupProjectParameters::SetupProjectParameters() : d(new SetupProjectParametersPrivate) { } @@ -125,6 +132,11 @@ template<> ErrorHandlingMode fromJson(const QJsonValue &v) return ErrorHandlingMode::Strict; } +template<> DeprecationWarningMode fromJson(const QJsonValue &v) +{ + return deprecationWarningModeFromName(v.toString()); +} + template<> SetupProjectParameters::RestoreBehavior fromJson(const QJsonValue &v) { const QString value = v.toString(); @@ -145,15 +157,18 @@ SetupProjectParameters SetupProjectParameters::fromJson(const QJsonObject &data) setValueFromJson(params.d->projectFilePath, data, "project-file-path"); setValueFromJson(params.d->buildRoot, data, "build-root"); setValueFromJson(params.d->settingsBaseDir, data, "settings-directory"); + setValueFromJson(params.d->maxJobCount, data, "max-job-count"); + if (params.maxJobCount() <= 0) + params.setMaxJobCount(BuildOptions::defaultMaxJobCount()); setValueFromJson(params.d->overriddenValues, data, "overridden-properties"); setValueFromJson(params.d->dryRun, data, "dry-run"); setValueFromJson(params.d->logElapsedTime, data, "log-time"); setValueFromJson(params.d->forceProbeExecution, data, "force-probe-execution"); setValueFromJson(params.d->waitLockBuildGraph, data, "wait-lock-build-graph"); - setValueFromJson(params.d->fallbackProviderEnabled, data, "fallback-provider-enabled"); setValueFromJson(params.d->environment, data, "environment"); setValueFromJson(params.d->restoreBehavior, data, "restore-behavior"); setValueFromJson(params.d->propertyCheckingMode, data, "error-handling-mode"); + setValueFromJson(params.d->deprecationWarningMode, data, "deprecation-warning-mode"); params.d->productErrorMode = params.d->propertyCheckingMode; return params; } @@ -219,6 +234,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. */ @@ -243,7 +296,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 @@ -325,6 +378,27 @@ void SetupProjectParameters::setSettingsDirectory(const QString &settingsBaseDir } /*! + * \brief Returns the maximum number of threads to employ when resolving the project. + * If the value is not valid (i.e. <= 0), a sensible one will be derived from the number of + * available processor cores. + * The default is 0. + * \sa BuildOptions::defaultMaxJobCount + */ +int SetupProjectParameters::maxJobCount() const +{ + return d->maxJobCount; +} + +/*! + * \brief Controls how many threads to employ when resolving the project. + * A value <= 0 leaves the decision to qbs. + */ +void SetupProjectParameters::setMaxJobCount(int jobCount) +{ + d->maxJobCount = jobCount; +} + +/*! * Returns the overridden values of the build configuration. */ QVariantMap SetupProjectParameters::overriddenValues() const @@ -354,7 +428,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()); } } @@ -395,7 +469,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()) @@ -405,7 +479,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; } @@ -442,7 +516,7 @@ ErrorInfo SetupProjectParameters::expandBuildConfiguration() QVariantMap expandedConfig = expandedBuildConfiguration(profile, configurationName(), &err); if (err.hasError()) return err; - if (d->buildConfiguration != expandedConfig) { + if (!qVariantMapsEqual(d->buildConfiguration, expandedConfig)) { d->buildConfigurationTree.clear(); d->buildConfiguration = expandedConfig; } @@ -547,22 +621,6 @@ void SetupProjectParameters::setWaitLockBuildGraph(bool wait) } /*! - * \brief Returns true if qbs should fall back to pkg-config if a dependency is not found. - */ -bool SetupProjectParameters::fallbackProviderEnabled() const -{ - return d->fallbackProviderEnabled; -} - -/*! - * Controls whether to fall back to pkg-config if a dependency is not found. - */ -void SetupProjectParameters::setFallbackProviderEnabled(bool enable) -{ - d->fallbackProviderEnabled = enable; -} - -/*! * \brief Gets the environment used while resolving the project. */ QProcessEnvironment SetupProjectParameters::environment() const @@ -688,4 +746,20 @@ void SetupProjectParameters::setProductErrorMode(ErrorHandlingMode mode) d->productErrorMode = mode; } +/*! + * \brief Indicates how deprecated constructs are handled. + */ +DeprecationWarningMode SetupProjectParameters::deprecationWarningMode() const +{ + return d->deprecationWarningMode; +} + +/*! + * \brief Specifies the behavior on encountering deprecated constructs. + */ +void SetupProjectParameters::setDeprecationWarningMode(DeprecationWarningMode mode) +{ + d->deprecationWarningMode = mode; +} + } // namespace qbs |