From 5c1a21e3fb5f58ef1964bb51fff923e0eddb3508 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 29 Sep 2020 10:12:56 -0700 Subject: [PATCH] Change verilog_kythe_extractor so it can be used for running Kythe verification tests directly from the bazel rules. This enables us to add the verification tests to the continuous integration. Issues #395 PiperOrigin-RevId: 334405499 --- verilog/tools/kythe/build_defs/BUILD | 9 +++++++++ verilog/tools/kythe/testdata/BUILD | 2 ++ verilog/tools/kythe/verilog_kythe_extractor.cc | 13 +++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 verilog/tools/kythe/build_defs/BUILD create mode 100644 verilog/tools/kythe/testdata/BUILD diff --git a/verilog/tools/kythe/build_defs/BUILD b/verilog/tools/kythe/build_defs/BUILD new file mode 100644 index 000000000..a6b7fe307 --- /dev/null +++ b/verilog/tools/kythe/build_defs/BUILD @@ -0,0 +1,9 @@ +# Copyright 2020 Google LLC. +# SPDX-License-Identifier: Apache-2.0 + +package( + default_visibility = [ + "//verilog/tools/kythe:__subpackages__", + ], + licenses = ["notice"], +) diff --git a/verilog/tools/kythe/testdata/BUILD b/verilog/tools/kythe/testdata/BUILD new file mode 100644 index 000000000..5577d60be --- /dev/null +++ b/verilog/tools/kythe/testdata/BUILD @@ -0,0 +1,2 @@ +# Copyright 2020 Google LLC. +# SPDX-License-Identifier: Apache-2.0 diff --git a/verilog/tools/kythe/verilog_kythe_extractor.cc b/verilog/tools/kythe/verilog_kythe_extractor.cc index 2aefb09f8..34cebcd73 100644 --- a/verilog/tools/kythe/verilog_kythe_extractor.cc +++ b/verilog/tools/kythe/verilog_kythe_extractor.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -33,6 +34,9 @@ ABSL_FLAG(bool, printextraction, false, ABSL_FLAG(bool, printkythefacts, false, "Whether or not to print the extracted kythe facts"); +ABSL_FLAG(std::string, output_path, "", + "File path where to write the extracted Kythe facts in JSON format."); + static int ExtractOneFile(absl::string_view content, absl::string_view filename) { int exit_status = 0; @@ -60,6 +64,15 @@ static int ExtractOneFile(absl::string_view content, std::cout << verilog::kythe::KytheFactsPrinter(facts_tree) << std::endl; } + const std::string output_path = absl::GetFlag(FLAGS_output_path); + if (!output_path.empty()) { + std::ofstream f(output_path.c_str()); + if (!f.good()) { + LOG(FATAL) << "Can't write to " << output_path; + } + f << verilog::kythe::KytheFactsPrinter(facts_tree) << std::endl; + } + return exit_status; }