1 /*
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
29 namespace {
30
PrintUsage(const char * exe_name)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
main(int argc,char * argv[])38 int 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
46 if (auto res = ParseApiFile(argv[1]); res.ok()) {
47 latest = std::move(*res);
48 } else {
49 LOG(FATAL) << "parsing sysprop_library API file " << argv[1]
50 << " failed: " << res.error();
51 }
52
53 if (auto res = ParseApiFile(argv[2]); res.ok()) {
54 current = std::move(*res);
55 } else {
56 LOG(FATAL) << "parsing sysprop_library API file " << argv[2]
57 << " failed: " << res.error();
58 }
59
60 if (auto res = CompareApis(latest, current); !res.ok()) {
61 LOG(ERROR) << "sysprop_library API check failed:\n" << res.error();
62 return EXIT_FAILURE;
63 }
64 }
65