blob: f64f81d778e95541a691e2bf3e11ad54f064b990 [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;
Yifan Hong60217032018-01-08 16:19:42 -080028 std::string error;
29 status_t err = details::gFetcher->fetch(path, xml, &error);
Yifan Honga72bde72017-09-28 13:36:48 -070030 if (err != OK) {
Yifan Hong60217032018-01-08 16:19:42 -080031 std::cerr << "Error: Cannot read '" << path << "' (" << strerror(-err) << "): " << error
32 << std::endl;
Yifan Honga72bde72017-09-28 13:36:48 -070033 return nullptr;
34 }
35 auto ret = std::make_unique<T>();
Yifan Hong94757062018-02-09 16:36:31 -080036 if (!converter(ret.get(), xml, &error)) {
37 std::cerr << "Error: Cannot parse '" << path << "': " << error << std::endl;
Yifan Honga72bde72017-09-28 13:36:48 -070038 return nullptr;
39 }
40 return ret;
41}
42
43} // namespace vintf
44} // namespace android
45
46int main(int argc, char** argv) {
47 using namespace android::vintf;
48 if (argc < 3) {
49 std::cerr << "usage: " << argv[0] << " <manifest.xml> <matrix.xml>" << std::endl
50 << " Checks compatibility between a manifest and a compatibility matrix."
51 << std::endl;
52 return -1;
53 }
54
55 auto manifest = readObject(argv[1], gHalManifestConverter);
56 auto matrix = readObject(argv[2], gCompatibilityMatrixConverter);
57 if (manifest == nullptr || matrix == nullptr) {
58 return -1;
59 }
60
61 std::string error;
62 if (!manifest->checkCompatibility(*matrix, &error)) {
63 std::cerr << "Error: Incompatible: " << error << std::endl;
64 std::cout << "false" << std::endl;
65 return 1;
66 }
67
68 std::cout << "true" << std::endl;
69 return 0;
70}