McuSupport: Only expand variables from the same target

There are multiple packages in different targets that share the same
variable name (eg. QUL_BOARD_SDK_DIR). Registering all packages into the
same macro expander will make these packages overwrite the variables from
other packages.
The macro expander should only use packages included in a specific target
to expand values from (plus the global ones).

Change-Id: Ia2568696a54e48e4e77f81a9bb1a844f2910bb8d
Reviewed-by: Yasser Grimes <yasser.grimes@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Rainer Keller
2022-10-31 09:27:11 +01:00
parent e558fc4d1f
commit 2da68d4108
2 changed files with 9 additions and 6 deletions

View File

@@ -38,17 +38,20 @@ Macros *McuSdkRepository::globalMacros()
void McuSdkRepository::expandVariables()
{
auto macroExpander = getMacroExpander();
for (const auto &package : std::as_const(packages))
package->setPath(macroExpander->expand(package->path()));
for (const auto &target : std::as_const(mcuTargets)) {
auto macroExpander = getMacroExpander(*target);
for (const auto &package : target->packages()) {
package->setPath(macroExpander->expand(package->path()));
}
}
}
MacroExpanderPtr McuSdkRepository::getMacroExpander()
MacroExpanderPtr McuSdkRepository::getMacroExpander(const McuTarget &target)
{
auto macroExpander = std::make_shared<Utils::MacroExpander>();
//register the macros
for (const auto &package : std::as_const(packages)) {
for (const auto &package : target.packages()) {
macroExpander->registerVariable(package->cmakeVariableName().toLocal8Bit(),
package->label(),
[package] { return package->path().toString(); });

View File

@@ -41,7 +41,7 @@ public:
Packages packages;
void expandVariables();
MacroExpanderPtr getMacroExpander();
MacroExpanderPtr getMacroExpander(const McuTarget &target);
static Macros *globalMacros();
};