summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2017-12-24 02:34:05 -0600
committerandroid-build-team Robot2017-12-24 02:34:05 -0600
commit867ed81ea2defdcfbad6bc48c6efd7f332c807f1 (patch)
tree79f386f157dcda7b6d456af1dfd613f20f86db1c
parentf0a0b5982dedd6bf643baf4822acc6d139dadb4f (diff)
parentccc8154e3d2d6007557b97b5f5c6496df98f3861 (diff)
downloadplatform-system-libvintf-867ed81ea2defdcfbad6bc48c6efd7f332c807f1.tar.gz
platform-system-libvintf-867ed81ea2defdcfbad6bc48c6efd7f332c807f1.tar.xz
platform-system-libvintf-867ed81ea2defdcfbad6bc48c6efd7f332c807f1.zip
Snap for 4517567 from ccc8154e3d2d6007557b97b5f5c6496df98f3861 to pi-release
Change-Id: Idb71ce80be99fed3c3d33475ba0e745d4e89cd13
-rw-r--r--CompatibilityMatrix.cpp26
-rw-r--r--assemble_vintf.cpp40
-rw-r--r--include/vintf/CompatibilityMatrix.h2
-rw-r--r--include/vintf/HalGroup.h4
-rw-r--r--include/vintf/XmlFile.h1
-rw-r--r--include/vintf/XmlFileGroup.h12
-rw-r--r--include/vintf/parse_xml.h1
-rw-r--r--test/Android.bp4
-rw-r--r--test/LibVintfTest.cpp (renamed from test/main.cpp)51
9 files changed, 123 insertions, 18 deletions
diff --git a/CompatibilityMatrix.cpp b/CompatibilityMatrix.cpp
index 521c44b..7afaa9b 100644
--- a/CompatibilityMatrix.cpp
+++ b/CompatibilityMatrix.cpp
@@ -109,7 +109,12 @@ bool CompatibilityMatrix::addAllHalsAsOptional(CompatibilityMatrix* other, std::
109 109
110 if (existingHal == nullptr) { 110 if (existingHal == nullptr) {
111 halToAdd.optional = true; 111 halToAdd.optional = true;
112 add(std::move(halToAdd)); 112 if (!add(std::move(halToAdd))) {
113 if (error) {
114 *error = "Cannot add HAL " + name + " for unknown reason.";
115 }
116 return false;
117 }
113 continue; 118 continue;
114 } 119 }
115 120
@@ -130,6 +135,25 @@ bool CompatibilityMatrix::addAllHalsAsOptional(CompatibilityMatrix* other, std::
130 return true; 135 return true;
131} 136}
132 137
138bool CompatibilityMatrix::addAllXmlFilesAsOptional(CompatibilityMatrix* other, std::string* error) {
139 if (other == nullptr || other->level() <= level()) {
140 return true;
141 }
142 for (auto& pair : other->mXmlFiles) {
143 const std::string& name = pair.first;
144 MatrixXmlFile& xmlFileToAdd = pair.second;
145
146 xmlFileToAdd.mOptional = true;
147 if (!addXmlFile(std::move(xmlFileToAdd))) {
148 if (error) {
149 *error = "Cannot add XML File " + name + " for unknown reason.";
150 }
151 return false;
152 }
153 }
154 return true;
155}
156
133bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) { 157bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
134 return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals && 158 return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals &&
135 lft.mXmlFiles == rgt.mXmlFiles && 159 lft.mXmlFiles == rgt.mXmlFiles &&
diff --git a/assemble_vintf.cpp b/assemble_vintf.cpp
index 19294c6..17f5d0c 100644
--- a/assemble_vintf.cpp
+++ b/assemble_vintf.cpp
@@ -40,6 +40,21 @@ static const std::string gConfigPrefix = "android-base-";
40static const std::string gConfigSuffix = ".cfg"; 40static const std::string gConfigSuffix = ".cfg";
41static const std::string gBaseConfig = "android-base.cfg"; 41static const std::string gBaseConfig = "android-base.cfg";
42 42
43// An input stream with a name.
44// The input stream may be an actual file, or a stringstream for testing.
45// It takes ownership on the istream.
46class NamedIstream {
47 public:
48 NamedIstream(const std::string& name, std::unique_ptr<std::istream>&& stream)
49 : mName(name), mStream(std::move(stream)) {}
50 const std::string& name() const { return mName; }
51 std::istream& stream() { return *mStream; }
52
53 private:
54 std::string mName;
55 std::unique_ptr<std::istream> mStream;
56};
57
43/** 58/**
44 * Slurps the device manifest file and add build time flag to it. 59 * Slurps the device manifest file and add build time flag to it.
45 */ 60 */
@@ -241,7 +256,7 @@ class AssembleVintf {
241 } 256 }
242 } 257 }
243 258
244 if (!halManifest->addAll(std::move(halToAdd), &error)) { 259 if (!halManifest->addAllHals(&halToAdd, &error)) {
245 std::cerr << "File \"" << path << "\" cannot be added: conflict on HAL \"" << error 260 std::cerr << "File \"" << path << "\" cannot be added: conflict on HAL \"" << error
246 << "\" with an existing HAL. See <hal> with the same name " 261 << "\" with an existing HAL. See <hal> with the same name "
247 << "in previously parsed files or previously declared in this file." 262 << "in previously parsed files or previously declared in this file."
@@ -467,16 +482,16 @@ class AssembleVintf {
467 AssembleFunc assemble) { 482 AssembleFunc assemble) {
468 Schemas<Schema> schemas; 483 Schemas<Schema> schemas;
469 Schema schema; 484 Schema schema;
470 if (!converter(&schema, read(mInFiles.front()))) { 485 if (!converter(&schema, read(mInFiles.front().stream()))) {
471 return TRY_NEXT; 486 return TRY_NEXT;
472 } 487 }
473 auto firstType = schema.type(); 488 auto firstType = schema.type();
474 schemas.emplace_back(mInFilePaths.front(), std::move(schema)); 489 schemas.emplace_back(mInFiles.front().name(), std::move(schema));
475 490
476 for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) { 491 for (auto it = mInFiles.begin() + 1; it != mInFiles.end(); ++it) {
477 Schema additionalSchema; 492 Schema additionalSchema;
478 const std::string fileName = mInFilePaths[std::distance(mInFiles.begin(), it)]; 493 const std::string& fileName = it->name();
479 if (!converter(&additionalSchema, read(*it))) { 494 if (!converter(&additionalSchema, read(it->stream()))) {
480 std::cerr << "File \"" << fileName << "\" is not a valid " << firstType << " " 495 std::cerr << "File \"" << fileName << "\" is not a valid " << firstType << " "
481 << schemaName << " (but the first file is a valid " << firstType << " " 496 << schemaName << " (but the first file is a valid " << firstType << " "
482 << schemaName << "). Error: " << converter.lastError() << std::endl; 497 << schemaName << "). Error: " << converter.lastError() << std::endl;
@@ -528,10 +543,10 @@ class AssembleVintf {
528 } 543 }
529 544
530 bool openInFile(const char* path) { 545 bool openInFile(const char* path) {
531 mInFilePaths.push_back(path); 546 auto s = std::make_unique<std::ifstream>(path);
532 mInFiles.push_back({}); 547 if (!s->is_open()) return false;
533 mInFiles.back().open(path); 548 mInFiles.emplace(mInFiles.end(), std::string{path}, std::move(s));
534 return mInFiles.back().is_open(); 549 return true;
535 } 550 }
536 551
537 bool openCheckFile(const char* path) { 552 bool openCheckFile(const char* path) {
@@ -541,8 +556,8 @@ class AssembleVintf {
541 556
542 void resetInFiles() { 557 void resetInFiles() {
543 for (auto& inFile : mInFiles) { 558 for (auto& inFile : mInFiles) {
544 inFile.clear(); 559 inFile.stream().clear();
545 inFile.seekg(0); 560 inFile.stream().seekg(0);
546 } 561 }
547 } 562 }
548 563
@@ -582,8 +597,7 @@ class AssembleVintf {
582 } 597 }
583 598
584 private: 599 private:
585 std::vector<std::string> mInFilePaths; 600 std::vector<NamedIstream> mInFiles;
586 std::vector<std::ifstream> mInFiles;
587 std::unique_ptr<std::ofstream> mOutFileRef; 601 std::unique_ptr<std::ofstream> mOutFileRef;
588 std::ifstream mCheckFile; 602 std::ifstream mCheckFile;
589 bool mOutputMatrix = false; 603 bool mOutputMatrix = false;
diff --git a/include/vintf/CompatibilityMatrix.h b/include/vintf/CompatibilityMatrix.h
index 23cbe53..1bb6387 100644
--- a/include/vintf/CompatibilityMatrix.h
+++ b/include/vintf/CompatibilityMatrix.h
@@ -68,6 +68,8 @@ struct CompatibilityMatrix : public HalGroup<MatrixHal>, public XmlFileGroup<Mat
68 // Return nullptr if none is found. 68 // Return nullptr if none is found.
69 std::pair<MatrixHal*, VersionRange*> getHalWithMajorVersion(const std::string& name, 69 std::pair<MatrixHal*, VersionRange*> getHalWithMajorVersion(const std::string& name,
70 size_t majorVer); 70 size_t majorVer);
71 // Similar to addAllHalsAsOptional but on <xmlfile> entries.
72 bool addAllXmlFilesAsOptional(CompatibilityMatrix* other, std::string* error);
71 73
72 status_t fetchAllInformation(const std::string &path); 74 status_t fetchAllInformation(const std::string &path);
73 75
diff --git a/include/vintf/HalGroup.h b/include/vintf/HalGroup.h
index e3f0c7c..0facab4 100644
--- a/include/vintf/HalGroup.h
+++ b/include/vintf/HalGroup.h
@@ -33,8 +33,8 @@ struct HalGroup {
33 public: 33 public:
34 virtual ~HalGroup() {} 34 virtual ~HalGroup() {}
35 // Move all hals from another HalGroup to this. 35 // Move all hals from another HalGroup to this.
36 bool addAll(HalGroup&& other, std::string* error = nullptr) { 36 bool addAllHals(HalGroup* other, std::string* error = nullptr) {
37 for (auto& pair : other.mHals) { 37 for (auto& pair : other->mHals) {
38 if (!add(std::move(pair.second))) { 38 if (!add(std::move(pair.second))) {
39 if (error) { 39 if (error) {
40 *error = pair.first; 40 *error = pair.first;
diff --git a/include/vintf/XmlFile.h b/include/vintf/XmlFile.h
index 787e217..1ad57bb 100644
--- a/include/vintf/XmlFile.h
+++ b/include/vintf/XmlFile.h
@@ -44,6 +44,7 @@ struct MatrixXmlFile : public XmlFile {
44 bool operator==(const MatrixXmlFile& other) const; 44 bool operator==(const MatrixXmlFile& other) const;
45 45
46 private: 46 private:
47 friend struct CompatibilityMatrix;
47 friend struct MatrixXmlFileConverter; 48 friend struct MatrixXmlFileConverter;
48 friend struct LibVintfTest; 49 friend struct LibVintfTest;
49 bool mOptional; 50 bool mOptional;
diff --git a/include/vintf/XmlFileGroup.h b/include/vintf/XmlFileGroup.h
index be2bb73..524efc9 100644
--- a/include/vintf/XmlFileGroup.h
+++ b/include/vintf/XmlFileGroup.h
@@ -58,6 +58,18 @@ struct XmlFileGroup {
58 return ConstMultiMapValueIterable<std::string, T>(mXmlFiles); 58 return ConstMultiMapValueIterable<std::string, T>(mXmlFiles);
59 } 59 }
60 60
61 bool addAllXmlFiles(XmlFileGroup* other, std::string* error) {
62 for (auto& pair : other->mXmlFiles) {
63 if (!addXmlFile(std::move(pair.second))) {
64 if (error) {
65 *error = pair.first;
66 }
67 return false;
68 }
69 }
70 return true;
71 }
72
61 protected: 73 protected:
62 map mXmlFiles; 74 map mXmlFiles;
63}; 75};
diff --git a/include/vintf/parse_xml.h b/include/vintf/parse_xml.h
index 61c4f8e..a92facf 100644
--- a/include/vintf/parse_xml.h
+++ b/include/vintf/parse_xml.h
@@ -33,6 +33,7 @@ enum SerializeFlag : uint32_t {
33 33
34 EVERYTHING = 0, 34 EVERYTHING = 0,
35 HALS_ONLY = ~NO_HALS, 35 HALS_ONLY = ~NO_HALS,
36 XMLFILES_ONLY = ~NO_XMLFILES,
36}; 37};
37using SerializeFlags = uint32_t; 38using SerializeFlags = uint32_t;
38 39
diff --git a/test/Android.bp b/test/Android.bp
index fe1696c..5c9fc43 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -17,7 +17,9 @@ cc_test {
17 defaults: ["libvintf-defaults"], 17 defaults: ["libvintf-defaults"],
18 host_supported: true, 18 host_supported: true,
19 gtest: false, 19 gtest: false,
20 srcs: ["main.cpp"], 20 srcs: [
21 "LibVintfTest.cpp",
22 ],
21 23
22 shared_libs: [ 24 shared_libs: [
23 "libbase", 25 "libbase",
diff --git a/test/main.cpp b/test/LibVintfTest.cpp
index 09f2ad0..8c07075 100644
--- a/test/main.cpp
+++ b/test/LibVintfTest.cpp
@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#define LOG_TAG "LibHidlTest" 17#define LOG_TAG "LibVintfTest"
18 18
19#include <algorithm> 19#include <algorithm>
20#include <functional> 20#include <functional>
@@ -106,6 +106,10 @@ public:
106 bool addAllHalsAsOptional(CompatibilityMatrix* cm1, CompatibilityMatrix* cm2, std::string* e) { 106 bool addAllHalsAsOptional(CompatibilityMatrix* cm1, CompatibilityMatrix* cm2, std::string* e) {
107 return cm1->addAllHalsAsOptional(cm2, e); 107 return cm1->addAllHalsAsOptional(cm2, e);
108 } 108 }
109 bool addAllXmlFilesAsOptional(CompatibilityMatrix* cm1, CompatibilityMatrix* cm2,
110 std::string* e) {
111 return cm1->addAllXmlFilesAsOptional(cm2, e);
112 }
109 113
110 std::map<std::string, HalInterface> testHalInterfaces() { 114 std::map<std::string, HalInterface> testHalInterfaces() {
111 HalInterface intf; 115 HalInterface intf;
@@ -2232,6 +2236,51 @@ TEST_F(LibVintfTest, AddOptionalHalMajorVersion) {
2232 "</compatibility-matrix>\n"); 2236 "</compatibility-matrix>\n");
2233} 2237}
2234 2238
2239TEST_F(LibVintfTest, AddOptionalXmlFile) {
2240 CompatibilityMatrix cm1;
2241 CompatibilityMatrix cm2;
2242 std::string error;
2243 std::string xml;
2244
2245 xml =
2246 "<compatibility-matrix version=\"1.0\" type=\"framework\" level=\"1\">\n"
2247 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2248 " <name>foo</name>\n"
2249 " <version>1.0-2</version>\n"
2250 " <path>/foo/bar/baz.xsd</path>\n"
2251 " </xmlfile>\n"
2252 "</compatibility-matrix>\n";
2253 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2254 << gCompatibilityMatrixConverter.lastError();
2255
2256 xml =
2257 "<compatibility-matrix version=\"1.0\" type=\"framework\" level=\"2\">\n"
2258 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2259 " <name>foo</name>\n"
2260 " <version>1.1-3</version>\n"
2261 " <path>/foo/bar/quux.xsd</path>\n"
2262 " </xmlfile>\n"
2263 "</compatibility-matrix>\n";
2264 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2265 << gCompatibilityMatrixConverter.lastError();
2266
2267 EXPECT_TRUE(addAllXmlFilesAsOptional(&cm1, &cm2, &error)) << error;
2268 xml = gCompatibilityMatrixConverter(cm1, SerializeFlag::XMLFILES_ONLY);
2269 EXPECT_EQ(xml,
2270 "<compatibility-matrix version=\"1.0\" type=\"framework\" level=\"1\">\n"
2271 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2272 " <name>foo</name>\n"
2273 " <version>1.0-2</version>\n"
2274 " <path>/foo/bar/baz.xsd</path>\n"
2275 " </xmlfile>\n"
2276 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2277 " <name>foo</name>\n"
2278 " <version>1.1-3</version>\n"
2279 " <path>/foo/bar/quux.xsd</path>\n"
2280 " </xmlfile>\n"
2281 "</compatibility-matrix>\n");
2282}
2283
2235} // namespace vintf 2284} // namespace vintf
2236} // namespace android 2285} // namespace android
2237 2286