1
1
#define NOBUILD_IMPLEMENTATION
2
2
#include " ./nob.h"
3
3
4
- #include < cassert>
4
+ #include < array>
5
+ #include < cstdlib>
5
6
#include < filesystem>
6
7
#include < queue>
7
8
#include < string_view>
8
9
#include < vector>
9
10
10
- #define CFLAGS " -Wall " , " -Wextra " , " -std=c2x " , " -pedantic"
11
- #define CPPFLAGS " -Wall" , " -Wextra " , " -std=c++23 " , " -pedantic" , " -Wconversion "
11
+ #define CFLAGS " -std=c2x " , " -Wall " , " -Wextra " , " -pedantic"
12
+ #define CPPFLAGS " -std=c++23 " , " - Wall" , " -Wconversion " , " -Wextra " , " -pedantic" , " -fsanitize=address,pointer-overflow,signed-integer-overflow,undefined "
12
13
13
14
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
14
15
16
+
17
+ #define MAKE_CMD (...) \
18
+ ({Cmd cmd = { \
19
+ .line = cstr_array_make (__VA_ARGS__, NULL ) \
20
+ }; \
21
+ Cstr cmd_to_show = cmd_show (cmd); \
22
+ INFO (" MAKE_CMD: %s" , cmd_to_show); \
23
+ std::free (reinterpret_cast <void *>( \
24
+ const_cast <char *>(cmd_to_show))); \
25
+ cmd;}) \
26
+
27
+
15
28
namespace fs = std::filesystem;
16
29
17
30
using namespace std ::string_literals; // for operator""s
18
31
using namespace std ::literals; // for operator""sv
19
32
20
- void build_kattis_c_file (std::string_view filename) {
21
- Cstr path = PATH (" kattis" , filename.data ());
22
- CMD (" cc" , CFLAGS, " -o" , NOEXT (path), path);
33
+ void build_kattis_c_file (std::string_view path) {
34
+ Cstr noextpath = NOEXT (path.data ());
35
+ CMD (" cc" , CFLAGS, " -o" , noextpath, path.data ());
36
+ std::free (reinterpret_cast <void *>(const_cast <char *>(noextpath))); // :-O
23
37
}
24
38
25
39
void build_kattis_c_files () {
26
40
for (auto const & entry : fs::directory_iterator (" kattis" ))
27
41
if (fs::is_regular_file (entry.path ())) {
28
- auto const filename = entry.path ().filename ().string ();
29
- if (filename.ends_with (" .c" ))
30
- build_kattis_c_file (filename);
42
+ const std::string& path = entry.path ().string ();
43
+ if (path.ends_with (" .c" )) build_kattis_c_file (path);
31
44
}
32
45
}
33
46
@@ -45,10 +58,21 @@ void build_custom_cpp_files() {
45
58
}
46
59
}
47
60
61
+ template <size_t N>
62
+ void make_and_run_cmd (std::array<Cstr, N> strings)
63
+ {
64
+ Cmd cmd;
65
+ cmd.line .count = strings.size ();
66
+ cmd.line .elems = strings.data ();
67
+ // TODO FIX leaks.
68
+ INFO (" make_and_run_cmd: %s" , cmd_show (cmd));
69
+ cmd_run_sync (cmd);
70
+ }
71
+
48
72
void build_cpp_file (std::string_view filename)
49
73
{
50
74
Cstr path = PATH (filename.data ());
51
- CMD ( " g++" , CPPFLAGS, " -o" , NOEXT (path), path);
75
+ make_and_run_cmd (std::array{ " g++" , CPPFLAGS, " -o" , NOEXT (path), path} );
52
76
}
53
77
54
78
void build_and_run_gtest_file (std::string_view filename)
@@ -58,10 +82,14 @@ void build_and_run_gtest_file(std::string_view filename)
58
82
CMD (NOEXT (path));
59
83
}
60
84
61
- Pid build_gtest_file_async (std::string_view filename )
85
+ Pid build_gtest_file_async (std::string_view path )
62
86
{
63
- Cstr path = PATH (filename.data ());
64
- return cmd_run_async (MAKE_CMD (" g++" , CPPFLAGS, " -o" , NOEXT (path), path, " -lgtest" ), NULL , NULL );
87
+ Cstr noextpath = NOEXT (path.data ());
88
+ Cmd cmd = MAKE_CMD (" g++" , CPPFLAGS, " -o" , noextpath, path.data (), " -lgtest" );
89
+ Pid pid = cmd_run_async (cmd, NULL , NULL );
90
+ std::free (reinterpret_cast <void *>(const_cast <char **>(cmd.line .elems )));
91
+ std::free (reinterpret_cast <void *>(const_cast <char *>(noextpath))); // :-O
92
+ return pid;
65
93
}
66
94
67
95
Pid run_gtest_file_async (std::string_view filename)
@@ -143,7 +171,7 @@ int main(int argc, char* argv[])
143
171
{
144
172
GO_REBUILD_URSELF (argc, argv);
145
173
146
- // build_kattis_c_files();
174
+ build_kattis_c_files ();
147
175
// build_custom_cpp_files();
148
176
// build_directory_cpp_files("adventofcode");
149
177
// build_codeforces_cpp_files();
0 commit comments