BareMetal: Fix device selection properties parsing in UVSC

A problem is that the source *.pdsc file contains a five main separate
items: 'package', 'family', 'sub-family', 'device', and 'device variant'.
Each of this item may contain an unique properties, which we need to
separate in a resulting device selection structure.

But, earlier we ignore the item types at filling of the device selection,
that lead to overwriting some properties in a wrong way for a some *.pdsc
files.

To solve it, we introduce the five item types: Package, Family, SubFamily,
Device, and DeviceVariant. In this case we take in account a current item
type at filling the resulting device selection structure to exclude an
unexpected values.

Change-Id: Iaa79d1b82c284a5f30004ebdd7abc02e77872b4e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Denis Shienkov
2020-04-24 14:42:28 +03:00
parent adf0e57195
commit 261c104175

View File

@@ -147,9 +147,10 @@ static void fillSvd(QXmlStreamReader &in, QString &svd)
class DeviceSelectionItem final : public TreeItem class DeviceSelectionItem final : public TreeItem
{ {
public: public:
enum Type { Root, Package, Family, SubFamily, Device, DeviceVariant };
enum Column { NameColumn, VersionColumn, VendorNameColumn }; enum Column { NameColumn, VersionColumn, VendorNameColumn };
explicit DeviceSelectionItem() explicit DeviceSelectionItem(const Type &type = Root)
{} : type(type) {}
QVariant data(int column, int role) const final QVariant data(int column, int role) const final
{ {
@@ -170,6 +171,7 @@ public:
return hasChildren() ? Qt::ItemIsEnabled : (Qt::ItemIsEnabled | Qt::ItemIsSelectable); return hasChildren() ? Qt::ItemIsEnabled : (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
} }
const Type type;
QString desc; QString desc;
QString fullPath; QString fullPath;
QString name; QString name;
@@ -235,7 +237,7 @@ void DeviceSelectionModel::parsePackage(const QString &packageFile)
void DeviceSelectionModel::parsePackage(QXmlStreamReader &in, const QString &packageFile) void DeviceSelectionModel::parsePackage(QXmlStreamReader &in, const QString &packageFile)
{ {
// Create and fill the 'package' item. // Create and fill the 'package' item.
const auto child = new DeviceSelectionItem; const auto child = new DeviceSelectionItem(DeviceSelectionItem::Package);
rootItem()->appendChild(child); rootItem()->appendChild(child);
child->fullPath = packageFile; child->fullPath = packageFile;
child->version = extractPackVersion(packageFile); child->version = extractPackVersion(packageFile);
@@ -266,7 +268,7 @@ void DeviceSelectionModel::parsePackage(QXmlStreamReader &in, const QString &pac
void DeviceSelectionModel::parseFamily(QXmlStreamReader &in, DeviceSelectionItem *parent) void DeviceSelectionModel::parseFamily(QXmlStreamReader &in, DeviceSelectionItem *parent)
{ {
// Create and fill the 'family' item. // Create and fill the 'family' item.
const auto child = new DeviceSelectionItem; const auto child = new DeviceSelectionItem(DeviceSelectionItem::Family);
parent->appendChild(child); parent->appendChild(child);
const QXmlStreamAttributes attrs = in.attributes(); const QXmlStreamAttributes attrs = in.attributes();
child->name = attrs.value("Dfamily").toString(); child->name = attrs.value("Dfamily").toString();
@@ -292,7 +294,7 @@ void DeviceSelectionModel::parseFamily(QXmlStreamReader &in, DeviceSelectionItem
void DeviceSelectionModel::parseSubFamily(QXmlStreamReader &in, DeviceSelectionItem *parent) void DeviceSelectionModel::parseSubFamily(QXmlStreamReader &in, DeviceSelectionItem *parent)
{ {
// Create and fill the 'sub-family' item. // Create and fill the 'sub-family' item.
const auto child = new DeviceSelectionItem; const auto child = new DeviceSelectionItem(DeviceSelectionItem::SubFamily);
parent->appendChild(child); parent->appendChild(child);
const QXmlStreamAttributes attrs = in.attributes(); const QXmlStreamAttributes attrs = in.attributes();
child->name = attrs.value("DsubFamily").toString(); child->name = attrs.value("DsubFamily").toString();
@@ -313,7 +315,7 @@ void DeviceSelectionModel::parseSubFamily(QXmlStreamReader &in, DeviceSelectionI
void DeviceSelectionModel::parseDevice(QXmlStreamReader &in, DeviceSelectionItem *parent) void DeviceSelectionModel::parseDevice(QXmlStreamReader &in, DeviceSelectionItem *parent)
{ {
// Create and fill the 'device' item. // Create and fill the 'device' item.
const auto child = new DeviceSelectionItem; const auto child = new DeviceSelectionItem(DeviceSelectionItem::Device);
parent->appendChild(child); parent->appendChild(child);
const QXmlStreamAttributes attrs = in.attributes(); const QXmlStreamAttributes attrs = in.attributes();
child->name = attrs.value("Dname").toString(); child->name = attrs.value("Dname").toString();
@@ -338,7 +340,7 @@ void DeviceSelectionModel::parseDevice(QXmlStreamReader &in, DeviceSelectionItem
void DeviceSelectionModel::parseDeviceVariant(QXmlStreamReader &in, DeviceSelectionItem *parent) void DeviceSelectionModel::parseDeviceVariant(QXmlStreamReader &in, DeviceSelectionItem *parent)
{ {
// Create and fill the 'device-variant' item. // Create and fill the 'device-variant' item.
const auto child = new DeviceSelectionItem; const auto child = new DeviceSelectionItem(DeviceSelectionItem::DeviceVariant);
parent->appendChild(child); parent->appendChild(child);
const QXmlStreamAttributes attrs = in.attributes(); const QXmlStreamAttributes attrs = in.attributes();
child->name = attrs.value("Dvariant").toString(); child->name = attrs.value("Dvariant").toString();
@@ -393,31 +395,15 @@ DeviceSelection DeviceSelectionView::buildSelection(const DeviceSelectionItem *i
DeviceSelection::Memories &mems = selection.memories; DeviceSelection::Memories &mems = selection.memories;
DeviceSelection::Package &pkg = selection.package; DeviceSelection::Package &pkg = selection.package;
do { auto extractBaseProps = [&selection, &algs, &cpu, &mems](const DeviceSelectionItem *item) {
if (selection.name.isEmpty()) if (selection.name.isEmpty())
selection.name = item->name; selection.name = item->name;
else if (selection.subfamily.isEmpty())
selection.subfamily = item->name;
else if (selection.family.isEmpty())
selection.family = item->name;
else if (pkg.name.isEmpty())
pkg.name = item->name;
if (selection.desc.isEmpty()) if (selection.desc.isEmpty())
selection.desc = item->desc; selection.desc = item->desc;
else if (pkg.desc.isEmpty())
pkg.desc = item->desc;
if (selection.vendorId.isEmpty()) if (selection.vendorId.isEmpty())
selection.vendorId = item->vendorId; selection.vendorId = item->vendorId;
else if (pkg.vendorId.isEmpty())
pkg.vendorId = item->vendorId;
if (selection.vendorName.isEmpty()) if (selection.vendorName.isEmpty())
selection.vendorName = item->vendorName; selection.vendorName = item->vendorName;
else if (pkg.vendorName.isEmpty())
pkg.vendorName = item->vendorName;
if (selection.svd.isEmpty()) if (selection.svd.isEmpty())
selection.svd = item->svd; selection.svd = item->svd;
@@ -430,13 +416,6 @@ DeviceSelection DeviceSelectionView::buildSelection(const DeviceSelectionItem *i
if (cpu.mpu.isEmpty()) if (cpu.mpu.isEmpty())
cpu.mpu = item->cpu.mpu; cpu.mpu = item->cpu.mpu;
if (pkg.file.isEmpty())
pkg.file = item->fullPath;
if (pkg.url.isEmpty())
pkg.url = item->url;
if (pkg.version.isEmpty())
pkg.version = item->version;
// Add only new flash algorithms. // Add only new flash algorithms.
for (const DeviceSelection::Algorithm &newAlg : item->algorithms) { for (const DeviceSelection::Algorithm &newAlg : item->algorithms) {
const bool contains = Utils::contains(algs, [&newAlg](const DeviceSelection::Algorithm &existAlg) { const bool contains = Utils::contains(algs, [&newAlg](const DeviceSelection::Algorithm &existAlg) {
@@ -454,6 +433,33 @@ DeviceSelection DeviceSelectionView::buildSelection(const DeviceSelectionItem *i
if (!contains) if (!contains)
mems.push_back(newMem); mems.push_back(newMem);
} }
};
auto extractPackageProps = [&pkg](const DeviceSelectionItem *item) {
pkg.desc = item->desc;
pkg.file = item->fullPath;
pkg.name = item->name;
pkg.url = item->url;
pkg.vendorId = item->vendorId;
pkg.vendorName = item->vendorName;
pkg.version = item->version;
};
do {
if (item->type == DeviceSelectionItem::DeviceVariant
|| item->type == DeviceSelectionItem::Device) {
extractBaseProps(item);
} else if (item->type == DeviceSelectionItem::SubFamily) {
extractBaseProps(item);
if (selection.subfamily.isEmpty())
selection.subfamily = item->name;
} else if (item->type == DeviceSelectionItem::Family) {
extractBaseProps(item);
if (selection.family.isEmpty())
selection.family = item->name;
} else if (item->type == DeviceSelectionItem::Package) {
extractPackageProps(item);
}
} while ((item->level() > 1) && (item = static_cast<const DeviceSelectionItem *>(item->parent()))); } while ((item->level() > 1) && (item = static_cast<const DeviceSelectionItem *>(item->parent())));
// Fix relative SVD file sub-path to make it as an absolute file path. // Fix relative SVD file sub-path to make it as an absolute file path.