Skip to content

Commit

Permalink
Make use of SetTextProtoFile() when writing textproto.
Browse files Browse the repository at this point in the history
Less code, and automatically get the added benefit that the
type is written to the proto file for easier human- and tool
readability.

PiperOrigin-RevId: 683377205
  • Loading branch information
hzeller authored and copybara-github committed Oct 7, 2024
1 parent f9f929b commit 74a99d8
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 11 deletions.
2 changes: 1 addition & 1 deletion xls/fuzzer/run_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ absl::Status RunSample(const Sample& smp, const std::filesystem::path& run_dir,

std::filesystem::path options_file_name = run_dir / "options.pbtxt";
XLS_RETURN_IF_ERROR(
SetFileContents(options_file_name, smp.options().ToPbtxt()));
SetTextProtoFile(options_file_name, smp.options().proto()));
argv.push_back("--options_file=options.pbtxt");

std::filesystem::path args_file_name = run_dir / "args.txt";
Expand Down
6 changes: 0 additions & 6 deletions xls/fuzzer/sample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ std::vector<std::string> ParseIrChannelNames(
return FromProto(proto);
}

std::string SampleOptions::ToPbtxt() const {
std::string pbtxt;
CHECK(google::protobuf::TextFormat::PrintToString(proto_, &pbtxt));
return pbtxt;
}

/* static */ absl::StatusOr<SampleOptions> SampleOptions::FromProto(
fuzzer::SampleOptionsProto proto) {
SampleOptions options;
Expand Down
2 changes: 0 additions & 2 deletions xls/fuzzer/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class SampleOptions {

// Convert to/from text serialized SampleOptionsProto.
static absl::StatusOr<SampleOptions> FromPbtxt(std::string_view text);
std::string ToPbtxt() const;

static absl::StatusOr<SampleOptions> FromProto(
fuzzer::SampleOptionsProto proto);

Expand Down
3 changes: 1 addition & 2 deletions xls/fuzzer/sample_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,7 @@ absl::Status SampleRunner::Run(const Sample& sample) {
XLS_RETURN_IF_ERROR(SetFileContents(input_path, sample.input_text()));

std::filesystem::path options_path = run_dir_ / "options.pbtxt";
XLS_RETURN_IF_ERROR(
SetFileContents(options_path, sample.options().ToPbtxt()));
XLS_RETURN_IF_ERROR(SetTextProtoFile(options_path, sample.options().proto()));

std::filesystem::path args_path = run_dir_ / "args.txt";
XLS_RETURN_IF_ERROR(
Expand Down

0 comments on commit 74a99d8

Please sign in to comment.