summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2017-09-19 15:36:21 -0500
committerYifan Hong2017-09-19 16:48:21 -0500
commitdb127cb06b951acb7febcaf8a052251bf4a84a9c (patch)
treea65dba8c7e71d0e1c2d204d8974ec89b75defc32 /parse_xml.cpp
parentdb6423e7f0d1d3d40aa84c81ccdee06db438c653 (diff)
downloadplatform-system-libvintf-db127cb06b951acb7febcaf8a052251bf4a84a9c.tar.gz
platform-system-libvintf-db127cb06b951acb7febcaf8a052251bf4a84a9c.tar.xz
platform-system-libvintf-db127cb06b951acb7febcaf8a052251bf4a84a9c.zip
Fix XML file metaversioning logic.
* define libvintf metaversion at VintfObject::kMetaVersion. * libvintf@x.y should be able to read all XML files at version x.z, where y >= z. * The minor version of compatibility-matrix.version now means the minimum libvintf metaversion that can parse this file. This CL does not change any behavior on existing XML files at version 1.0. Test: libvintf_test Test: vintf_object_test Bug: 62801658 Change-Id: If1b74ef83e56565a715e50786a7531ed086755f7
Diffstat (limited to 'parse_xml.cpp')
-rw-r--r--parse_xml.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/parse_xml.cpp b/parse_xml.cpp
index 259fd4e..0b3a514 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -25,6 +25,7 @@
25 25
26#include <tinyxml2.h> 26#include <tinyxml2.h>
27 27
28#include "constants.h"
28#include "parse_string.h" 29#include "parse_string.h"
29 30
30namespace android { 31namespace android {
@@ -747,7 +748,7 @@ const ManifestXmlFileConverter manifestXmlFileConverter{};
747struct HalManifestConverter : public XmlNodeConverter<HalManifest> { 748struct HalManifestConverter : public XmlNodeConverter<HalManifest> {
748 std::string elementName() const override { return "manifest"; } 749 std::string elementName() const override { return "manifest"; }
749 void mutateNode(const HalManifest &m, NodeType *root, DocType *d) const override { 750 void mutateNode(const HalManifest &m, NodeType *root, DocType *d) const override {
750 appendAttr(root, "version", HalManifest::kVersion); 751 appendAttr(root, "version", m.getMetaVersion());
751 appendAttr(root, "type", m.mType); 752 appendAttr(root, "type", m.mType);
752 753
753 appendChildren(root, manifestHalConverter, m.getHals(), d); 754 appendChildren(root, manifestHalConverter, m.getHals(), d);
@@ -760,15 +761,15 @@ struct HalManifestConverter : public XmlNodeConverter<HalManifest> {
760 appendChildren(root, manifestXmlFileConverter, m.getXmlFiles(), d); 761 appendChildren(root, manifestXmlFileConverter, m.getXmlFiles(), d);
761 } 762 }
762 bool buildObject(HalManifest *object, NodeType *root) const override { 763 bool buildObject(HalManifest *object, NodeType *root) const override {
763 Version version;
764 std::vector<ManifestHal> hals; 764 std::vector<ManifestHal> hals;
765 if (!parseAttr(root, "version", &version) || 765 if (!parseAttr(root, "version", &object->mMetaVersion) ||
766 !parseAttr(root, "type", &object->mType) || 766 !parseAttr(root, "type", &object->mType) ||
767 !parseChildren(root, manifestHalConverter, &hals)) { 767 !parseChildren(root, manifestHalConverter, &hals)) {
768 return false; 768 return false;
769 } 769 }
770 if (version != HalManifest::kVersion) { 770 if (!kMetaVersion.minorAtLeast(object->mMetaVersion)) {
771 this->mLastError = "Unrecognized manifest.version"; 771 this->mLastError = "Unrecognized manifest.version " + to_string(object->mMetaVersion) +
772 " (libvintf@" + to_string(kMetaVersion) + ")";
772 return false; 773 return false;
773 } 774 }
774 if (object->mType == SchemaType::DEVICE) { 775 if (object->mType == SchemaType::DEVICE) {
@@ -857,7 +858,7 @@ const MatrixXmlFileConverter matrixXmlFileConverter{};
857struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatrix> { 858struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatrix> {
858 std::string elementName() const override { return "compatibility-matrix"; } 859 std::string elementName() const override { return "compatibility-matrix"; }
859 void mutateNode(const CompatibilityMatrix &m, NodeType *root, DocType *d) const override { 860 void mutateNode(const CompatibilityMatrix &m, NodeType *root, DocType *d) const override {
860 appendAttr(root, "version", CompatibilityMatrix::kVersion); 861 appendAttr(root, "version", m.getMinimumMetaVersion());
861 appendAttr(root, "type", m.mType); 862 appendAttr(root, "type", m.mType);
862 appendChildren(root, matrixHalConverter, iterateValues(m.mHals), d); 863 appendChildren(root, matrixHalConverter, iterateValues(m.mHals), d);
863 if (m.mType == SchemaType::FRAMEWORK) { 864 if (m.mType == SchemaType::FRAMEWORK) {
@@ -910,8 +911,9 @@ struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatri
910 } 911 }
911 } 912 }
912 913
913 if (version != CompatibilityMatrix::kVersion) { 914 if (!kMetaVersion.minorAtLeast(version)) {
914 this->mLastError = "Unrecognized compatibility-matrix.version"; 915 this->mLastError = "Unrecognized compatibility-matrix.version " + to_string(version) +
916 " (libvintf@" + to_string(kMetaVersion) + ")";
915 return false; 917 return false;
916 } 918 }
917 for (auto &&hal : hals) { 919 for (auto &&hal : hals) {