From bc69c3266ff56d43f30cc55fdd5cf74324e0584d Mon Sep 17 00:00:00 2001 From: Logan Chien Date: Thu, 14 Mar 2019 16:51:48 +0800 Subject: [PATCH] header-checker: Do not expose format-specific details Test: ./tests/test.py Test: ${ANDROID_HOST_OUT}/nativetest64/\ header-checker-unittests/header-checker-unittests Change-Id: Ib55dc8bdd195d4072d875d0cbd495c7c9c550fec --- .../src/repr/ir_diff_dumper.cpp | 4 +- .../header-checker/src/repr/ir_dumper.cpp | 8 ++-- .../header-checker/src/repr/ir_reader.cpp | 9 ++-- vndk/tools/header-checker/src/repr/json/api.h | 41 +++++++++++++++++ .../src/repr/json/ir_dumper.cpp | 5 +++ .../src/repr/json/ir_reader.cpp | 6 +++ .../header-checker/src/repr/protobuf/api.h | 45 +++++++++++++++++++ .../src/repr/protobuf/ir_diff_dumper.cpp | 9 +++- .../src/repr/protobuf/ir_dumper.cpp | 6 +++ .../src/repr/protobuf/ir_reader.cpp | 7 +++ 10 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 vndk/tools/header-checker/src/repr/json/api.h create mode 100644 vndk/tools/header-checker/src/repr/protobuf/api.h diff --git a/vndk/tools/header-checker/src/repr/ir_diff_dumper.cpp b/vndk/tools/header-checker/src/repr/ir_diff_dumper.cpp index 0a40a312b..d0b0eab9a 100644 --- a/vndk/tools/header-checker/src/repr/ir_diff_dumper.cpp +++ b/vndk/tools/header-checker/src/repr/ir_diff_dumper.cpp @@ -15,7 +15,7 @@ #include "repr/ir_diff_dumper.h" #include "repr/ir_representation.h" -#include "repr/protobuf/ir_diff_dumper.h" +#include "repr/protobuf/api.h" #include #include @@ -31,7 +31,7 @@ std::unique_ptr IRDiffDumper::CreateIRDiffDumper( TextFormatIR text_format, const std::string &dump_path) { switch (text_format) { case TextFormatIR::ProtobufTextFormat: - return std::make_unique(dump_path); + return CreateProtobufIRDiffDumper(dump_path); default: // Nothing else is supported yet. llvm::errs() << "Text format not supported yet\n"; diff --git a/vndk/tools/header-checker/src/repr/ir_dumper.cpp b/vndk/tools/header-checker/src/repr/ir_dumper.cpp index 3466a8540..048359d85 100644 --- a/vndk/tools/header-checker/src/repr/ir_dumper.cpp +++ b/vndk/tools/header-checker/src/repr/ir_dumper.cpp @@ -14,8 +14,8 @@ #include "repr/ir_dumper.h" -#include "repr/json/ir_dumper.h" -#include "repr/protobuf/ir_dumper.h" +#include "repr/json/api.h" +#include "repr/protobuf/api.h" #include #include @@ -31,9 +31,9 @@ std::unique_ptr IRDumper::CreateIRDumper( TextFormatIR text_format, const std::string &dump_path) { switch (text_format) { case TextFormatIR::ProtobufTextFormat: - return std::make_unique(dump_path); + return CreateProtobufIRDumper(dump_path); case TextFormatIR::Json: - return std::make_unique(dump_path); + return CreateJsonIRDumper(dump_path); default: llvm::errs() << "Text format not supported yet\n"; return nullptr; diff --git a/vndk/tools/header-checker/src/repr/ir_reader.cpp b/vndk/tools/header-checker/src/repr/ir_reader.cpp index 22594423a..ed4151a17 100644 --- a/vndk/tools/header-checker/src/repr/ir_reader.cpp +++ b/vndk/tools/header-checker/src/repr/ir_reader.cpp @@ -17,9 +17,8 @@ #include "repr/abi_diff_helpers.h" #include "repr/ir_representation.h" #include "repr/ir_representation_internal.h" -#include "repr/ir_diff_representation.h" -#include "repr/json/ir_reader.h" -#include "repr/protobuf/ir_reader.h" +#include "repr/json/api.h" +#include "repr/protobuf/api.h" #include #include @@ -41,9 +40,9 @@ IRReader::CreateIRReader( TextFormatIR text_format, const std::set *exported_headers) { switch (text_format) { case TextFormatIR::ProtobufTextFormat: - return std::make_unique(exported_headers); + return CreateProtobufIRReader(exported_headers); case TextFormatIR::Json: - return std::make_unique(exported_headers); + return CreateJsonIRReader(exported_headers); default: llvm::errs() << "Text format not supported yet\n"; return nullptr; diff --git a/vndk/tools/header-checker/src/repr/json/api.h b/vndk/tools/header-checker/src/repr/json/api.h new file mode 100644 index 000000000..95c1c37c1 --- /dev/null +++ b/vndk/tools/header-checker/src/repr/json/api.h @@ -0,0 +1,41 @@ +// 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. + +#ifndef HEADER_CHECKER_REPR_JSON_API_H_ +#define HEADER_CHECKER_REPR_JSON_API_H_ + +#include +#include +#include + + +namespace header_checker { +namespace repr { + + +class IRDumper; +class IRReader; + + +std::unique_ptr CreateJsonIRDumper(const std::string &dump_path); + +std::unique_ptr CreateJsonIRReader( + const std::set *exported_headers); + + +} // namespace repr +} // namespace header_checker + + +#endif // HEADER_CHECKER_REPR_JSON_API_H_ diff --git a/vndk/tools/header-checker/src/repr/json/ir_dumper.cpp b/vndk/tools/header-checker/src/repr/json/ir_dumper.cpp index 8c4a7fc23..f9c56ec46 100644 --- a/vndk/tools/header-checker/src/repr/json/ir_dumper.cpp +++ b/vndk/tools/header-checker/src/repr/json/ir_dumper.cpp @@ -17,6 +17,7 @@ #include "repr/ir_dumper.h" #include "repr/ir_reader.h" #include "repr/ir_representation_internal.h" +#include "repr/json/api.h" #include "repr/json/converter.h" #include @@ -426,6 +427,10 @@ JsonIRDumper::JsonIRDumper(const std::string &dump_path) } } +std::unique_ptr CreateJsonIRDumper(const std::string &dump_path) { + return std::make_unique(dump_path); +} + } // namespace repr } // header_checker diff --git a/vndk/tools/header-checker/src/repr/json/ir_reader.cpp b/vndk/tools/header-checker/src/repr/json/ir_reader.cpp index bd79eb977..3c90bc193 100644 --- a/vndk/tools/header-checker/src/repr/json/ir_reader.cpp +++ b/vndk/tools/header-checker/src/repr/json/ir_reader.cpp @@ -17,6 +17,7 @@ #include "repr/ir_dumper.h" #include "repr/ir_reader.h" #include "repr/ir_representation_internal.h" +#include "repr/json/api.h" #include "repr/json/converter.h" #include @@ -478,6 +479,11 @@ void JsonIRReader::ReadElfObjects(const JsonObjectRef &tu) { } } +std::unique_ptr CreateJsonIRReader( + const std::set *exported_headers) { + return std::make_unique(exported_headers); +} + } // namespace repr } // header_checker diff --git a/vndk/tools/header-checker/src/repr/protobuf/api.h b/vndk/tools/header-checker/src/repr/protobuf/api.h new file mode 100644 index 000000000..22a03ee50 --- /dev/null +++ b/vndk/tools/header-checker/src/repr/protobuf/api.h @@ -0,0 +1,45 @@ +// 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. + +#ifndef HEADER_CHECKER_REPR_PROTOBUF_API_H_ +#define HEADER_CHECKER_REPR_PROTOBUF_API_H_ + +#include +#include +#include + + +namespace header_checker { +namespace repr { + + +class IRDiffDumper; +class IRDumper; +class IRReader; + + +std::unique_ptr CreateProtobufIRDumper(const std::string &dump_path); + +std::unique_ptr CreateProtobufIRReader( + const std::set *exported_headers); + +std::unique_ptr CreateProtobufIRDiffDumper( + const std::string &dump_path); + + +} // namespace repr +} // namespace header_checker + + +#endif // HEADER_CHECKER_REPR_PROTOBUF_API_H_ diff --git a/vndk/tools/header-checker/src/repr/protobuf/ir_diff_dumper.cpp b/vndk/tools/header-checker/src/repr/protobuf/ir_diff_dumper.cpp index 4c4106ae5..12d7dedea 100644 --- a/vndk/tools/header-checker/src/repr/protobuf/ir_diff_dumper.cpp +++ b/vndk/tools/header-checker/src/repr/protobuf/ir_diff_dumper.cpp @@ -15,10 +15,12 @@ #include "repr/protobuf/ir_diff_dumper.h" #include "repr/ir_diff_representation.h" +#include "repr/protobuf/api.h" #include "repr/protobuf/converter.h" -#include #include +#include +#include #include @@ -366,6 +368,11 @@ bool ProtobufIRDiffDumper::Dump() { return google::protobuf::TextFormat::Print(*diff_tu_.get(), &text_os); } +std::unique_ptr CreateProtobufIRDiffDumper( + const std::string &dump_path) { + return std::make_unique(dump_path); +} + } // namespace repr } // namespace header_checker diff --git a/vndk/tools/header-checker/src/repr/protobuf/ir_dumper.cpp b/vndk/tools/header-checker/src/repr/protobuf/ir_dumper.cpp index 5c7931f93..d4a0594cb 100644 --- a/vndk/tools/header-checker/src/repr/protobuf/ir_dumper.cpp +++ b/vndk/tools/header-checker/src/repr/protobuf/ir_dumper.cpp @@ -15,8 +15,10 @@ #include "repr/protobuf/ir_dumper.h" #include "repr/protobuf/abi_dump.h" +#include "repr/protobuf/api.h" #include +#include #include @@ -489,6 +491,10 @@ bool ProtobufIRDumper::Dump() { return google::protobuf::TextFormat::Print(*tu_ptr_.get(), &text_os); } +std::unique_ptr CreateProtobufIRDumper(const std::string &dump_path) { + return std::make_unique(dump_path); +} + } // namespace repr } // namespace header_checker diff --git a/vndk/tools/header-checker/src/repr/protobuf/ir_reader.cpp b/vndk/tools/header-checker/src/repr/protobuf/ir_reader.cpp index f29dc8b60..1f92c9618 100644 --- a/vndk/tools/header-checker/src/repr/protobuf/ir_reader.cpp +++ b/vndk/tools/header-checker/src/repr/protobuf/ir_reader.cpp @@ -15,9 +15,11 @@ #include "repr/protobuf/ir_reader.h" #include "repr/ir_representation_internal.h" +#include "repr/protobuf/api.h" #include "repr/protobuf/converter.h" #include +#include #include @@ -369,6 +371,11 @@ void ProtobufIRReader::ReadElfObjects(const abi_dump::TranslationUnit &tu) { } } +std::unique_ptr CreateProtobufIRReader( + const std::set *exported_headers) { + return std::make_unique(exported_headers); +} + } // namespace repr } // namespace header_checker