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

Commit05ad3df

Browse files
authored
Generator code refactoring (#216)
1 parent8b00500 commit05ad3df

File tree

22 files changed

+347
-363
lines changed

22 files changed

+347
-363
lines changed

‎bootstrap/src/build_buildcc.cpp‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,26 @@
1919
namespacebuildcc {
2020

2121
voidschema_gen_cb(FileGenerator &generator,const BaseTarget &flatc_exe) {
22-
generator.AddInput("{gen_root_dir}/path.fbs","path_fbs");
23-
generator.AddInput("{gen_root_dir}/custom_generator.fbs",
24-
"custom_generator_fbs");
25-
generator.AddInput("{gen_root_dir}/target.fbs","target_fbs");
22+
generator.AddPattern("path_fbs","{current_root_dir}/path.fbs");
23+
generator.AddPattern("custom_generator_fbs",
24+
"{current_root_dir}/custom_generator.fbs");
25+
generator.AddPattern("target_fbs","{current_root_dir}/target.fbs");
2626

27-
generator.AddOutput("{gen_build_dir}/path_generated.h");
28-
generator.AddOutput("{gen_build_dir}/custom_generator_generated.h");
29-
generator.AddOutput("{gen_build_dir}/target_generated.h");
27+
generator.AddInput("{path_fbs}");
28+
generator.AddInput("{custom_generator_fbs}");
29+
generator.AddInput("{target_fbs}");
30+
31+
generator.AddOutput("{current_build_dir}/path_generated.h");
32+
generator.AddOutput("{current_build_dir}/custom_generator_generated.h");
33+
generator.AddOutput("{current_build_dir}/target_generated.h");
3034

3135
generator.AddPatterns({
3236
{"flatc_compiler",fmt::format("{}", flatc_exe.GetTargetPath())},
3337
});
3438
// generator.AddCommand("{flatc_compiler} --help");
35-
generator.AddCommand(
36-
"{flatc_compiler} -o {gen_build_dir} -I {gen_root_dir} --gen-object-api"
37-
"--cpp {path_fbs} {custom_generator_fbs} {target_fbs}");
39+
generator.AddCommand("{flatc_compiler} -o {current_build_dir} -I"
40+
"{current_root_dir} --gen-object-api"
41+
"--cpp {path_fbs} {custom_generator_fbs} {target_fbs}");
3842

3943
generator.Build();
4044
}
@@ -45,7 +49,7 @@ void buildcc_cb(BaseTarget &target, const FileGenerator &schema_gen,
4549
const TargetInfo &taskflow_ho,const BaseTarget &tpl) {
4650
// NOTE, Build as single lib
4751
target.AddIncludeDir("",true);
48-
const std::string &schema_build_dir = schema_gen.Get("gen_build_dir");
52+
const std::string &schema_build_dir = schema_gen.Get("current_build_dir");
4953
target.AddIncludeDirAbsolute(schema_build_dir,true);
5054

5155
// ENV

‎buildcc/lib/target/cmake/common_target_src.cmake‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ set(COMMON_TARGET_SRCS
5656
# Target
5757
src/target/target.cpp
5858
src/target/build.cpp
59+
src/target/tasks.cpp
5960
include/target/target.h
6061
)

‎buildcc/lib/target/cmake/mock_target.cmake‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ add_library(mock_target STATIC
55
mock/custom_generator/recheck_states.cpp
66

77
# Target mocks
8-
src/target/tasks.cpp
98
mock/target/runner.cpp
109
mock/target/recheck_states.cpp
1110
)

‎buildcc/lib/target/cmake/target.cmake‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set(TARGET_SRCS
44
src/custom_generator/recheck_states.cpp
55

66
src/target/recheck_states.cpp
7-
src/target/tasks.cpp
87
)
98

109
if(${BUILDCC_BUILD_AS_SINGLE_LIB})

‎buildcc/lib/target/include/target/custom_generator.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ class CustomGenerator : public internal::BuilderInterface {
134134
* @param generate_cb User-defined generate callback to build outputs from the
135135
* provided inputs
136136
*/
137-
voidAddGenInfo(const std::string &id,const fs_unordered_set &inputs,
138-
const fs_unordered_set &outputs,
137+
voidAddGenInfo(const std::string &id,
138+
const std::unordered_set<std::string> &inputs,
139+
const std::unordered_set<std::string> &outputs,
139140
const GenerateCb &generate_cb,
140141
std::shared_ptr<CustomBlobHandler> blob_handler =nullptr);
141142

@@ -192,6 +193,11 @@ class CustomGenerator : public internal::BuilderInterface {
192193
voidIdUpdated();
193194

194195
protected:
196+
std::stringParsePattern(const std::string &pattern,
197+
const std::unordered_map<constchar *, std::string>
198+
&arguments = {})const {
199+
return command_.Construct(pattern, arguments);
200+
}
195201
const env::Command &ConstCommand()const {return command_; }
196202
env::Command &RefCommand() {return command_; }
197203

‎buildcc/lib/target/include/target/file_generator.h‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,23 @@ class FileGenerator : public CustomGenerator {
2929

3030
/**
3131
* @brief Add absolute input path pattern to generator
32-
* NOTE: We can use {gen_root_dir} and {gen_build_dir} in the
32+
* NOTE: We can use {current_root_dir} and {current_build_dir} in the
3333
* absolute_input_pattern
3434
*
3535
* If `identifier` is supplied it is added to default arguments as a key
3636
* Example: fmt::format("{identifier}") -> "absolute_input_pattern"
3737
*/
38-
voidAddInput(const std::string &absolute_input_pattern,
39-
constchar *identifier =nullptr);
38+
voidAddInput(const std::string &absolute_input_pattern);
4039

4140
/**
4241
* @brief Add absolute output path pattern to generator
43-
* NOTE: We can use {gen_root_dir} and {gen_build_dir} in the
42+
* NOTE: We can use {current_root_dir} and {current_build_dir} in the
4443
* absolute_output_pattern
4544
*
4645
* If `identifier` is supplied it is added to default arguments as a key
4746
* Example: fmt::format("{identifier}") -> "absolute_output_pattern"
4847
*/
49-
voidAddOutput(const std::string &absolute_output_pattern,
50-
constchar *identifier =nullptr);
48+
voidAddOutput(const std::string &absolute_output_pattern);
5149

5250
/**
5351
* @brief Add a command_pattern that is fed to `Command::Execute` internally
@@ -77,8 +75,8 @@ class FileGenerator : public CustomGenerator {
7775

7876
private:
7977
//
80-
internal::fs_unordered_set inputs_;
81-
internal::fs_unordered_set outputs_;
78+
std::unordered_set<std::string> inputs_;
79+
std::unordered_set<std::string> outputs_;
8280
std::vector<std::string> commands_;
8381
};
8482

‎buildcc/lib/target/include/target/target.h‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,12 @@ class Target : public internal::BuilderInterface,
7777
compile_pch_(*this), compile_object_(*this), link_target_(*this) {
7878
Initialize();
7979
}
80-
virtual~Target(){}
80+
virtual~Target()=default;
8181
Target(const Target &target) =delete;
8282

8383
// Builders
8484
voidBuild()override;
8585

86-
// Getters
87-
env::TaskStateGetTaskState()constnoexcept {return task_state_; }
88-
8986
private:
9087
friendclassinternal::CompilePch;
9188
friendclassinternal::CompileObject;
@@ -112,14 +109,7 @@ class Target : public internal::BuilderInterface,
112109
const std::vector<std::string> &current_external_libs);
113110

114111
// Tasks
115-
voidSetTaskStateFailure();
116-
intGetTaskStateAsInt()constnoexcept {
117-
returnstatic_cast<int>(task_state_);
118-
}
119-
120-
voidStartTask();
121112
voidEndTask();
122-
tf::TaskCheckStateTask();
123113
voidTaskDeps();
124114

125115
// Callbacks for unit tests
@@ -151,8 +141,6 @@ class Target : public internal::BuilderInterface,
151141
// Task states
152142
tf::Task target_start_task_;
153143
tf::Task target_end_task_;
154-
std::mutex task_state_mutex_;
155-
env::TaskState task_state_{env::TaskState::SUCCESS};
156144
};
157145

158146
typedef Target BaseTarget;

‎buildcc/lib/target/include/target/template_generator.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef TARGET_TEMPLATE_GENERATOR_H_
1818
#defineTARGET_TEMPLATE_GENERATOR_H_
1919

20+
#include<string_view>
21+
2022
#include"target/custom_generator.h"
2123

2224
namespacebuildcc {
@@ -27,8 +29,8 @@ class TemplateGenerator : public CustomGenerator {
2729
~TemplateGenerator()override =default;
2830
TemplateGenerator(const TemplateGenerator &) =delete;
2931

30-
voidAddTemplate(const fs::path &input_filename,
31-
const fs::path &output_filename);
32+
voidAddTemplate(std::string_view absolute_input_pattern,
33+
std::string_view absolute_output_pattern);
3234
std::stringParse(const std::string &pattern)const;
3335

3436
/**
@@ -47,8 +49,8 @@ class TemplateGenerator : public CustomGenerator {
4749

4850
private:
4951
structTemplateInfo {
50-
fs::path input;
51-
fs::path output;
52+
std::string input_pattern;
53+
std::string output_pattern;
5254
};
5355

5456
private:

‎buildcc/lib/target/src/custom_generator/custom_generator.cpp‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
namespace {
2020

2121
constexprconstchar *constkGenerateTaskName ="Generate";
22+
constexprconstchar *constkProjectRootDirName ="project_root_dir";
23+
constexprconstchar *constkProjectBuildDirName ="project_build_dir";
24+
constexprconstchar *constkCurrentRootDirName ="current_root_dir";
25+
constexprconstchar *constkCurrentBuildDirName ="current_build_dir";
2226

2327
}// namespace
2428

@@ -42,24 +46,21 @@ CustomGenerator::Get(const std::string &file_identifier) const {
4246
}
4347

4448
voidCustomGenerator::AddGenInfo(
45-
const std::string &id,const fs_unordered_set &inputs,
46-
const fs_unordered_set &outputs,const GenerateCb &generate_cb,
49+
const std::string &id,const std::unordered_set<std::string> &inputs,
50+
const std::unordered_set<std::string> &outputs,
51+
const GenerateCb &generate_cb,
4752
std::shared_ptr<CustomBlobHandler> blob_handler) {
4853
env::assert_fatal(user_.gen_info_map.find(id) == user_.gen_info_map.end(),
4954
fmt::format("Duplicate id {} detected", id));
5055
ASSERT_FATAL(generate_cb,"Invalid callback provided");
5156

5257
UserGenInfo schema;
5358
for (constauto &i : inputs) {
54-
fs::path input =
55-
internal::Path::CreateNewPath(command_.Construct(path_as_string(i)))
56-
.GetPathname();
59+
fs::path input =string_as_path(command_.Construct(i));
5760
schema.inputs.emplace(std::move(input));
5861
}
5962
for (constauto &o : outputs) {
60-
fs::path output =
61-
internal::Path::CreateNewPath(command_.Construct(path_as_string(o)))
62-
.GetPathname();
63+
fs::path output =string_as_path(command_.Construct(o));
6364
schema.outputs.emplace(std::move(output));
6465
}
6566
schema.generate_cb = generate_cb;
@@ -109,10 +110,10 @@ void CustomGenerator::Initialize() {
109110
//
110111
fs::create_directories(env_.GetTargetBuildDir());
111112
command_.AddDefaultArguments({
112-
{"project_root_dir",path_as_string(Project::GetRootDir())},
113-
{"project_build_dir",path_as_string(Project::GetBuildDir())},
114-
{"gen_root_dir",path_as_string(env_.GetTargetRootDir())},
115-
{"gen_build_dir",path_as_string(env_.GetTargetBuildDir())},
113+
{kProjectRootDirName,path_as_string(Project::GetRootDir())},
114+
{kProjectBuildDirName,path_as_string(Project::GetBuildDir())},
115+
{kCurrentRootDirName,path_as_string(env_.GetTargetRootDir())},
116+
{kCurrentBuildDirName,path_as_string(env_.GetTargetBuildDir())},
116117
});
117118

118119
//

‎buildcc/lib/target/src/generator/file_generator.cpp‎

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,18 @@ bool FileGeneratorGenerateCb(const buildcc::CustomGeneratorContext &ctx) {
9595

9696
namespacebuildcc {
9797

98-
voidFileGenerator::AddInput(const std::string &absolute_input_pattern,
99-
constchar *identifier) {
100-
std::string absolute_input_string =
101-
RefCommand().Construct(absolute_input_pattern);
102-
constauto absolute_input_path =
103-
internal::Path::CreateNewPath(absolute_input_string);
104-
inputs_.insert(absolute_input_path.GetPathname());
105-
106-
if (identifier !=nullptr) {
107-
AddPattern(identifier, absolute_input_path.GetPathAsString());
108-
}
98+
voidFileGenerator::AddInput(const std::string &absolute_input_pattern) {
99+
inputs_.emplace(absolute_input_pattern);
109100
}
110101

111-
voidFileGenerator::AddOutput(const std::string &absolute_output_pattern,
112-
constchar *identifier) {
113-
std::string absolute_output_string =
114-
RefCommand().Construct(absolute_output_pattern);
115-
constauto absolute_output_path =
116-
internal::Path::CreateNewPath(absolute_output_string);
117-
outputs_.insert(absolute_output_path.GetPathname());
118-
119-
if (identifier !=nullptr) {
120-
AddPattern(identifier, absolute_output_path.GetPathAsString());
121-
}
102+
voidFileGenerator::AddOutput(const std::string &absolute_output_pattern) {
103+
outputs_.emplace(absolute_output_pattern);
122104
}
123105

124106
voidFileGenerator::AddCommand(
125107
const std::string &command_pattern,
126108
const std::unordered_map<constchar *, std::string> &arguments) {
127-
std::string constructed_command =
128-
RefCommand().Construct(command_pattern, arguments);
109+
std::string constructed_command =ParsePattern(command_pattern, arguments);
129110
commands_.emplace_back(std::move(constructed_command));
130111
}
131112

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp