McuSupport: Support globbing in default paths

With this change default paths containing globbing characters will be
expanded to an available path.
example:  "sdk-*" will be replaced with "sdk-1.2.3" if the latter is
available.

To test the wildcards and make sure it works with QtCreator macros
a fake_kit was added containing fake packages.

Task-number: QTCREATORBUG-26900
Change-Id: I31440d24e42a6170fc5f1905f884bb3be43c57bc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Yasser Grimes
2022-10-24 18:50:27 +03:00
parent e16a5c8d0e
commit 71ae73119e
8 changed files with 179 additions and 9 deletions

View File

@@ -30,18 +30,37 @@ using namespace Utils;
namespace McuSupport::Internal {
static const Utils::FilePath expandWildcards(const Utils::FilePath& path)
{
if (!path.fileName().contains("*") && !path.fileName().contains("?"))
return path;
const FilePath p = path.parentDir();
auto entries = p.dirEntries(
Utils::FileFilter({path.fileName()}, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot));
if (entries.isEmpty())
return path;
// Return the last match (can correspond to the latest version)
sort(entries, [](const FilePath &a, const FilePath &b) { return a.fileName() < b.fileName(); });
return entries.last();
}
Macros *McuSdkRepository::globalMacros()
{
static Macros macros;
return &macros;
}
void McuSdkRepository::expandVariables()
void McuSdkRepository::expandVariablesAndWildcards()
{
for (const auto &target : std::as_const(mcuTargets)) {
auto macroExpander = getMacroExpander(*target);
for (const auto &package : target->packages()) {
package->setPath(macroExpander->expand(package->path()));
package->setPath(expandWildcards(macroExpander->expand(package->path())));
}
}
}