blob: 081ca845d8bf4a1c32cbdac1ad5072c84b2fd16b [file] [log] [blame]
Inseob Kim900fbad2019-06-26 14:09:20 +09001/*
2 * Copyright (C) 2019 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#define LOG_TAG "sysprop_api_checker_main"
18
19#include <android-base/logging.h>
20#include <cstdio>
21#include <cstdlib>
22#include <string>
23
24#include <getopt.h>
25
26#include "ApiChecker.h"
27#include "Common.h"
28
29namespace {
30
31[[noreturn]] void PrintUsage(const char* exe_name) {
32 std::printf("Usage: %s latest-file current-file\n", exe_name);
33 std::exit(EXIT_FAILURE);
34}
35
36} // namespace
37
38int main(int argc, char* argv[]) {
39 if (argc != 3) {
40 std::fprintf(stderr, "%s needs 2 arguments\n", argv[0]);
41 PrintUsage(argv[0]);
42 }
43
44 sysprop::SyspropLibraryApis latest, current;
45
Bernie Innocenti7ac8da42020-02-06 23:30:12 +090046 if (auto res = ParseApiFile(argv[1]); res.ok()) {
Inseob Kim900fbad2019-06-26 14:09:20 +090047 latest = std::move(*res);
48 } else {
49 LOG(FATAL) << "parsing sysprop_library API file " << argv[1]
50 << " failed: " << res.error();
51 }
52
Bernie Innocenti7ac8da42020-02-06 23:30:12 +090053 if (auto res = ParseApiFile(argv[2]); res.ok()) {
Inseob Kim900fbad2019-06-26 14:09:20 +090054 current = std::move(*res);
55 } else {
56 LOG(FATAL) << "parsing sysprop_library API file " << argv[2]
57 << " failed: " << res.error();
58 }
59
Bernie Innocenti7ac8da42020-02-06 23:30:12 +090060 if (auto res = CompareApis(latest, current); !res.ok()) {
Inseob Kim900fbad2019-06-26 14:09:20 +090061 LOG(ERROR) << "sysprop_library API check failed:\n" << res.error();
62 return EXIT_FAILURE;
63 }
64}