Skip to content

Commit f36a2a6

Browse files
committed
Factor out build_exec()
1 parent 40b6a6a commit f36a2a6

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

nob.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ bool build_and_run_test(Cmd *cmd, const char *test_name)
1919
{
2020
const char *bin_path = temp_sprintf("%s%s", BUILD_FOLDER TESTS_FOLDER, test_name);
2121
const char *src_path = temp_sprintf("%s%s.c", TESTS_FOLDER, test_name);
22-
#ifdef _MSC_VER
23-
cmd_append(cmd, "cl", "-I.", "-o", bin_path, src_path);
24-
#else
25-
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", bin_path, src_path);
26-
#endif // _MSC_VER
27-
if (!cmd_run_sync_and_reset(cmd)) return false;
22+
if (!build_exec(cmd, bin_path, src_path)) return false;
2823
cmd_append(cmd, bin_path);
2924
if (!cmd_run_sync_and_reset(cmd)) return false;
3025
nob_log(INFO, "--- %s finished ---", bin_path);

shared.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77
#define TESTS_FOLDER "tests/"
88
#define TOOLS_FOLDER "tools/"
99

10+
bool build_exec(Cmd *cmd, const char *bin_path, const char *src_path)
11+
{
12+
#ifdef _MSC_VER
13+
cmd_append(cmd, "cl", "-I.", "-o", bin_path, src_path);
14+
#else
15+
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", bin_path, src_path);
16+
#endif // _MSC_VER
17+
return cmd_run_sync_and_reset(cmd);
18+
}
19+
1020
// Tests are allowed to build the tools they may need for their testing
1121
// The tools are single C files residing in TOOLS_FOLDER
1222
bool build_tool(Cmd *cmd, const char *tool_name)
1323
{
1424
const char *tool_src = temp_sprintf("%s%s.c", TOOLS_FOLDER, tool_name);
1525
const char *tool_bin = temp_sprintf("%s%s", BUILD_FOLDER TOOLS_FOLDER, tool_name);
16-
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", tool_bin, tool_src);
17-
if (!cmd_run_sync_and_reset(cmd)) return false;
18-
return true;
26+
return build_exec(cmd, tool_bin, tool_src);
1927
}
2028

2129
#endif // SHARED_H_

0 commit comments

Comments
 (0)