diff options
| author | Inseob Kim <inseob@google.com> | 2019-07-25 01:32:07 -0700 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2019-07-25 01:32:07 -0700 |
| commit | 0dfe426db387e86f659dec16687dff4249d782b1 (patch) | |
| tree | 8311f8f8d7aaefe37eb065c599d622fce00c5ef8 | |
| parent | 674fed4acf3c82b4ab3cd7e6316ec90e527ee7ea (diff) | |
| parent | f1474186b4691bca80a52fb92ac708118deaf40a (diff) | |
| download | platform_system_tools_sysprop-0dfe426db387e86f659dec16687dff4249d782b1.tar.gz platform_system_tools_sysprop-0dfe426db387e86f659dec16687dff4249d782b1.tar.bz2 platform_system_tools_sysprop-0dfe426db387e86f659dec16687dff4249d782b1.zip | |
Implement API dumper am: 5d3e6880b2 am: 5ec8f3a114 am: fd3b92fe0d am: 30d7d1bd65
am: f1474186b4
Change-Id: I5d669c630699c290a623553cdb1a5953aed6d097
| -rw-r--r-- | Android.bp | 6 | ||||
| -rw-r--r-- | ApiDumpMain.cpp | 75 |
2 files changed, 81 insertions, 0 deletions
@@ -43,6 +43,12 @@ cc_binary_host { srcs: ["ApiChecker.cpp", "ApiCheckerMain.cpp"], } +cc_binary_host { + name: "sysprop_api_dump", + defaults: ["sysprop-defaults"], + srcs: ["ApiDumpMain.cpp"], +} + cc_test_host { name: "sysprop_test", defaults: ["sysprop-defaults"], diff --git a/ApiDumpMain.cpp b/ApiDumpMain.cpp new file mode 100644 index 0000000..e607196 --- /dev/null +++ b/ApiDumpMain.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "sysprop_api_dump_main" + +#include <android-base/file.h> +#include <android-base/logging.h> +#include <google/protobuf/text_format.h> + +#include <algorithm> +#include <cstdio> +#include <cstdlib> +#include <map> +#include <string> + +#include "Common.h" + +namespace { + +[[noreturn]] void PrintUsage(const char* exe_name) { + std::printf("Usage: %s output_file sysprop_files...\n", exe_name); + std::exit(EXIT_FAILURE); +} + +} // namespace + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::fprintf(stderr, "%s needs at least 2 arguments\n", argv[0]); + PrintUsage(argv[0]); + } + + sysprop::SyspropLibraryApis api; + std::map<std::string, sysprop::Properties> modules; + + for (int i = 2; i < argc; ++i) { + if (auto res = ParseProps(argv[i]); res) { + if (!modules.emplace(res->module(), *res).second) { + LOG(FATAL) << "duplicated module name " << res->module(); + } + } else { + LOG(FATAL) << "parsing sysprop file " << argv[i] + << " failed: " << res.error(); + } + } + + for (auto& [name, props] : modules) { + // Sort properties to normalize + std::sort(props.mutable_prop()->begin(), props.mutable_prop()->end(), + [](auto& a, auto& b) { return a.api_name() < b.api_name(); }); + *api.add_props() = std::move(props); + } + + std::string res; + if (!google::protobuf::TextFormat::PrintToString(api, &res)) { + LOG(FATAL) << "dumping API failed"; + } + + if (!android::base::WriteStringToFile(res, argv[1])) { + PLOG(FATAL) << "writing API file to " << argv[1] << " failed"; + } +} |
