Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c2337e

Browse files
authored
[Serialization] JSON Serialization for Target (#225)
1 parent1fded03 commit2c2337e

File tree

15 files changed

+432
-478
lines changed

15 files changed

+432
-478
lines changed

‎bootstrap/include/bootstrap/build_buildcc.h‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030

3131
namespacebuildcc {
3232

33-
voidschema_gen_cb(FileGenerator &generator,const BaseTarget &flatc_exe);
34-
35-
voidbuildcc_cb(BaseTarget &target,const FileGenerator &schema_gen,
36-
const TargetInfo &flatbuffers_ho,
33+
voidbuildcc_cb(BaseTarget &target,const TargetInfo &flatbuffers_ho,
3734
const TargetInfo &nlohmann_json_ho,const TargetInfo &fmt_ho,
3835
const TargetInfo &spdlog_ho,const TargetInfo &cli11_ho,
3936
const TargetInfo &taskflow_ho,const TargetInfo &tl_optional_ho,
@@ -57,9 +54,6 @@ class BuildBuildCC {
5754
// Executable
5855
staticconstexprconstchar *constkFlatcExeName ="flatc";
5956

60-
// Generator
61-
staticconstexprconstchar *constkSchemaGenName ="schema_gen";
62-
6357
// Libraries
6458
staticconstexprconstchar *constkTplLibName ="libtpl";
6559
staticconstexprconstchar *constkBuildccLibName ="libbuildcc";
@@ -86,9 +80,6 @@ class BuildBuildCC {
8680
ExecutableTarget_generic &GetFlatc() {
8781
return storage_.Ref<ExecutableTarget_generic>(kFlatcExeName);
8882
}
89-
FileGenerator &GetSchemaGen() {
90-
return storage_.Ref<FileGenerator>(kSchemaGenName);
91-
}
9283
TargetInfo &GetFlatbuffersHo() {
9384
return storage_.Ref<TargetInfo>(kFlatbuffersHoName);
9485
}

‎bootstrap/src/build_buildcc.cpp‎

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,13 @@
1818

1919
namespacebuildcc {
2020

21-
voidschema_gen_cb(FileGenerator &generator,const BaseTarget &flatc_exe) {
22-
generator.AddPattern("path_fbs","{current_root_dir}/path.fbs");
23-
generator.AddPattern("target_fbs","{current_root_dir}/target.fbs");
24-
25-
generator.AddInput("{path_fbs}");
26-
generator.AddInput("{target_fbs}");
27-
28-
generator.AddOutput("{current_build_dir}/path_generated.h");
29-
generator.AddOutput("{current_build_dir}/target_generated.h");
30-
31-
generator.AddPatterns({
32-
{"flatc_compiler",fmt::format("{}", flatc_exe.GetTargetPath())},
33-
});
34-
// generator.AddCommand("{flatc_compiler} --help");
35-
generator.AddCommand("{flatc_compiler} -o {current_build_dir} -I"
36-
"{current_root_dir} --gen-object-api"
37-
"--cpp {path_fbs} {target_fbs}");
38-
39-
generator.Build();
40-
}
41-
42-
voidbuildcc_cb(BaseTarget &target,const FileGenerator &schema_gen,
43-
const TargetInfo &flatbuffers_ho,
21+
voidbuildcc_cb(BaseTarget &target,const TargetInfo &flatbuffers_ho,
4422
const TargetInfo &nlohmann_json_ho,const TargetInfo &fmt_ho,
4523
const TargetInfo &spdlog_ho,const TargetInfo &cli11_ho,
4624
const TargetInfo &taskflow_ho,const TargetInfo &tl_optional_ho,
4725
const BaseTarget &tpl) {
4826
// NOTE, Build as single lib
4927
target.AddIncludeDir("",true);
50-
const std::string &schema_build_dir = schema_gen.Get("current_build_dir");
51-
target.AddIncludeDirAbsolute(schema_build_dir,true);
5228

5329
// ENV
5430
target.GlobSources("lib/env/src");
@@ -60,7 +36,6 @@ void buildcc_cb(BaseTarget &target, const FileGenerator &schema_gen,
6036
target.AddIncludeDir("schema/include");
6137
target.GlobHeaders("schema/include/schema");
6238
target.GlobHeaders("schema/include/schema/interface");
63-
target.GlobHeaders("schema/include/schema/private");
6439

6540
// TOOLCHAIN
6641
target.GlobSources("lib/toolchain/src/api");
@@ -205,12 +180,6 @@ void BuildBuildCC::Initialize() {
205180
TargetEnv(env_.GetTargetRootDir() /"third_party" /"flatbuffers",
206181
env_.GetTargetBuildDir()));
207182

208-
// Schema
209-
(void)storage_.Add<FileGenerator>(
210-
kSchemaGenName,kSchemaGenName,
211-
TargetEnv(env_.GetTargetRootDir() /"buildcc" /"schema",
212-
env_.GetTargetBuildDir() / toolchain_.GetName()));
213-
214183
// Flatbuffers HO lib
215184
(void)storage_.Add<TargetInfo>(
216185
kFlatbuffersHoName, toolchain_,
@@ -271,8 +240,6 @@ void BuildBuildCC::Initialize() {
271240
}
272241

273242
voidBuildBuildCC::Setup(const ArgToolchainState &state) {
274-
auto &flatc_exe =GetFlatc();
275-
auto &schema_gen =GetSchemaGen();
276243
auto &flatbuffers_ho_lib =GetFlatbuffersHo();
277244
auto &nlohmann_json_ho_lib =GetNlohmannJsonHo();
278245
auto &cli11_ho_lib =GetCli11Ho();
@@ -283,10 +250,6 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
283250
auto &tpl_lib =GetTpl();
284251
auto &buildcc_lib =GetBuildcc();
285252
Reg::Toolchain(state)
286-
.Func(global_flags_cb, flatc_exe, toolchain_)
287-
.Build(build_flatc_exe_cb, flatc_exe)
288-
.Build(schema_gen_cb, schema_gen, flatc_exe)
289-
.Dep(schema_gen, flatc_exe)
290253
.Func(flatbuffers_ho_cb, flatbuffers_ho_lib)
291254
.Func(nlohmann_json_ho_cb, nlohmann_json_ho_lib)
292255
.Func(cli11_ho_cb, cli11_ho_lib)
@@ -297,10 +260,9 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
297260
.Func(global_flags_cb, tpl_lib, toolchain_)
298261
.Build(tpl_cb, tpl_lib)
299262
.Func(global_flags_cb, buildcc_lib, toolchain_)
300-
.Build(buildcc_cb, buildcc_lib, schema_gen, flatbuffers_ho_lib,
301-
nlohmann_json_ho_lib, fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib,
302-
taskflow_ho_lib, tl_optional_ho_lib, tpl_lib)
303-
.Dep(buildcc_lib, schema_gen)
263+
.Build(buildcc_cb, buildcc_lib, flatbuffers_ho_lib, nlohmann_json_ho_lib,
264+
fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib,
265+
tl_optional_ho_lib, tpl_lib)
304266
.Dep(buildcc_lib, tpl_lib);
305267
}
306268

‎buildcc/schema/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
include(cmake/schema_generate.cmake)
21
include(cmake/schema.cmake)

‎buildcc/schema/cmake/schema.cmake‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# schema test
22
if (${TESTING})
33
add_library(mock_schemaSTATIC
4-
include/schema/private/schema_util.h
54
include/schema/interface/serialization_interface.h
65

76
include/schema/path.h
@@ -11,6 +10,7 @@ if (${TESTING})
1110
include/schema/custom_generator_serialization.h
1211

1312
src/target_serialization.cpp
13+
include/schema/target_schema.h
1414
include/schema/target_serialization.h
1515
)
1616
target_include_directories(mock_schemaPUBLIC
@@ -27,7 +27,6 @@ if (${TESTING})
2727
CppUTestExt
2828
${TEST_LINK_LIBS}
2929
)
30-
add_dependencies(mock_schema fbs_to_header)
3130

3231
target_compile_options(mock_schemaPUBLIC${TEST_COMPILE_FLAGS}${BUILD_COMPILE_FLAGS})
3332
target_link_options(mock_schemaPUBLIC${TEST_LINK_FLAGS}${BUILD_LINK_FLAGS})
@@ -38,21 +37,30 @@ if (${TESTING})
3837
)
3938
target_link_libraries(test_custom_generator_serializationPRIVATE mock_schema)
4039

40+
add_executable(test_target_serialization
41+
test/test_target_serialization.cpp
42+
)
43+
target_link_libraries(test_target_serializationPRIVATE mock_schema)
44+
4145
add_test(NAME test_custom_generator_serializationCOMMAND test_custom_generator_serialization
4246
WORKING_DIRECTORY${CMAKE_CURRENT_SOURCE_DIR}/test
4347
)
48+
add_test(NAME test_target_serializationCOMMAND test_target_serialization
49+
WORKING_DIRECTORY${CMAKE_CURRENT_SOURCE_DIR}/test
50+
)
4451
endif()
4552

4653
set(SCHEMA_SRCS
47-
include/schema/private/schema_util.h
4854
include/schema/interface/serialization_interface.h
4955

5056
include/schema/path.h
5157

5258
src/custom_generator_serialization.cpp
59+
include/schema/custom_generator_schema.h
5360
include/schema/custom_generator_serialization.h
5461

5562
src/target_serialization.cpp
63+
include/schema/target_schema.h
5664
include/schema/target_serialization.h
5765
)
5866

@@ -67,7 +75,6 @@ if(${BUILDCC_BUILD_AS_SINGLE_LIB})
6775
target_include_directories(buildccPRIVATE
6876
${SCHEMA_BUILD_DIR}
6977
)
70-
add_dependencies(buildcc fbs_to_header)
7178
endif()
7279

7380
if(${BUILDCC_BUILD_AS_INTERFACE})
@@ -89,7 +96,6 @@ if(${BUILDCC_BUILD_AS_INTERFACE})
8996
)
9097
target_compile_options(schemaPRIVATE${BUILD_COMPILE_FLAGS})
9198
target_link_options(schemaPRIVATE${BUILD_LINK_FLAGS})
92-
add_dependencies(schema fbs_to_header)
9399
endif()
94100

95101
if (${BUILDCC_INSTALL})

‎buildcc/schema/cmake/schema_generate.cmake‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎buildcc/schema/include/schema/custom_generator_schema.h‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,34 @@ namespace buildcc::internal {
2525

2626
structCustomGeneratorSchema {
2727
private:
28-
staticconstexprconstchar *constkSchemaName ="name";
29-
staticconstexprconstchar *constkIdsName ="ids";
30-
staticconstexprconstchar *constkGroupsName ="groups";
28+
staticconstexprconstchar *constkName ="name";
29+
staticconstexprconstchar *constkIds ="ids";
30+
staticconstexprconstchar *constkGroups ="groups";
3131

3232
public:
3333
using IdKey = std::string;
3434
using GroupKey = std::string;
3535
structIdInfo {
3636
private:
37-
staticconstexprconstchar *constkInputsName ="inputs";
38-
staticconstexprconstchar *constkOutputsName ="outputs";
39-
staticconstexprconstchar *constkUserblobName ="userblob";
37+
staticconstexprconstchar *constkInputs ="inputs";
38+
staticconstexprconstchar *constkOutputs ="outputs";
39+
staticconstexprconstchar *constkUserblob ="userblob";
4040

4141
public:
4242
path_unordered_set internal_inputs;
4343
fs_unordered_set outputs;
4444
std::vector<uint8_t> userblob;
4545

4646
friendvoidto_json(json &j,const IdInfo &info) {
47-
j[kInputsName] = info.internal_inputs;
48-
j[kOutputsName] = info.outputs;
49-
j[kUserblobName] = info.userblob;
47+
j[kInputs] = info.internal_inputs;
48+
j[kOutputs] = info.outputs;
49+
j[kUserblob] = info.userblob;
5050
}
5151

5252
friendvoidfrom_json(const json &j, IdInfo &info) {
53-
j.at(kInputsName).get_to(info.internal_inputs);
54-
j.at(kOutputsName).get_to(info.outputs);
55-
j.at(kUserblobName).get_to(info.userblob);
53+
j.at(kInputs).get_to(info.internal_inputs);
54+
j.at(kOutputs).get_to(info.outputs);
55+
j.at(kUserblob).get_to(info.userblob);
5656
}
5757
};
5858

@@ -65,15 +65,15 @@ struct CustomGeneratorSchema {
6565
std::unordered_map<GroupKey, GroupInfo> internal_groups;
6666

6767
friendvoidto_json(json &j,const CustomGeneratorSchema &schema) {
68-
j[kSchemaName] = schema.name;
69-
j[kIdsName] = schema.internal_ids;
70-
j[kGroupsName] = schema.internal_groups;
68+
j[kName] = schema.name;
69+
j[kIds] = schema.internal_ids;
70+
j[kGroups] = schema.internal_groups;
7171
}
7272

7373
friendvoidfrom_json(const json &j, CustomGeneratorSchema &schema) {
74-
j.at(kSchemaName).get_to(schema.name);
75-
j.at(kIdsName).get_to(schema.internal_ids);
76-
j.at(kGroupsName).get_to(schema.internal_groups);
74+
j.at(kName).get_to(schema.name);
75+
j.at(kIds).get_to(schema.internal_ids);
76+
j.at(kGroups).get_to(schema.internal_groups);
7777
}
7878
};
7979

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp