summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2017-12-12 15:20:33 -0600
committerYifan Hong2017-12-14 17:33:59 -0600
commita2635c418cdc039d582a50fa91f8dbaa85ce7b02 (patch)
treeae925f1e778d5144be9778e16a4ed0ee737059d9 /parse_xml.cpp
parent2027a49ab65dd24876d30a308beb1500d5123673 (diff)
downloadplatform-system-libvintf-a2635c418cdc039d582a50fa91f8dbaa85ce7b02.tar.gz
platform-system-libvintf-a2635c418cdc039d582a50fa91f8dbaa85ce7b02.tar.xz
platform-system-libvintf-a2635c418cdc039d582a50fa91f8dbaa85ce7b02.zip
Allow clean mode in assemble_vintf
XmlConverter serialization accepts optional flags that controls the sections in final output. Test: assemble_vintf -i current.xml --no-hals and --hals-only Test: assemble_vintf -i device/*/manifest.xml --no-hals and --hals-only Bug: 62720090 Change-Id: Icfc1bdf28f3bc550a75f25e17fca742522aee24c Merged-In: Icfc1bdf28f3bc550a75f25e17fca742522aee24c
Diffstat (limited to 'parse_xml.cpp')
-rw-r--r--parse_xml.cpp66
1 files changed, 50 insertions, 16 deletions
diff --git a/parse_xml.cpp b/parse_xml.cpp
index 350d10b..3df7e19 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -140,19 +140,23 @@ struct XmlNodeConverter : public XmlConverter<Object> {
140 140
141 // sub-types should implement these. 141 // sub-types should implement these.
142 virtual void mutateNode(const Object &o, NodeType *n, DocType *d) const = 0; 142 virtual void mutateNode(const Object &o, NodeType *n, DocType *d) const = 0;
143 virtual void mutateNode(const Object& o, NodeType* n, DocType* d, SerializeFlags) const {
144 mutateNode(o, n, d);
145 }
143 virtual bool buildObject(Object *o, NodeType *n) const = 0; 146 virtual bool buildObject(Object *o, NodeType *n) const = 0;
144 virtual std::string elementName() const = 0; 147 virtual std::string elementName() const = 0;
145 148
146 // convenience methods for user 149 // convenience methods for user
147 inline const std::string &lastError() const { return mLastError; } 150 inline const std::string &lastError() const { return mLastError; }
148 inline NodeType *serialize(const Object &o, DocType *d) const { 151 inline NodeType* serialize(const Object& o, DocType* d,
152 SerializeFlags flags = EVERYTHING) const {
149 NodeType *root = createNode(this->elementName(), d); 153 NodeType *root = createNode(this->elementName(), d);
150 this->mutateNode(o, root, d); 154 this->mutateNode(o, root, d, flags);
151 return root; 155 return root;
152 } 156 }
153 inline std::string serialize(const Object &o) const { 157 inline std::string serialize(const Object& o, SerializeFlags flags) const {
154 DocType *doc = createDocument(); 158 DocType *doc = createDocument();
155 appendChild(doc, serialize(o, doc)); 159 appendChild(doc, serialize(o, doc, flags));
156 std::string s = printDocument(doc); 160 std::string s = printDocument(doc);
157 deleteDocument(doc); 161 deleteDocument(doc);
158 return s; 162 return s;
@@ -176,8 +180,8 @@ struct XmlNodeConverter : public XmlConverter<Object> {
176 inline NodeType *operator()(const Object &o, DocType *d) const { 180 inline NodeType *operator()(const Object &o, DocType *d) const {
177 return serialize(o, d); 181 return serialize(o, d);
178 } 182 }
179 inline std::string operator()(const Object &o) const { 183 inline std::string operator()(const Object& o, SerializeFlags flags) const {
180 return serialize(o); 184 return serialize(o, flags);
181 } 185 }
182 inline bool operator()(Object *o, NodeType *node) const { 186 inline bool operator()(Object *o, NodeType *node) const {
183 return deserialize(o, node); 187 return deserialize(o, node);
@@ -746,19 +750,32 @@ const ManifestXmlFileConverter manifestXmlFileConverter{};
746struct HalManifestConverter : public XmlNodeConverter<HalManifest> { 750struct HalManifestConverter : public XmlNodeConverter<HalManifest> {
747 std::string elementName() const override { return "manifest"; } 751 std::string elementName() const override { return "manifest"; }
748 void mutateNode(const HalManifest &m, NodeType *root, DocType *d) const override { 752 void mutateNode(const HalManifest &m, NodeType *root, DocType *d) const override {
753 mutateNode(m, root, d, SerializeFlag::EVERYTHING);
754 }
755 void mutateNode(const HalManifest& m, NodeType* root, DocType* d,
756 SerializeFlags flags) const override {
749 appendAttr(root, "version", m.getMetaVersion()); 757 appendAttr(root, "version", m.getMetaVersion());
750 appendAttr(root, "type", m.mType); 758 appendAttr(root, "type", m.mType);
751 if (m.mLevel != Level::UNSPECIFIED) { 759 if (m.mLevel != Level::UNSPECIFIED) {
752 this->appendAttr(root, "target-level", m.mLevel); 760 this->appendAttr(root, "target-level", m.mLevel);
753 } 761 }
754 appendChildren(root, manifestHalConverter, m.getHals(), d); 762
763 if (!(flags & SerializeFlag::NO_HALS)) {
764 appendChildren(root, manifestHalConverter, m.getHals(), d);
765 }
755 if (m.mType == SchemaType::DEVICE) { 766 if (m.mType == SchemaType::DEVICE) {
756 appendChild(root, halManifestSepolicyConverter(m.device.mSepolicyVersion, d)); 767 if (!(flags & SerializeFlag::NO_SEPOLICY)) {
768 appendChild(root, halManifestSepolicyConverter(m.device.mSepolicyVersion, d));
769 }
757 } else if (m.mType == SchemaType::FRAMEWORK) { 770 } else if (m.mType == SchemaType::FRAMEWORK) {
758 appendChildren(root, vndkConverter, m.framework.mVndks, d); 771 if (!(flags & SerializeFlag::NO_VNDK)) {
772 appendChildren(root, vndkConverter, m.framework.mVndks, d);
773 }
759 } 774 }
760 775
761 appendChildren(root, manifestXmlFileConverter, m.getXmlFiles(), d); 776 if (!(flags & SerializeFlag::NO_XMLFILES)) {
777 appendChildren(root, manifestXmlFileConverter, m.getXmlFiles(), d);
778 }
762 } 779 }
763 bool buildObject(HalManifest *object, NodeType *root) const override { 780 bool buildObject(HalManifest *object, NodeType *root) const override {
764 std::vector<ManifestHal> hals; 781 std::vector<ManifestHal> hals;
@@ -859,21 +876,38 @@ const MatrixXmlFileConverter matrixXmlFileConverter{};
859struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatrix> { 876struct CompatibilityMatrixConverter : public XmlNodeConverter<CompatibilityMatrix> {
860 std::string elementName() const override { return "compatibility-matrix"; } 877 std::string elementName() const override { return "compatibility-matrix"; }
861 void mutateNode(const CompatibilityMatrix &m, NodeType *root, DocType *d) const override { 878 void mutateNode(const CompatibilityMatrix &m, NodeType *root, DocType *d) const override {
879 mutateNode(m, root, d, SerializeFlag::EVERYTHING);
880 }
881 void mutateNode(const CompatibilityMatrix& m, NodeType* root, DocType* d,
882 SerializeFlags flags) const override {
862 appendAttr(root, "version", m.getMinimumMetaVersion()); 883 appendAttr(root, "version", m.getMinimumMetaVersion());
863 appendAttr(root, "type", m.mType); 884 appendAttr(root, "type", m.mType);
864 if (m.mLevel != Level::UNSPECIFIED) { 885 if (m.mLevel != Level::UNSPECIFIED) {
865 this->appendAttr(root, "level", m.mLevel); 886 this->appendAttr(root, "level", m.mLevel);
866 } 887 }
867 appendChildren(root, matrixHalConverter, iterateValues(m.mHals), d); 888
889 if (!(flags & SerializeFlag::NO_HALS)) {
890 appendChildren(root, matrixHalConverter, iterateValues(m.mHals), d);
891 }
868 if (m.mType == SchemaType::FRAMEWORK) { 892 if (m.mType == SchemaType::FRAMEWORK) {
869 appendChildren(root, matrixKernelConverter, m.framework.mKernels, d); 893 if (!(flags & SerializeFlag::NO_KERNEL)) {
870 appendChild(root, sepolicyConverter(m.framework.mSepolicy, d)); 894 appendChildren(root, matrixKernelConverter, m.framework.mKernels, d);
871 appendChild(root, avbConverter(m.framework.mAvbMetaVersion, d)); 895 }
896 if (!(flags & SerializeFlag::NO_SEPOLICY)) {
897 appendChild(root, sepolicyConverter(m.framework.mSepolicy, d));
898 }
899 if (!(flags & SerializeFlag::NO_AVB)) {
900 appendChild(root, avbConverter(m.framework.mAvbMetaVersion, d));
901 }
872 } else if (m.mType == SchemaType::DEVICE) { 902 } else if (m.mType == SchemaType::DEVICE) {
873 appendChild(root, vndkConverter(m.device.mVndk, d)); 903 if (!(flags & SerializeFlag::NO_VNDK)) {
904 appendChild(root, vndkConverter(m.device.mVndk, d));
905 }
874 } 906 }
875 907
876 appendChildren(root, matrixXmlFileConverter, m.getXmlFiles(), d); 908 if (!(flags & SerializeFlag::NO_XMLFILES)) {
909 appendChildren(root, matrixXmlFileConverter, m.getXmlFiles(), d);
910 }
877 } 911 }
878 bool buildObject(CompatibilityMatrix *object, NodeType *root) const override { 912 bool buildObject(CompatibilityMatrix *object, NodeType *root) const override {
879 Version version; 913 Version version;