summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Komissarov <abbapoh@gmail.com>2022-08-25 21:34:18 +0300
committerIvan Komissarov <ABBAPOH@gmail.com>2022-09-16 11:50:04 +0000
commit77f50cc5c4f61a8d79843631796a3b81e282c54e (patch)
tree15c4089f8de071507cb4d2ab0035cf67002d8ba7 /src
parent3a2ff079c3f38c5aff7249e1c55a2cdc6a50e2e8 (diff)
downloadqbs-77f50cc5c4f61a8d79843631796a3b81e282c54e.tar.gz
Take into account qbs module props used by providers when caching
Otherwise, we end up with wrong modules used by products that override qbs module props such as sysroot. Change-Id: Id5a74e8198217e737fb02a506ac7a9bb216b4d60 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/lib/corelib/language/moduleproviderinfo.h7
-rw-r--r--src/lib/corelib/language/moduleproviderloader.cpp55
-rw-r--r--src/lib/corelib/language/moduleproviderloader.h5
-rw-r--r--src/lib/corelib/tools/persistence.cpp2
4 files changed, 60 insertions, 9 deletions
diff --git a/src/lib/corelib/language/moduleproviderinfo.h b/src/lib/corelib/language/moduleproviderinfo.h
index 8ed6f008d..d4c375f4a 100644
--- a/src/lib/corelib/language/moduleproviderinfo.h
+++ b/src/lib/corelib/language/moduleproviderinfo.h
@@ -92,7 +92,12 @@ using ModuleProviderInfoList = std::vector<ModuleProviderInfo>;
// Persistent info stored between sessions
struct StoredModuleProviderInfo
{
- using CacheKey = std::tuple<QString /*name*/, QVariantMap /*config*/, int /*lookup*/>;
+ using CacheKey = std::tuple<
+ QString /*name*/,
+ QVariantMap /*config*/,
+ QVariantMap /*qbsModule*/,
+ int /*lookup*/
+ >;
using ModuleProvidersCache = QHash<CacheKey, ModuleProviderInfo>;
ModuleProvidersCache providers;
diff --git a/src/lib/corelib/language/moduleproviderloader.cpp b/src/lib/corelib/language/moduleproviderloader.cpp
index 8ff08a1b7..3e62d9ed9 100644
--- a/src/lib/corelib/language/moduleproviderloader.cpp
+++ b/src/lib/corelib/language/moduleproviderloader.cpp
@@ -116,10 +116,11 @@ ModuleProviderLoader::ModuleProviderResult ModuleProviderLoader::executeModulePr
return {};
QStringList allSearchPaths;
ModuleProviderResult result;
+ const auto qbsModule = evaluateQbsModule(product);
for (const auto &[name, lookupType] : providers) {
const QVariantMap config = getModuleProviderConfig(product).value(name.toString()).toMap();
- ModuleProviderInfo &info =
- m_storedModuleProviderInfo.providers[{name.toString(), config, int(lookupType)}];
+ ModuleProviderInfo &info = m_storedModuleProviderInfo.providers[
+ {name.toString(), config, qbsModule, int(lookupType)}];
const bool fromCache = !info.name.isEmpty();
if (!fromCache) {
info.name = name;
@@ -128,7 +129,7 @@ ModuleProviderLoader::ModuleProviderResult ModuleProviderLoader::executeModulePr
if (!info.providerFile.isEmpty()) {
qCDebug(lcModuleLoader) << "Running provider" << name << "at" << info.providerFile;
info.searchPaths = evaluateModuleProvider(
- product, dependsItemLocation, name, info.providerFile, config);
+ product, dependsItemLocation, name, info.providerFile, config, qbsModule);
info.transientOutput = m_parameters.dryRun();
}
}
@@ -260,12 +261,47 @@ QString ModuleProviderLoader::findModuleProviderFile(
return {};
}
+QVariantMap ModuleProviderLoader::evaluateQbsModule(ProductContext &product) const
+{
+ const QString properties[] = {
+ QStringLiteral("sysroot"),
+ };
+ const auto qbsItemValue = std::static_pointer_cast<ItemValue>(
+ product.item->property(StringConstants::qbsModule()));
+ QVariantMap result;
+ for (const auto &property : properties) {
+ auto value = m_evaluator->value(qbsItemValue->item(), property).toVariant();
+ if (value.isValid())
+ result[property] = std::move(value);
+ }
+ return result;
+}
+
+Item *ModuleProviderLoader::createProviderScope(
+ ProductContext &product, const QVariantMap &qbsModule)
+{
+ const auto qbsItemValue = std::static_pointer_cast<ItemValue>(
+ product.item->property(StringConstants::qbsModule()));
+
+ Item *fakeQbsModule = Item::create(product.item->pool(), ItemType::Scope);
+
+ for (auto it = qbsModule.begin(), end = qbsModule.end(); it != end; ++it) {
+ fakeQbsModule->setProperty(it.key(), VariantValue::create(it.value()));
+ }
+
+ Item *scope = Item::create(product.item->pool(), ItemType::Scope);
+ scope->setFile(qbsItemValue->item()->file());
+ scope->setProperty(StringConstants::qbsModule(), ItemValue::create(fakeQbsModule));
+ return scope;
+}
+
QStringList ModuleProviderLoader::evaluateModuleProvider(
ProductContext &product,
const CodeLocation &dependsItemLocation,
const QualifiedId &name,
const QString &providerFile,
- const QVariantMap &moduleConfig)
+ const QVariantMap &moduleConfig,
+ const QVariantMap &qbsModule)
{
QTemporaryFile dummyItemFile;
if (!dummyItemFile.open()) {
@@ -278,6 +314,11 @@ QStringList ModuleProviderLoader::evaluateModuleProvider(
const QString projectBuildDir = product.project->item->variantProperty(
StringConstants::buildDirectoryProperty())->value().toString();
const QString searchPathBaseDir = ModuleProviderInfo::outputDirPath(projectBuildDir, name);
+
+ // include qbs module into hash
+ auto jsConfig = moduleConfig;
+ jsConfig[StringConstants::qbsModule()] = qbsModule;
+
QTextStream stream(&dummyItemFile);
using Qt::endl;
setupDefaultCodec(stream);
@@ -286,7 +327,7 @@ QStringList ModuleProviderLoader::evaluateModuleProvider(
stream << "import '" << providerFile << "' as Provider" << endl;
stream << "Provider {" << endl;
stream << " name: " << toJSLiteral(name.toString()) << endl;
- stream << " property var config: (" << toJSLiteral(moduleConfig) << ')' << endl;
+ stream << " property var config: (" << toJSLiteral(jsConfig) << ')' << endl;
stream << " outputBaseDir: FileInfo.joinPaths(baseDirPrefix, "
" Utilities.getHash(JSON.stringify(config)))" << endl;
stream << " property string baseDirPrefix: " << toJSLiteral(searchPathBaseDir) << endl;
@@ -303,7 +344,9 @@ QStringList ModuleProviderLoader::evaluateModuleProvider(
.arg(providerFile, providerItem->typeName(),
BuiltinDeclarations::instance().nameForType(ItemType::ModuleProvider)));
}
- providerItem->setParent(product.item);
+
+ providerItem->setScope(createProviderScope(product, qbsModule));
+
providerItem->overrideProperties(moduleConfig, name.toString(), m_parameters, m_logger);
m_probesResolver->resolveProbes(&product, providerItem);
diff --git a/src/lib/corelib/language/moduleproviderloader.h b/src/lib/corelib/language/moduleproviderloader.h
index ce1ec7f0a..91a32ec80 100644
--- a/src/lib/corelib/language/moduleproviderloader.h
+++ b/src/lib/corelib/language/moduleproviderloader.h
@@ -111,12 +111,15 @@ private:
std::optional<std::vector<QualifiedId>> getModuleProviders(Item *item);
QString findModuleProviderFile(const QualifiedId &name, ModuleProviderLookup lookupType);
+ QVariantMap evaluateQbsModule(ProductContext &product) const;
+ Item *createProviderScope(ProductContext &product, const QVariantMap &qbsModule);
QStringList evaluateModuleProvider(
ProductContext &product,
const CodeLocation &location,
const QualifiedId &name,
const QString &providerFile,
- const QVariantMap &moduleConfig);
+ const QVariantMap &moduleConfig,
+ const QVariantMap &qbsModule);
private:
ItemReader *const m_reader{nullptr};
diff --git a/src/lib/corelib/tools/persistence.cpp b/src/lib/corelib/tools/persistence.cpp
index 95211e894..1940b19de 100644
--- a/src/lib/corelib/tools/persistence.cpp
+++ b/src/lib/corelib/tools/persistence.cpp
@@ -48,7 +48,7 @@
namespace qbs {
namespace Internal {
-static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE-130";
+static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE-131";
NoBuildGraphError::NoBuildGraphError(const QString &filePath)
: ErrorInfo(Tr::tr("Build graph not found for configuration '%1'. Expected location was '%2'.")