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

Generator code refactoring#216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
coder137 merged 20 commits intomainfromcode_refactoring
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
20 commits
Select commitHold shift + click to select a range
53dc003
Updated custom_generator
coder137May 23, 2022
43af778
Updated file_generator
coder137May 23, 2022
d91d214
Updated template_generator
coder137May 23, 2022
a043db2
Minor update to cmake files
coder137May 23, 2022
2dc3e12
Updated path.h
coder137May 23, 2022
fc32667
Updated example
coder137May 23, 2022
8841f71
Updated unit test
coder137May 23, 2022
3ae899f
Updated bootstrap files
coder137May 23, 2022
11eebd4
Updated target.h
coder137May 23, 2022
390e91f
Updated bootstrap
coder137May 23, 2022
cc2a7de
Removed Target state from Target
coder137May 23, 2022
82c49b6
Update custom_generator from gen_* to current_*
coder137May 26, 2022
2842f9b
Minor updates to file_generator.h
coder137May 26, 2022
0fe6772
Updated tests
coder137May 26, 2022
2b01557
Updated bootstrap and example
coder137May 26, 2022
4c659e0
Updated default_values.txt.in
coder137May 26, 2022
2f1daa7
Updated template_generator
coder137May 26, 2022
a931d5d
Update file_generator.cpp
coder137May 26, 2022
7540191
Updated custom_generator.cpp
coder137May 26, 2022
c89bc08
Added unit test for PCH failure case
coder137Oct 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletionsbootstrap/src/build_buildcc.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,22 +19,26 @@
namespace buildcc {

void schema_gen_cb(FileGenerator &generator, const BaseTarget &flatc_exe) {
generator.AddInput("{gen_root_dir}/path.fbs", "path_fbs");
generator.AddInput("{gen_root_dir}/custom_generator.fbs",
"custom_generator_fbs");
generator.AddInput("{gen_root_dir}/target.fbs", "target_fbs");
generator.AddPattern("path_fbs", "{current_root_dir}/path.fbs");
generator.AddPattern("custom_generator_fbs",
"{current_root_dir}/custom_generator.fbs");
generator.AddPattern("target_fbs", "{current_root_dir}/target.fbs");

generator.AddOutput("{gen_build_dir}/path_generated.h");
generator.AddOutput("{gen_build_dir}/custom_generator_generated.h");
generator.AddOutput("{gen_build_dir}/target_generated.h");
generator.AddInput("{path_fbs}");
generator.AddInput("{custom_generator_fbs}");
generator.AddInput("{target_fbs}");

generator.AddOutput("{current_build_dir}/path_generated.h");
generator.AddOutput("{current_build_dir}/custom_generator_generated.h");
generator.AddOutput("{current_build_dir}/target_generated.h");

generator.AddPatterns({
{"flatc_compiler", fmt::format("{}", flatc_exe.GetTargetPath())},
});
// generator.AddCommand("{flatc_compiler} --help");
generator.AddCommand(
"{flatc_compiler} -o {gen_build_dir} -I {gen_root_dir} --gen-object-api "
"--cpp {path_fbs} {custom_generator_fbs} {target_fbs}");
generator.AddCommand("{flatc_compiler} -o {current_build_dir} -I "
"{current_root_dir} --gen-object-api "
"--cpp {path_fbs} {custom_generator_fbs} {target_fbs}");

generator.Build();
}
Expand All@@ -45,7 +49,7 @@ void buildcc_cb(BaseTarget &target, const FileGenerator &schema_gen,
const TargetInfo &taskflow_ho, const BaseTarget &tpl) {
// NOTE, Build as single lib
target.AddIncludeDir("", true);
const std::string &schema_build_dir = schema_gen.Get("gen_build_dir");
const std::string &schema_build_dir = schema_gen.Get("current_build_dir");
target.AddIncludeDirAbsolute(schema_build_dir, true);

// ENV
Expand Down
1 change: 1 addition & 0 deletionsbuildcc/lib/target/cmake/common_target_src.cmake
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,5 +56,6 @@ set(COMMON_TARGET_SRCS
# Target
src/target/target.cpp
src/target/build.cpp
src/target/tasks.cpp
include/target/target.h
)
1 change: 0 additions & 1 deletionbuildcc/lib/target/cmake/mock_target.cmake
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,6 @@ add_library(mock_target STATIC
mock/custom_generator/recheck_states.cpp

# Target mocks
src/target/tasks.cpp
mock/target/runner.cpp
mock/target/recheck_states.cpp
)
Expand Down
1 change: 0 additions & 1 deletionbuildcc/lib/target/cmake/target.cmake
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,6 @@ set(TARGET_SRCS
src/custom_generator/recheck_states.cpp

src/target/recheck_states.cpp
src/target/tasks.cpp
)

if(${BUILDCC_BUILD_AS_SINGLE_LIB})
Expand Down
10 changes: 8 additions & 2 deletionsbuildcc/lib/target/include/target/custom_generator.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -134,8 +134,9 @@ class CustomGenerator : public internal::BuilderInterface {
* @param generate_cb User-defined generate callback to build outputs from the
* provided inputs
*/
void AddGenInfo(const std::string &id, const fs_unordered_set &inputs,
const fs_unordered_set &outputs,
void AddGenInfo(const std::string &id,
const std::unordered_set<std::string> &inputs,
const std::unordered_set<std::string> &outputs,
const GenerateCb &generate_cb,
std::shared_ptr<CustomBlobHandler> blob_handler = nullptr);

Expand DownExpand Up@@ -192,6 +193,11 @@ class CustomGenerator : public internal::BuilderInterface {
void IdUpdated();

protected:
std::string ParsePattern(const std::string &pattern,
const std::unordered_map<const char *, std::string>
&arguments = {}) const {
return command_.Construct(pattern, arguments);
}
const env::Command &ConstCommand() const { return command_; }
env::Command &RefCommand() { return command_; }

Expand Down
14 changes: 6 additions & 8 deletionsbuildcc/lib/target/include/target/file_generator.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,25 +29,23 @@ class FileGenerator : public CustomGenerator {

/**
* @brief Add absolute input path pattern to generator
* NOTE: We can use {gen_root_dir} and {gen_build_dir} in the
* NOTE: We can use {current_root_dir} and {current_build_dir} in the
* absolute_input_pattern
*
* If `identifier` is supplied it is added to default arguments as a key
* Example: fmt::format("{identifier}") -> "absolute_input_pattern"
*/
void AddInput(const std::string &absolute_input_pattern,
const char *identifier = nullptr);
void AddInput(const std::string &absolute_input_pattern);

/**
* @brief Add absolute output path pattern to generator
* NOTE: We can use {gen_root_dir} and {gen_build_dir} in the
* NOTE: We can use {current_root_dir} and {current_build_dir} in the
* absolute_output_pattern
*
* If `identifier` is supplied it is added to default arguments as a key
* Example: fmt::format("{identifier}") -> "absolute_output_pattern"
*/
void AddOutput(const std::string &absolute_output_pattern,
const char *identifier = nullptr);
void AddOutput(const std::string &absolute_output_pattern);

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

private:
//
internal::fs_unordered_set inputs_;
internal::fs_unordered_set outputs_;
std::unordered_set<std::string> inputs_;
std::unordered_set<std::string> outputs_;
std::vector<std::string> commands_;
};

Expand Down
14 changes: 1 addition & 13 deletionsbuildcc/lib/target/include/target/target.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,15 +77,12 @@ class Target : public internal::BuilderInterface,
compile_pch_(*this), compile_object_(*this), link_target_(*this) {
Initialize();
}
virtual ~Target(){}
virtual ~Target()= default;
Target(const Target &target) = delete;

// Builders
void Build() override;

// Getters
env::TaskState GetTaskState() const noexcept { return task_state_; }

private:
friend class internal::CompilePch;
friend class internal::CompileObject;
Expand All@@ -112,14 +109,7 @@ class Target : public internal::BuilderInterface,
const std::vector<std::string> &current_external_libs);

// Tasks
void SetTaskStateFailure();
int GetTaskStateAsInt() const noexcept {
return static_cast<int>(task_state_);
}

void StartTask();
void EndTask();
tf::Task CheckStateTask();
void TaskDeps();

// Callbacks for unit tests
Expand DownExpand Up@@ -151,8 +141,6 @@ class Target : public internal::BuilderInterface,
// Task states
tf::Task target_start_task_;
tf::Task target_end_task_;
std::mutex task_state_mutex_;
env::TaskState task_state_{env::TaskState::SUCCESS};
};

typedef Target BaseTarget;
Expand Down
10 changes: 6 additions & 4 deletionsbuildcc/lib/target/include/target/template_generator.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
#ifndef TARGET_TEMPLATE_GENERATOR_H_
#define TARGET_TEMPLATE_GENERATOR_H_

#include <string_view>

#include "target/custom_generator.h"

namespace buildcc {
Expand All@@ -27,8 +29,8 @@ class TemplateGenerator : public CustomGenerator {
~TemplateGenerator() override = default;
TemplateGenerator(const TemplateGenerator &) = delete;

void AddTemplate(const fs::path &input_filename,
const fs::path &output_filename);
void AddTemplate(std::string_view absolute_input_pattern,
std::string_view absolute_output_pattern);
std::string Parse(const std::string &pattern) const;

/**
Expand All@@ -47,8 +49,8 @@ class TemplateGenerator : public CustomGenerator {

private:
struct TemplateInfo {
fs::path input;
fs::path output;
std::string input_pattern;
std::string output_pattern;
};

private:
Expand Down
25 changes: 13 additions & 12 deletionsbuildcc/lib/target/src/custom_generator/custom_generator.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,10 @@
namespace {

constexpr const char *const kGenerateTaskName = "Generate";
constexpr const char *const kProjectRootDirName = "project_root_dir";
constexpr const char *const kProjectBuildDirName = "project_build_dir";
constexpr const char *const kCurrentRootDirName = "current_root_dir";
constexpr const char *const kCurrentBuildDirName = "current_build_dir";

} // namespace

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

void CustomGenerator::AddGenInfo(
const std::string &id, const fs_unordered_set &inputs,
const fs_unordered_set &outputs, const GenerateCb &generate_cb,
const std::string &id, const std::unordered_set<std::string> &inputs,
const std::unordered_set<std::string> &outputs,
const GenerateCb &generate_cb,
std::shared_ptr<CustomBlobHandler> blob_handler) {
env::assert_fatal(user_.gen_info_map.find(id) == user_.gen_info_map.end(),
fmt::format("Duplicate id {} detected", id));
ASSERT_FATAL(generate_cb, "Invalid callback provided");

UserGenInfo schema;
for (const auto &i : inputs) {
fs::path input =
internal::Path::CreateNewPath(command_.Construct(path_as_string(i)))
.GetPathname();
fs::path input = string_as_path(command_.Construct(i));
schema.inputs.emplace(std::move(input));
}
for (const auto &o : outputs) {
fs::path output =
internal::Path::CreateNewPath(command_.Construct(path_as_string(o)))
.GetPathname();
fs::path output = string_as_path(command_.Construct(o));
schema.outputs.emplace(std::move(output));
}
schema.generate_cb = generate_cb;
Expand DownExpand Up@@ -109,10 +110,10 @@ void CustomGenerator::Initialize() {
//
fs::create_directories(env_.GetTargetBuildDir());
command_.AddDefaultArguments({
{"project_root_dir", path_as_string(Project::GetRootDir())},
{"project_build_dir", path_as_string(Project::GetBuildDir())},
{"gen_root_dir", path_as_string(env_.GetTargetRootDir())},
{"gen_build_dir", path_as_string(env_.GetTargetBuildDir())},
{kProjectRootDirName, path_as_string(Project::GetRootDir())},
{kProjectBuildDirName, path_as_string(Project::GetBuildDir())},
{kCurrentRootDirName, path_as_string(env_.GetTargetRootDir())},
{kCurrentBuildDirName, path_as_string(env_.GetTargetBuildDir())},
});

//
Expand Down
29 changes: 5 additions & 24 deletionsbuildcc/lib/target/src/generator/file_generator.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -95,37 +95,18 @@ bool FileGeneratorGenerateCb(const buildcc::CustomGeneratorContext &ctx) {

namespace buildcc {

void FileGenerator::AddInput(const std::string &absolute_input_pattern,
const char *identifier) {
std::string absolute_input_string =
RefCommand().Construct(absolute_input_pattern);
const auto absolute_input_path =
internal::Path::CreateNewPath(absolute_input_string);
inputs_.insert(absolute_input_path.GetPathname());

if (identifier != nullptr) {
AddPattern(identifier, absolute_input_path.GetPathAsString());
}
void FileGenerator::AddInput(const std::string &absolute_input_pattern) {
inputs_.emplace(absolute_input_pattern);
}

void FileGenerator::AddOutput(const std::string &absolute_output_pattern,
const char *identifier) {
std::string absolute_output_string =
RefCommand().Construct(absolute_output_pattern);
const auto absolute_output_path =
internal::Path::CreateNewPath(absolute_output_string);
outputs_.insert(absolute_output_path.GetPathname());

if (identifier != nullptr) {
AddPattern(identifier, absolute_output_path.GetPathAsString());
}
void FileGenerator::AddOutput(const std::string &absolute_output_pattern) {
outputs_.emplace(absolute_output_pattern);
}

void FileGenerator::AddCommand(
const std::string &command_pattern,
const std::unordered_map<const char *, std::string> &arguments) {
std::string constructed_command =
RefCommand().Construct(command_pattern, arguments);
std::string constructed_command = ParsePattern(command_pattern, arguments);
commands_.emplace_back(std::move(constructed_command));
}

Expand Down
22 changes: 10 additions & 12 deletionsbuildcc/lib/target/src/generator/template_generator.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,20 +44,16 @@ bool template_generate_cb(const buildcc::CustomGeneratorContext &ctx) {

namespace buildcc {

void TemplateGenerator::AddTemplate(const fs::path &input_filename,
const fs::path &output_filename) {
void TemplateGenerator::AddTemplate(std::string_view absolute_input_pattern,
std::string_view absolute_output_pattern) {
TemplateInfo info;
info.input = internal::Path::CreateNewPath(
RefCommand().Construct(path_as_string(input_filename)))
.GetPathname();
info.output = internal::Path::CreateNewPath(
RefCommand().Construct(path_as_string(output_filename)))
.GetPathname();
info.input_pattern = absolute_input_pattern;
info.output_pattern = absolute_output_pattern;
template_infos_.emplace_back(std::move(info));
}

std::string TemplateGenerator::Parse(const std::string &pattern) const {
returnConstCommand().Construct(pattern);
returnParsePattern(pattern);
}

/**
Expand All@@ -67,9 +63,11 @@ std::string TemplateGenerator::Parse(const std::string &pattern) const {
*/
void TemplateGenerator::Build() {
for (const auto &info : template_infos_) {
std::string name =
info.input.lexically_relative(Project::GetRootDir()).string();
AddGenInfo(name, {info.input}, {info.output}, template_generate_cb);
std::string name = string_as_path(ParsePattern(info.input_pattern))
.lexically_relative(Project::GetRootDir())
.string();
AddGenInfo(name, {info.input_pattern}, {info.output_pattern},
template_generate_cb);
}
this->CustomGenerator::Build();
}
Expand Down
7 changes: 3 additions & 4 deletionsbuildcc/lib/target/src/target/build.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,10 +97,6 @@ void Target::Build() {
// Load the serialized file
(void)serialization_.LoadFromFile();

// Target State Tasks
StartTask();
EndTask();

// PCH Compile
if (state_.ContainsPch()) {
command_.AddDefaultArguments({
Expand All@@ -119,6 +115,9 @@ void Target::Build() {
});
}

// Target State Tasks
EndTask();

// Compile Command
compile_object_.CacheCompileCommands();
compile_object_.Task();
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp