Register

register.h

class Reg

Public Functions

Reg() = delete
Reg(const Reg&) = delete
Reg(Reg&&) = delete

Public Static Functions

static void Init()
static void Deinit()
static void Run(const std::function<void(void)> &post_build_cb = std::function<void(void)>())
static CallbackInstance Call(bool condition = true)
static ToolchainInstance Toolchain(const ArgToolchainState &condition)
static const tf::Taskflow &GetTaskflow()
class CallbackInstance

Public Functions

inline CallbackInstance(bool condition = true)
template<typename C, typename ...Params>
inline CallbackInstance &Func(const C &cb, Params&&... params)
template<typename C, typename T, typename ...Params>
inline CallbackInstance &Build(const C &build_cb, T &builder, Params&&... params)
class Instance

Public Functions

template<typename C, typename T, typename ...Params>
inline void Build(const C &build_cb, T &builder, Params&&... params)
void Dep(const internal::BuilderInterface &target, const internal::BuilderInterface &dependency)

Setup dependency between 2 Targets PreReq: Call Reg::Instance::Build before calling Reg::Instance::Dep

Target runs after dependency is built

void Test(const std::string &command, const BaseTarget &target, const TestConfig &config = TestConfig())

Instance the Target to be run PreReq: Call Reg::Instance::Build before calling Reg::Instance::Test PreReq: Requires ArgToolchainState::build && ArgToolchainState::test to be true.

Target is added as the {executable} argument. We can add more fmt::format arguments using the TestConfig arguments parameter

void RunBuild()

Builds the targets that have been dynamically added through Reg::Instance::Build

void RunTest()

Runs the targets that have been dynamically added through Reg::Instance::Test

inline const tf::Taskflow &GetTaskflow() const

Public Static Functions

template<typename C, typename ...Params>
static inline void Callback(const C &build_cb, Params&&... params)

Generic register callback with variable arguments Can be used to organize code into functional chunks.

template<typename C, typename ...Params>
static inline void CallbackIf(bool expression, const C &build_cb, Params&&... params)

Generic register callback that is run when expression == true Can be used to add Toolchain-Target specific information.

class ToolchainInstance

Public Functions

inline ToolchainInstance(const ArgToolchainState &condition)
template<typename C, typename ...Params>
inline ToolchainInstance &Func(const C &cb, Params&&... params)
template<typename C, typename T, typename ...Params>
inline ToolchainInstance &Build(const C &build_cb, T &builder, Params&&... params)
template<typename P>
inline ToolchainInstance &BuildPackage(P &package)
ToolchainInstance &Dep(const internal::BuilderInterface &target, const internal::BuilderInterface &dependency)
ToolchainInstance &Test(const std::string &command, const BaseTarget &target, const TestConfig &config = TestConfig())

test_info.h

struct TestConfig

Public Functions

inline TestConfig(const std::unordered_map<const char*, std::string> &arguments = {}, const env::optional<fs::path> &working_directory = {}, const TestOutput &output = TestOutput())

Configure your Reg::Instance::Test using TestConfig.

Parameters:
  • arguments – fmt::format args passed to test commands

  • working_directory – Working directory from which the test runs

  • output – Output from tests

inline const std::unordered_map<const char*, std::string> &GetArguments() const
inline const env::optional<fs::path> &GetWorkingDirectory() const
inline const TestOutput &GetTestOutput() const
struct TestOutput

Public Types

enum class Type

Values:

enumerator DefaultBehaviour

Do not redirect to user or tests, default printed on console

enumerator TestPrintOnStderr

Test only redirects stderr and prints.

enumerator TestPrintOnStdout

Test only redirects stdout and prints.

enumerator TestPrintOnStderrAndStdout

Test redirects both and prints.

enumerator UserRedirect

Redirects to user variables.

Public Functions

inline TestOutput(Type output_type = Type::TestPrintOnStderrAndStdout, std::vector<std::string> *redirect_stdout = nullptr, std::vector<std::string> *redirect_stderr = nullptr)

Configure your Reg::Instance::Test to get test output.

Parameters:
  • output_type – Select your output type (behaviour)

  • redirect_stdout – User stdout redirection

  • redirect_stderr – User stderr redirection

inline Type GetType() const
inline std::vector<std::string> *GetRedirectStdoutToUser() const
inline std::vector<std::string> *GetRedirectStderrToUser() const

Example

 1class BigObj {};
 2
 3static void callback_usage_func(const BigObj & cobj, BigObj & obj);
 4
 5int main(int argc, char ** argv) {
 6    Args::Init()
 7        .Parse(argc, argv);
 8
 9    Reg::Init();
10    Reg::Call(Args::Clean()).Func([](){
11        fs::remove_all(Project::GetBuildDir());
12    })
13
14
15    BigObj obj;
16    Reg::Call().Func(callback_usage_func, BigObj(), obj)
17
18    bool expression = true; // false
19    Reg::Call(expression).Func(callback_usage_func, BigObj(), obj)
20
21    // Example snippets of these given in Target API
22    // Build
23    // Dep
24    // Test
25    // RunBuild
26    // RunTest
27    return 0;
28}