Skip to content

Commit

Permalink
Change verilog_kythe_extractor so it can be used for running Kythe ve…
Browse files Browse the repository at this point in the history
…rification tests directly from the bazel rules. This enables us to add the verification tests to the continuous integration.

Issues #395

PiperOrigin-RevId: 334405499
  • Loading branch information
Googler authored and hzeller committed Sep 29, 2020
1 parent a133eb9 commit 5c1a21e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions verilog/tools/kythe/build_defs/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2020 Google LLC.
# SPDX-License-Identifier: Apache-2.0

package(
default_visibility = [
"//verilog/tools/kythe:__subpackages__",
],
licenses = ["notice"],
)
2 changes: 2 additions & 0 deletions verilog/tools/kythe/testdata/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2020 Google LLC.
# SPDX-License-Identifier: Apache-2.0
13 changes: 13 additions & 0 deletions verilog/tools/kythe/verilog_kythe_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fstream>
#include <iostream>
#include <string>

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5c1a21e

Please sign in to comment.