Skip to content

Commit 03a77a0

Browse files
committed
Remove ortools dependency from PPL lib
1 parent 1f9e75b commit 03a77a0

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

WORKSPACE

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ http_archive(
4949
# remote = "https://github.com/grpc-ecosystem/grpc-httpjson-transcoding.git",
5050
)
5151

52-
http_archive(
53-
name = "com_google_ortools",
54-
sha256 = "054d9517fc6c83f15150c93ef1c2c674ffd7d4a0d1fdc78f6ef8bc3e25c2e339",
55-
strip_prefix = "or-tools-9.7",
56-
url = "https://github.com/google/or-tools/archive/refs/tags/v9.7.tar.gz",
57-
)
58-
5952
http_archive(
6053
name = "com_google_proto_field_extraction",
6154
strip_prefix = "proto-field-extraction-e808da3acf5bd6d518e19e8afa20b4a9d0b2b599", # Mar 20, 2024

proto_processing_lib/proto_scrubber/BUILD.bazel

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Copyright 2023 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,17 +80,14 @@ cc_library(
8180
deps = [
8281
":constants",
8382
":utility",
84-
"@com_google_protobuf//:cc_wkt_protos",
85-
"@com_google_protoconverter//:all",
8683
"@com_google_absl//absl/container:flat_hash_map",
8784
"@com_google_absl//absl/flags:flag",
8885
"@com_google_absl//absl/log",
8986
"@com_google_absl//absl/status",
9087
"@com_google_absl//absl/strings",
88+
"@com_google_protobuf//:cc_wkt_protos",
89+
"@com_google_protoconverter//:all",
9190
"@ocp//ocpdiag/core/compat:status_macros",
92-
# Use OR-Tools map_util and container_loggings from gtl.
93-
# Warning: May not support all functionalities.
94-
"@com_google_ortools//ortools/base:map_util",
9591
],
9692
)
9793

@@ -174,15 +170,12 @@ cc_library(
174170
deps = [
175171
":field_checker_interface",
176172
":field_mask_node",
177-
"@com_google_protobuf//:cc_wkt_protos",
178173
"//proto_processing_lib:factory_helper",
179174
"//proto_processing_lib:interface_util",
180175
"@com_google_absl//absl/container:flat_hash_map",
181176
"@com_google_absl//absl/log",
182177
"@com_google_absl//absl/status",
183-
# Use OR-Tools map_util and container_loggings from gtl.
184-
# Warning: May not support all functionalities.
185-
"@com_google_ortools//ortools/base:map_util",
178+
"@com_google_protobuf//:cc_wkt_protos",
186179
],
187180
)
188181

@@ -426,4 +419,3 @@ cc_test(
426419
"@ocp//ocpdiag/core/testing:status_matchers",
427420
],
428421
)
429-

proto_processing_lib/proto_scrubber/cloud_audit_log_field_checker.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@
2525
#include "proto_processing_lib/factory_helper.h"
2626
#include "proto_processing_lib/proto_scrubber/field_checker_interface.h"
2727
#include "proto_processing_lib/proto_scrubber/field_mask_node.h"
28-
#include "ortools/base/map_util.h"
2928

3029
namespace proto_processing_lib::proto_scrubber {
3130
namespace {
3231

3332
// Returns pointer to message type name, or nullptr if field isn't a message or
3433
// has an unknown type. Caller does not own returned pointer.
3534
const std::string* GetMessageTypeName(const FieldMaskNode* node);
35+
36+
const FieldMaskNode* FindPtrOrNull(
37+
absl::flat_hash_map<std::string, const FieldMaskNode*> type_to_node,
38+
const std::string& type_name) {
39+
const auto& it = type_to_node.find(type_name);
40+
if (it == type_to_node.end()) {
41+
return nullptr;
42+
}
43+
return it->second;
44+
}
3645
} // namespace
3746

3847
CloudAuditLogFieldChecker::CloudAuditLogFieldChecker(
@@ -69,8 +78,7 @@ FieldCheckResults CloudAuditLogFieldChecker::CheckField(
6978
const std::string* type_name = GetMessageTypeName(current_node);
7079

7180
if (type_name != nullptr) {
72-
const FieldMaskNode* found_node =
73-
gtl::FindPtrOrNull(type_to_node, *type_name);
81+
const FieldMaskNode* found_node = FindPtrOrNull(type_to_node, *type_name);
7482
if (found_node == nullptr) {
7583
// Keep track of this message type in case it's cyclic.
7684
type_to_node.emplace(*type_name, current_node);

proto_processing_lib/proto_scrubber/field_mask_node.cc

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,38 @@
3131
#include "src/google/protobuf/util/converter/utility.h"
3232
#include "proto_processing_lib/proto_scrubber/constants.h"
3333
#include "proto_processing_lib/proto_scrubber/utility.h"
34-
#include "ortools/base/map_util.h"
3534
#include "ocpdiag/core/compat/status_macros.h"
3635

3736
namespace proto_processing_lib::proto_scrubber {
3837

38+
39+
namespace {
40+
3941
using google::protobuf::util::converter::ToSnakeCase;
4042

43+
void InsertIfNotPresent(
44+
absl::flat_hash_map<absl::string_view, const google::protobuf::Field*>&
45+
child_name_child_map,
46+
absl::string_view field_name, const google::protobuf::Field* field) {
47+
if (!child_name_child_map.contains(field_name)) {
48+
child_name_child_map.emplace(field_name, field);
49+
}
50+
}
51+
52+
const google::protobuf::Field* FindWithDefault(
53+
absl::flat_hash_map<absl::string_view, const google::protobuf::Field*>&
54+
child_name_child_map,
55+
absl::string_view field_name) {
56+
const auto& it = child_name_child_map.find(field_name);
57+
if (it == child_name_child_map.end()) {
58+
google::protobuf::Field* field = nullptr;
59+
return field;
60+
}
61+
return it->second;
62+
}
63+
64+
} // namespace
65+
4166
FieldMaskNode::FieldMaskNode(
4267
const google::protobuf::Type* type, bool is_leaf, bool is_map,
4368
bool all_keys_included,
@@ -81,24 +106,23 @@ const google::protobuf::Field* FieldMaskNode::FindChildField(
81106
// method is called).
82107
if (child_name_child_map_.empty()) {
83108
for (const google::protobuf::Field& field : type_->fields()) {
84-
gtl::InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
109+
InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
85110
}
86111
if (type_->name() == kStructType || type_->name() == kStructValueType ||
87112
type_->name() == kStructListValueType) {
88113
// Add Struct type fields and List type fields for nested searching.
89114
// A Struct value can be List. A List value can be Struct.
90115
for (const google::protobuf::Field& field :
91116
type_finder_(kStructTypeUrl)->fields()) {
92-
gtl::InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
117+
InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
93118
}
94119
for (const google::protobuf::Field& field :
95120
type_finder_(kStructListValueTypeUrl)->fields()) {
96-
gtl::InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
121+
InsertIfNotPresent(&child_name_child_map_, field.name(), &field);
97122
}
98123
}
99-
100124
}
101-
return gtl::FindWithDefault(child_name_child_map_, field_name);
125+
return FindWithDefault(child_name_child_map_, field_name);
102126
}
103127

104128
absl::Status FieldMaskNode::ParseFieldNameAndMapKey(const std::string& segment,

0 commit comments

Comments
 (0)