Refactor: command_create_f_to_o() and command_get_profile()
This commit is contained in:
@@ -18,25 +18,8 @@ Command command_create_f_to_o(CommandOptions* co)
|
|||||||
|
|
||||||
size_t len_args = 6;
|
size_t len_args = 6;
|
||||||
|
|
||||||
size_t flag_count = 0;
|
ProfileResult pr = command_get_profile(co);
|
||||||
|
len_args += pr.compiler_flags_count;
|
||||||
StringView* dep_flags_buf = NULL;
|
|
||||||
|
|
||||||
switch(co->bp)
|
|
||||||
{
|
|
||||||
case B_DEBUG:
|
|
||||||
len_args += co->c->debug_compiler_flags_c;
|
|
||||||
flag_count = co->c->debug_compiler_flags_c;
|
|
||||||
dep_flags_buf = co->c->debug_compiler_flags;
|
|
||||||
break;
|
|
||||||
case B_PROD:
|
|
||||||
len_args += co->c->prod_compiler_flags_c;
|
|
||||||
flag_count = co->c->prod_compiler_flags_c;
|
|
||||||
dep_flags_buf = co->c->prod_compiler_flags;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DIE("No configuration was selected!");
|
|
||||||
}
|
|
||||||
|
|
||||||
const char** args_buf = (const char**)arena_alloc(co->a, sizeof(const char*) * len_args);
|
const char** args_buf = (const char**)arena_alloc(co->a, sizeof(const char*) * len_args);
|
||||||
args_buf[0] = co->app.buf;
|
args_buf[0] = co->app.buf;
|
||||||
@@ -49,9 +32,9 @@ Command command_create_f_to_o(CommandOptions* co)
|
|||||||
args_buf[4] = f_o.buf;
|
args_buf[4] = f_o.buf;
|
||||||
args_buf[5] = "-MMD";
|
args_buf[5] = "-MMD";
|
||||||
|
|
||||||
for (size_t i = 0; i < flag_count; i++)
|
for (size_t i = 0; i < pr.compiler_flags_count; i++)
|
||||||
{
|
{
|
||||||
args_buf[i + 5] = dep_flags_buf[i].buf;
|
args_buf[i + 5] = pr.compiler_flags_buf[i].buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
args_buf[len_args] = NULL;
|
args_buf[len_args] = NULL;
|
||||||
@@ -61,6 +44,25 @@ Command command_create_f_to_o(CommandOptions* co)
|
|||||||
return (Command){.a = co->a, .app = co->app, .args = args_buf};
|
return (Command){.a = co->a, .app = co->app, .args = args_buf};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProfileResult command_get_profile(CommandOptions* co)
|
||||||
|
{
|
||||||
|
ProfileResult pr;
|
||||||
|
switch(co->bp)
|
||||||
|
{
|
||||||
|
case B_DEBUG:
|
||||||
|
pr.compiler_flags_count = co->c->debug_compiler_flags_c;
|
||||||
|
pr.compiler_flags_buf = co->c->debug_compiler_flags;
|
||||||
|
break;
|
||||||
|
case B_PROD:
|
||||||
|
pr.compiler_flags_count = co->c->prod_compiler_flags_c;
|
||||||
|
pr.compiler_flags_buf = co->c->prod_compiler_flags;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DIE("No configuration was selected!");
|
||||||
|
}
|
||||||
|
return pr;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Add input sanitization to cmd->app and cmd->args
|
// TODO: Add input sanitization to cmd->app and cmd->args
|
||||||
int command_run(Command* cmd)
|
int command_run(Command* cmd)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ struct CommandOptions
|
|||||||
StringView* files;
|
StringView* files;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ProfileResult
|
||||||
|
{
|
||||||
|
size_t compiler_flags_count;
|
||||||
|
StringView* compiler_flags_buf;
|
||||||
|
};
|
||||||
|
|
||||||
struct Command
|
struct Command
|
||||||
{
|
{
|
||||||
Arena* a;
|
Arena* a;
|
||||||
@@ -28,8 +34,10 @@ struct Command
|
|||||||
typedef struct Argument Argument;
|
typedef struct Argument Argument;
|
||||||
typedef struct Command Command;
|
typedef struct Command Command;
|
||||||
typedef struct CommandOptions CommandOptions;
|
typedef struct CommandOptions CommandOptions;
|
||||||
|
typedef struct ProfileResult ProfileResult;
|
||||||
|
|
||||||
Command command_create_f_to_o(CommandOptions* co);
|
Command command_create_f_to_o(CommandOptions* co);
|
||||||
|
ProfileResult command_get_profile(CommandOptions* co);
|
||||||
|
|
||||||
int command_run(Command* cmd);
|
int command_run(Command* cmd);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user