Skip to content

Refactor Register constructable class to Reg static class #204

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
448125c
Update args.rst
coder137 Mar 29, 2022
363d3ff
Updated Args
coder137 Mar 29, 2022
d78b379
Updated Args bool APIs
coder137 Mar 29, 2022
7c3c300
Updated args and test_args
coder137 Mar 30, 2022
b743dc0
Added Reg API
coder137 Mar 31, 2022
9808773
Updated register
coder137 Mar 31, 2022
8429d17
Updated register
coder137 Mar 31, 2022
32d45d3
Updated register
coder137 Apr 1, 2022
4ecbcea
Updated example build files
coder137 Apr 1, 2022
0c2c1ac
Update register.h
coder137 Apr 1, 2022
3115ace
Update args.h
coder137 Apr 1, 2022
524a033
Updated examples
coder137 Apr 1, 2022
b5cb26f
Updated bootstrap and buildexe
coder137 Apr 1, 2022
991839e
Update build.main.cpp
coder137 Apr 1, 2022
f8f3bac
Updated Register
coder137 Apr 1, 2022
4c76a28
Updated register
coder137 Apr 1, 2022
3ce5975
Update test_register.cpp
coder137 Apr 2, 2022
b4d6faf
Updated register, Shifted internally
coder137 Apr 2, 2022
7b35311
Update build.cpp
coder137 Apr 2, 2022
623aefd
Renamed Register to Instance
coder137 Apr 2, 2022
a7e851a
Updated Reg::Instance
coder137 Apr 2, 2022
deb2666
Updated register dep usage
coder137 Apr 2, 2022
4333c9c
Removed executor from Reg::Instance
coder137 Apr 2, 2022
d4a4cb0
Updated register
coder137 Apr 2, 2022
9ceecd0
Update tpl buildcc script
coder137 Apr 7, 2022
0d82f8b
Update build_buildcc.cpp
coder137 Apr 7, 2022
01e910c
Update register.h
coder137 Apr 7, 2022
7476c0e
Update build_buildcc.cpp
coder137 Apr 7, 2022
b5c4ba9
Update register.h
coder137 Apr 8, 2022
62c88fc
Update build_buildcc.cpp
coder137 Apr 8, 2022
7e78a67
Update main.buildcc.cpp
coder137 Apr 8, 2022
49dc94a
Update args.h
coder137 Apr 8, 2022
d00723a
Update register.h
coder137 Apr 8, 2022
b46eba8
Updated documentation
coder137 Apr 8, 2022
beea759
Updated documentation
coder137 Apr 8, 2022
37c839a
Updated documentation
coder137 Apr 8, 2022
a0bc5ab
Update test_register.cpp
coder137 Apr 8, 2022
4e76dd6
Update test_register.cpp
coder137 Apr 8, 2022
84212c1
Update test_register.cpp
coder137 Apr 8, 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
6 changes: 2 additions & 4 deletions bootstrap/include/bootstrap/build_buildcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class BuildBuildCC {
static constexpr const char *const kBuildccLibName = "libbuildcc";

public:
BuildBuildCC(Register &reg, const BaseToolchain &toolchain,
const TargetEnv &env)
: reg_(reg), toolchain_(toolchain), env_(env) {}
BuildBuildCC(const BaseToolchain &toolchain, const TargetEnv &env)
: toolchain_(toolchain), env_(env) {}
BuildBuildCC(const BuildBuildCC &) = delete;

void Setup(const ArgToolchainState &state);
Expand All @@ -75,7 +74,6 @@ class BuildBuildCC {
}

private:
Register &reg_;
const BaseToolchain &toolchain_;
TargetEnv env_;

Expand Down
8 changes: 1 addition & 7 deletions bootstrap/include/bootstrap/build_tpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@

namespace buildcc {

struct TplConfig {
TplConfig() = default;

OsId os_id{OsId::Linux};
};

void tpl_cb(BaseTarget &target, const TplConfig &config = TplConfig());
void tpl_cb(BaseTarget &target);

} // namespace buildcc

Expand Down
19 changes: 10 additions & 9 deletions bootstrap/main.buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,32 @@ int main(int argc, char **argv) {
.AddToolchain("host", "Host Toolchain", custom_toolchain_arg)
.Parse(argc, argv);

Register reg;
reg.Clean(clean_cb);
Reg::Init();
Reg::Call(Args::Clean()).Func(clean_cb);

BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain();
toolchain.Verify();

BuildBuildCC buildcc(
reg, toolchain, TargetEnv(Project::GetRootDir(), Project::GetBuildDir()));
toolchain, TargetEnv(Project::GetRootDir(), Project::GetBuildDir()));
buildcc.Setup(custom_toolchain_arg.state);

const auto &buildcc_lib = buildcc.GetBuildcc();
ExecutableTarget_generic buildcc_hybrid_simple_example(
"buildcc_hybrid_simple_example", toolchain, "example/hybrid/simple");
reg.Build(custom_toolchain_arg.state, hybrid_simple_example_cb,
buildcc_hybrid_simple_example, buildcc_lib);
reg.Dep(buildcc_hybrid_simple_example, buildcc_lib);
Reg::Toolchain(custom_toolchain_arg.state)
.Build(hybrid_simple_example_cb, buildcc_hybrid_simple_example,
buildcc_lib)
.Dep(buildcc_hybrid_simple_example, buildcc_lib);

// Runners
reg.RunBuild();
reg.RunTest();
Reg::Run();

// - Clang Compile Commands
plugin::ClangCompileCommands({&buildcc_lib}).Generate();

// - Plugin Graph
std::string output = reg.GetTaskflow().dump();
std::string output = Reg::GetTaskflow().dump();
const bool saved = env::save_file("graph.dot", output, false);
env::assert_fatal(saved, "Could not save graph.dot file");

Expand Down
41 changes: 20 additions & 21 deletions bootstrap/src/build_buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
if constexpr (env::is_win()) {
// TODO, Clang
switch (target.GetToolchain().GetId()) {
case ToolchainId::Gcc:
case ToolchainId::MinGW: {
target.AddPreprocessorFlag("-DFMT_HEADER_ONLY=1");
target.AddPreprocessorFlag("-DSPDLOG_FMT_EXTERNAL");
Expand All @@ -147,7 +146,7 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
}
}

if constexpr (env::is_linux()) {
if constexpr (env::is_linux() || env::is_unix() || env::is_clang()) {
// TODO, Clang
switch (target.GetToolchain().GetId()) {
case ToolchainId::Gcc: {
Expand Down Expand Up @@ -196,51 +195,41 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
env_.GetTargetBuildDir()));

reg_.CallbackIf(state, global_flags_cb, flatc_exe, toolchain_);
reg_.Build(state, build_flatc_exe_cb, flatc_exe);

// Schema
auto &schema_gen = storage_.Add<BaseGenerator>(
kSchemaGenName, kSchemaGenName,
TargetEnv(env_.GetTargetRootDir() / "buildcc" / "schema",
env_.GetTargetBuildDir() / toolchain_.GetName()));
reg_.Build(schema_gen_cb, schema_gen, flatc_exe);
reg_.Dep(schema_gen, flatc_exe);

// Flatbuffers HO lib
auto &flatbuffers_ho_lib = storage_.Add<TargetInfo>(
kFlatbuffersHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "flatbuffers",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, flatbuffers_ho_cb, flatbuffers_ho_lib);

// CLI11 HO lib
auto &cli11_ho_lib = storage_.Add<TargetInfo>(
kCli11HoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "CLI11",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, cli11_ho_cb, cli11_ho_lib);

// fmt HO lib
auto &fmt_ho_lib = storage_.Add<TargetInfo>(
kFmtHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "fmt",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, fmt_ho_cb, fmt_ho_lib);

// spdlog HO lib
auto &spdlog_ho_lib = storage_.Add<TargetInfo>(
kSpdlogHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "spdlog",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, spdlog_ho_cb, spdlog_ho_lib);

// taskflow HO lib
auto &taskflow_ho_lib = storage_.Add<TargetInfo>(
kTaskflowHoName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "third_party" / "taskflow",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, taskflow_ho_cb, taskflow_ho_lib);

// Tiny-process-library lib
// TODO, Make this a generic selection between StaticTarget and
Expand All @@ -250,21 +239,31 @@ void BuildBuildCC::Setup(const ArgToolchainState &state) {
TargetEnv(env_.GetTargetRootDir() / "third_party" /
"tiny-process-library",
env_.GetTargetBuildDir()));
reg_.CallbackIf(state, global_flags_cb, tpl_lib, toolchain_);
TplConfig tpl_config;
tpl_config.os_id = get_host_os();
reg_.Build(state, tpl_cb, tpl_lib, tpl_config);

// BuildCC lib
// TODO, Make this a generic selection between StaticTarget and
// DynamicTarget
auto &buildcc_lib = storage_.Add<StaticTarget_generic>(
kBuildccLibName, kBuildccLibName, toolchain_,
TargetEnv(env_.GetTargetRootDir() / "buildcc", env_.GetTargetBuildDir()));
reg_.CallbackIf(state, global_flags_cb, buildcc_lib, toolchain_);
reg_.Build(state, buildcc_cb, buildcc_lib, schema_gen, flatbuffers_ho_lib,
fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib, tpl_lib);
reg_.Dep(buildcc_lib, schema_gen);
reg_.Dep(buildcc_lib, tpl_lib);

Reg::Toolchain(state)
.Func(global_flags_cb, flatc_exe, toolchain_)
.Build(build_flatc_exe_cb, flatc_exe)
.Build(schema_gen_cb, schema_gen, flatc_exe)
.Dep(schema_gen, flatc_exe)
.Func(flatbuffers_ho_cb, flatbuffers_ho_lib)
.Func(cli11_ho_cb, cli11_ho_lib)
.Func(fmt_ho_cb, fmt_ho_lib)
.Func(spdlog_ho_cb, spdlog_ho_lib)
.Func(taskflow_ho_cb, taskflow_ho_lib)
.Func(global_flags_cb, tpl_lib, toolchain_)
.Build(tpl_cb, tpl_lib)
.Func(global_flags_cb, buildcc_lib, toolchain_)
.Build(buildcc_cb, buildcc_lib, schema_gen, flatbuffers_ho_lib,
fmt_ho_lib, spdlog_ho_lib, cli11_ho_lib, taskflow_ho_lib, tpl_lib)
.Dep(buildcc_lib, schema_gen)
.Dep(buildcc_lib, tpl_lib);
}

} // namespace buildcc
15 changes: 5 additions & 10 deletions bootstrap/src/build_tpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@

namespace buildcc {

void tpl_cb(BaseTarget &target, const TplConfig &config) {
void tpl_cb(BaseTarget &target) {
target.AddSource("process.cpp");
target.AddIncludeDir("");
target.AddHeader("process.hpp");

switch (config.os_id) {
case OsId::Win:
if constexpr (env::is_win()) {
target.AddSource("process_win.cpp");
break;
case OsId::Linux:
case OsId::Unix:
case OsId::Mac:
}

if constexpr (env::is_linux() || env::is_unix() || env::is_clang()) {
target.AddSource("process_unix.cpp");
break;
default:
break;
}

target.Build();
Expand Down
124 changes: 69 additions & 55 deletions buildcc/lib/args/include/args/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@

#include "toolchain/toolchain.h"

#include "target/common/target_config.h"

namespace fs = std::filesystem;

namespace buildcc {

/**
* @brief Toolchain State used by the Register module to selectively build or
* test targets
* @brief Toolchain State used to selectively build and test targets
*/
struct ArgToolchainState {
bool build{false};
Expand Down Expand Up @@ -81,8 +82,15 @@ struct ArgToolchain {
struct ArgTarget {
ArgTarget(){};

std::string compile_command{""};
std::string link_command{""};
TargetConfig GetTargetConfig() {
TargetConfig config;
config.compile_command = compile_command;
config.link_command = link_command;
return config;
}

std::string compile_command;
std::string link_command;
};

struct ArgCustom {
Expand All @@ -91,56 +99,8 @@ struct ArgCustom {

class Args {
private:
class Instance {
public:
/**
* @brief Parse command line information to CLI11
*
* @param argc from int main(int argc, char ** argv)
* @param argv from int main(int argc, char ** argv)
*/
static void Parse(int argc, const char *const *argv);

/**
* @brief Add toolchain with a unique name and description
*
* @param out Receive the toolchain information through the CLI
* @param initial Set the default toolchain information as a fallback
*/
Instance &AddToolchain(const std::string &name,
const std::string &description, ArgToolchain &out,
const ArgToolchain &initial = ArgToolchain());

/**
* @brief Add toolchain with a unique name and description
*
* @param out Receive the toolchain information through the CLI
* @param initial Set the default toolchain information as a fallback
*/
Instance &AddTarget(const std::string &name, const std::string &description,
ArgTarget &out, const ArgTarget &initial = ArgTarget());

/**
* @brief Custom callback for data
*
* @param add_cb Add callback that exposes underlying CLI::App
*/
Instance &AddCustomCallback(const std::function<void(CLI::App &)> &add_cb);

/**
* @brief Add custom data
*
* @param data Derive from `buildcc::ArgCustom` and override the `Add` API
*/
Instance &AddCustomData(ArgCustom &data);
};

struct Internal {
Instance instance;
CLI::App app{"BuildCC Buildsystem"};
CLI::App *toolchain{nullptr};
CLI::App *target{nullptr};
};
class Instance;
struct Internal;

public:
Args() = delete;
Expand All @@ -151,6 +111,8 @@ class Args {
static void Deinit();

// Getters
static bool IsInit();
static bool IsParsed();
static bool Clean();
static env::LogLevel GetLogLevel();

Expand All @@ -159,12 +121,64 @@ class Args {

private:
static void RootArgs();
static CLI::App &Ref();
static Internal &RefInternal();
static CLI::App &RefApp();

private:
static std::unique_ptr<Internal> internal_;
};

class Args::Instance {
public:
/**
* @brief Parse command line information to CLI11
*
* @param argc from int main(int argc, char ** argv)
* @param argv from int main(int argc, char ** argv)
*/
static void Parse(int argc, const char *const *argv);

/**
* @brief Add toolchain with a unique name and description
*
* @param out Receive the toolchain information through the CLI
* @param initial Set the default toolchain information as a fallback
*/
Instance &AddToolchain(const std::string &name,
const std::string &description, ArgToolchain &out,
const ArgToolchain &initial = ArgToolchain());

/**
* @brief Add toolchain with a unique name and description
*
* @param out Receive the toolchain information through the CLI
* @param initial Set the default toolchain information as a fallback
*/
Instance &AddTarget(const std::string &name, const std::string &description,
ArgTarget &out, const ArgTarget &initial = ArgTarget());

/**
* @brief Custom callback for data
*
* @param add_cb Add callback that exposes underlying CLI::App
*/
Instance &AddCustomCallback(const std::function<void(CLI::App &)> &add_cb);

/**
* @brief Add custom data
*
* @param data Derive from `buildcc::ArgCustom` and override the `Add` API
*/
Instance &AddCustomData(ArgCustom &data);
};

struct Args::Internal {
Instance instance;
CLI::App app{"BuildCC Buildsystem"};
CLI::App *toolchain{nullptr};
CLI::App *target{nullptr};
};

} // namespace buildcc

#endif
Loading