blob: 211702e7267a8a22e945d3ae4305a01b106a7d38 [file] [log] [blame]
Yifan Honga72bde72017-09-28 13:36:48 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <iostream>
18
19#include <vintf/parse_xml.h>
20#include "utils.h"
21
22namespace android {
23namespace vintf {
24
25template <typename T>
26std::unique_ptr<T> readObject(const std::string& path, const XmlConverter<T>& converter) {
27 std::string xml;
28 status_t err = details::gFetcher->fetch(path, xml);
29 if (err != OK) {
30 std::cerr << "Error: Cannot read '" << path << "': " << strerror(-err) << std::endl;
31 return nullptr;
32 }
33 auto ret = std::make_unique<T>();
34 if (!converter(ret.get(), xml)) {
35 std::cerr << "Error: Cannot parse '" << path << "': " << converter.lastError() << std::endl;
36 return nullptr;
37 }
38 return ret;
39}
40
41} // namespace vintf
42} // namespace android
43
44int main(int argc, char** argv) {
45 using namespace android::vintf;
46 if (argc < 3) {
47 std::cerr << "usage: " << argv[0] << " <manifest.xml> <matrix.xml>" << std::endl
48 << " Checks compatibility between a manifest and a compatibility matrix."
49 << std::endl;
50 return -1;
51 }
52
53 auto manifest = readObject(argv[1], gHalManifestConverter);
54 auto matrix = readObject(argv[2], gCompatibilityMatrixConverter);
55 if (manifest == nullptr || matrix == nullptr) {
56 return -1;
57 }
58
59 std::string error;
60 if (!manifest->checkCompatibility(*matrix, &error)) {
61 std::cerr << "Error: Incompatible: " << error << std::endl;
62 std::cout << "false" << std::endl;
63 return 1;
64 }
65
66 std::cout << "true" << std::endl;
67 return 0;
68}