Skip to content

Commit 450780c

Browse files
committed
Move public headers and proto schema's from util/ to ift/config/.
This avoids having a public util:: namespace which is too generic.
1 parent 55e1e10 commit 450780c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+418
-428
lines changed

ift/config/BUILD

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
2+
load("@protobuf//bazel:proto_library.bzl", "proto_library")
3+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
4+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
5+
6+
proto_library(
7+
name = "segmentation_plan_proto",
8+
srcs = ["segmentation_plan.proto"],
9+
visibility = [
10+
"//visibility:public",
11+
],
12+
deps = [
13+
":common_proto",
14+
],
15+
)
16+
17+
cc_proto_library(
18+
name = "segmentation_plan_cc_proto",
19+
visibility = [
20+
"//visibility:public",
21+
],
22+
deps = [
23+
":segmentation_plan_proto",
24+
],
25+
)
26+
27+
proto_library(
28+
name = "common_proto",
29+
srcs = ["common.proto"],
30+
visibility = [
31+
"//visibility:public",
32+
],
33+
)
34+
35+
cc_proto_library(
36+
name = "common_cc_proto",
37+
visibility = ["//visibility:public"],
38+
deps = [":common_proto"],
39+
)
40+
41+
proto_library(
42+
name = "segmenter_config_proto",
43+
srcs = ["segmenter_config.proto"],
44+
visibility = [
45+
"//visibility:public",
46+
],
47+
deps = [
48+
":common_proto",
49+
":segmentation_plan_proto",
50+
],
51+
)
52+
53+
cc_proto_library(
54+
name = "segmenter_config_cc_proto",
55+
visibility = [
56+
"//visibility:public",
57+
],
58+
deps = [
59+
":segmenter_config_proto",
60+
],
61+
)
62+
63+
cc_library(
64+
name = "auto_segmenter_config",
65+
srcs = [
66+
"auto_segmenter_config.cc",
67+
],
68+
hdrs = [
69+
"auto_segmenter_config.h",
70+
],
71+
deps = [
72+
":load_codepoints",
73+
":segmenter_config_cc_proto",
74+
"//common",
75+
"@abseil-cpp//absl/container:flat_hash_set",
76+
"@harfbuzz",
77+
],
78+
visibility = [
79+
"//visibility:public",
80+
]
81+
)
82+
83+
cc_library(
84+
name = "load_codepoints",
85+
srcs = [
86+
"load_codepoints.cc",
87+
],
88+
hdrs = [
89+
"load_codepoints.h",
90+
],
91+
deps = [
92+
"//common",
93+
"//ift/freq",
94+
"@abseil-cpp//absl/status:statusor",
95+
"@abseil-cpp//absl/strings",
96+
"@harfbuzz",
97+
"@ift_encoder_data//:codepoint_count_cc_proto",
98+
"@ift_encoder_data//:metadata_cc_proto",
99+
"@riegeli//riegeli/bytes:fd_reader",
100+
"@riegeli//riegeli/records:record_reader",
101+
],
102+
visibility = [
103+
"//visibility:public",
104+
]
105+
)
106+
107+
cc_library(
108+
name = "segmenter_config_util",
109+
srcs = [
110+
"segmenter_config_util.cc",
111+
],
112+
hdrs = [
113+
"segmenter_config_util.h",
114+
],
115+
deps = [
116+
":load_codepoints",
117+
":segmentation_plan_cc_proto",
118+
":segmenter_config_cc_proto",
119+
"//common",
120+
"//ift/encoder",
121+
"@abseil-cpp//absl/status:statusor",
122+
"@harfbuzz",
123+
],
124+
visibility = [
125+
"//visibility:public",
126+
]
127+
)
128+
129+
cc_test(
130+
name = "auto_segmenter_config_test",
131+
size = "small",
132+
srcs = [
133+
"auto_segmenter_config_test.cc",
134+
],
135+
data = [
136+
"//common:testdata",
137+
"@ift_encoder_data//:freq_data",
138+
],
139+
deps = [
140+
":auto_segmenter_config",
141+
"//common",
142+
"@googletest//:gtest_main",
143+
"@harfbuzz",
144+
],
145+
)
146+
147+
cc_test(
148+
name = "load_codepoints_test",
149+
size = "small",
150+
srcs = [
151+
"load_codepoints_test.cc",
152+
],
153+
data = [
154+
"//util:testdata",
155+
"@ift_encoder_data//:freq_data",
156+
],
157+
deps = [
158+
":load_codepoints",
159+
"@googletest//:gtest_main",
160+
],
161+
)
162+
163+
cc_test(
164+
name = "segmenter_config_util_test",
165+
size = "small",
166+
srcs = [
167+
"segmenter_config_util_test.cc",
168+
],
169+
data = [
170+
"//util:testdata",
171+
],
172+
deps = [
173+
":segmenter_config_util",
174+
"@googletest//:gtest_main",
175+
],
176+
)
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "util/auto_segmenter_config.h"
1+
#include "ift/config/auto_segmenter_config.h"
22

33
#include <cctype>
44
#include <string>
@@ -11,16 +11,8 @@
1111
#include "common/int_set.h"
1212
#include "common/try.h"
1313
#include "hb.h"
14-
#include "util/load_codepoints.h"
15-
#include "util/segmenter_config.pb.h"
16-
17-
using ift::proto::CLOSURE_AND_DEP_GRAPH;
18-
using ift::proto::CostConfiguration;
19-
using ift::proto::FIND_CONDITIONS;
20-
using ift::proto::HeuristicConfiguration;
21-
using ift::proto::MergeGroup;
22-
using ift::proto::MOVE_TO_INIT_FONT;
23-
using ift::proto::SegmenterConfig;
14+
#include "ift/config/load_codepoints.h"
15+
#include "ift/config/segmenter_config.pb.h"
2416

2517
using absl::btree_set;
2618
using absl::flat_hash_map;
@@ -30,7 +22,7 @@ using absl::StatusOr;
3022
using common::CodepointSet;
3123
using common::FontHelper;
3224

33-
namespace util {
25+
namespace ift::config {
3426

3527
static constexpr uint32_t kMinimumGroupSize = 4;
3628

@@ -733,4 +725,4 @@ StatusOr<SegmenterConfig> AutoSegmenterConfig::GenerateConfig(
733725
return config;
734726
}
735727

736-
} // namespace util
728+
} // namespace ift::config
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#ifndef UTIL_AUTO_SEGMENTER_CONFIG_H_
2-
#define UTIL_AUTO_SEGMENTER_CONFIG_H_
1+
#ifndef IFT_CONFIG_AUTO_SEGMENTER_CONFIG_H_
2+
#define IFT_CONFIG_AUTO_SEGMENTER_CONFIG_H_
33

44
#include <optional>
55
#include <string>
66

77
#include "absl/status/statusor.h"
88
#include "absl/strings/string_view.h"
99
#include "hb.h"
10-
#include "util/segmenter_config.pb.h"
10+
#include "ift/config/segmenter_config.pb.h"
1111

12-
namespace util {
12+
namespace ift::config {
1313

1414
class AutoSegmenterConfig {
1515
public:
@@ -24,7 +24,7 @@ class AutoSegmenterConfig {
2424
// quality tradeoff. Lower values have shorter segmenting
2525
// times, high values have longer segmenting times but
2626
// typically results in better segmentation quality.
27-
static absl::StatusOr<ift::proto::SegmenterConfig> GenerateConfig(
27+
static absl::StatusOr<SegmenterConfig> GenerateConfig(
2828
hb_face_t* face, std::optional<std::string> primary_script = std::nullopt,
2929
std::optional<int> quality_level = std::nullopt);
3030

@@ -37,6 +37,6 @@ class AutoSegmenterConfig {
3737
AutoSegmenterConfig() = delete;
3838
};
3939

40-
} // namespace util
40+
} // namespace ift::config
4141

42-
#endif // UTIL_AUTO_SEGMENTER_CONFIG_H_
42+
#endif // IFT_CONFIG_AUTO_SEGMENTER_CONFIG_H_
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "util/auto_segmenter_config.h"
1+
#include "ift/config/auto_segmenter_config.h"
22

33
#include <google/protobuf/text_format.h>
44

@@ -11,14 +11,14 @@
1111
#include "gmock/gmock.h"
1212
#include "gtest/gtest.h"
1313
#include "hb.h"
14-
#include "util/load_codepoints.h"
14+
#include "ift/config/load_codepoints.h"
1515

16-
using ift::proto::CLOSURE_AND_DEP_GRAPH;
17-
using ift::proto::FIND_CONDITIONS;
18-
using ift::proto::MOVE_TO_INIT_FONT;
19-
using ift::proto::SegmenterConfig;
16+
using ift::config::CLOSURE_AND_DEP_GRAPH;
17+
using ift::config::FIND_CONDITIONS;
18+
using ift::config::MOVE_TO_INIT_FONT;
19+
using ift::config::SegmenterConfig;
2020

21-
namespace util {
21+
namespace ift::config {
2222
namespace {
2323

2424
using ::common::hb_blob_unique_ptr;
@@ -263,7 +263,7 @@ TEST_F(AutoSegmenterConfigTest, Roboto_FullFileName_Language) {
263263
}
264264

265265
TEST_F(AutoSegmenterConfigTest, LanguageMappingsExist) {
266-
auto built_in_freqs_or = util::BuiltInFrequenciesList();
266+
auto built_in_freqs_or = ift::config::BuiltInFrequenciesList();
267267
ASSERT_TRUE(built_in_freqs_or.ok());
268268
for (const auto& [file_name, _] : *built_in_freqs_or) {
269269
if (!absl::StartsWith(file_name, "Language_")) continue;
@@ -298,4 +298,4 @@ TEST_F(AutoSegmenterConfigTest, QualityLevelForcing) {
298298
}
299299

300300
} // namespace
301-
} // namespace util
301+
} // namespace ift::config
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
edition = "2023";
22

3-
package ift.proto;
3+
package ift.config;
44

55
// A list of unicode code points.
66
message Codepoints {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using ift::freq::UnicodeFrequencies;
3232
using ift_encoder_data::CodepointCount;
3333
using ift_encoder_data::DatasetMetadata;
3434

35-
namespace util {
35+
namespace ift::config {
3636

3737
StatusOr<common::FontData> LoadFile(const char* path) {
3838
hb_blob_unique_ptr blob =
@@ -240,4 +240,4 @@ BuiltInFrequenciesList() {
240240
return result;
241241
}
242242

243-
} // namespace util
243+
} // namespace ift::config
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef UTIL_LOAD_CODEPOINTS_H_
2-
#define UTIL_LOAD_CODEPOINTS_H_
1+
#ifndef IFT_CONFIG_LOAD_CODEPOINTS_H_
2+
#define IFT_CONFIG_LOAD_CODEPOINTS_H_
33

44
#include <optional>
55
#include <vector>
@@ -12,7 +12,7 @@
1212
#include "common/int_set.h"
1313
#include "ift/freq/unicode_frequencies.h"
1414

15-
namespace util {
15+
namespace ift::config {
1616

1717
template <typename T>
1818
common::IntSet Values(const T& proto_set) {
@@ -98,6 +98,6 @@ struct CodepointAndFrequency {
9898
absl::StatusOr<std::vector<CodepointAndFrequency>> LoadCodepointsOrdered(
9999
const char* path);
100100

101-
} // namespace util
101+
} // namespace ift::config
102102

103-
#endif // UTIL_LOAD_CODEPOINTS_H_
103+
#endif // IFT_CONFIG_LOAD_CODEPOINTS_H_

0 commit comments

Comments
 (0)