Yifan Hong | a72bde7 | 2017-09-28 13:36:48 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | namespace android { |
| 23 | namespace vintf { |
| 24 | |
| 25 | template <typename T> |
| 26 | std::unique_ptr<T> readObject(const std::string& path, const XmlConverter<T>& converter) { |
| 27 | std::string xml; |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 28 | std::string error; |
| 29 | status_t err = details::gFetcher->fetch(path, xml, &error); |
Yifan Hong | a72bde7 | 2017-09-28 13:36:48 -0700 | [diff] [blame] | 30 | if (err != OK) { |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 31 | std::cerr << "Error: Cannot read '" << path << "' (" << strerror(-err) << "): " << error |
| 32 | << std::endl; |
Yifan Hong | a72bde7 | 2017-09-28 13:36:48 -0700 | [diff] [blame] | 33 | return nullptr; |
| 34 | } |
| 35 | auto ret = std::make_unique<T>(); |
Yifan Hong | 9475706 | 2018-02-09 16:36:31 -0800 | [diff] [blame^] | 36 | if (!converter(ret.get(), xml, &error)) { |
| 37 | std::cerr << "Error: Cannot parse '" << path << "': " << error << std::endl; |
Yifan Hong | a72bde7 | 2017-09-28 13:36:48 -0700 | [diff] [blame] | 38 | return nullptr; |
| 39 | } |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | } // namespace vintf |
| 44 | } // namespace android |
| 45 | |
| 46 | int 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 | } |