diff --git a/build.cpp b/bld_file.cpp similarity index 100% rename from build.cpp rename to bld_file.cpp diff --git a/bld_lib.cpp b/bld_lib.cpp index 3ecdd00..1079e36 100644 --- a/bld_lib.cpp +++ b/bld_lib.cpp @@ -259,8 +259,8 @@ int Run(Strs s) { } #ifndef BLD_MAIN +int Main(); int main() { - int Main(); SRC_InitCache(Perm, S8_Lit("buildfile.cache")); int result = Main(); if (result == 0) SRC_SaveCache(); diff --git a/bld_main.cpp b/bld_main.cpp index 20cd29b..798d31d 100644 --- a/bld_main.cpp +++ b/bld_main.cpp @@ -6,6 +6,14 @@ int main(int argument_count, char **arguments) { OS_SetWorkingDir(S8_Lit("build")); IO_Printf("WORKING DIR: %Q\n", OS_GetWorkingDir(Perm)); +#if OS_LINUX + S8_String cc = "gcc"_s; +#elif OS_WINDOWS + S8_String cc = "cl"_s; +#else + S8_String cc = "clang"_s; +#endif + for (int i = 1; i < argument_count; i += 1) { S8_String arg = S8_MakeFromChar(arguments[i]); if (arg == "clear_cache"_s) OS_DeleteFile("bld.cache"_s); @@ -18,7 +26,7 @@ int main(int argument_count, char **arguments) { { S8_List files_current_dir = OS_ListDir(Perm, S8_Lit(".."), 0); for (S8_Node *it = files_current_dir.first; it; it = it->next) { - if (S8_Find(it->string, S8_Lit("build.c"), S8_IGNORE_CASE, 0)) { + if (S8_Find(it->string, S8_Lit("bld_file.c"), S8_IGNORE_CASE, 0)) { build_file = it->string; } } @@ -37,8 +45,18 @@ int main(int argument_count, char **arguments) { // Compile the build file only if code changed if (SRC_WasModified(build_file)) { double time = OS_GetTime(); - S8_String f = S8_Lit("-WX -W3 -wd4200 -diagnostics:column -nologo -Zi"); - int result = OS_SystemF("cl %Q %Q -Fe:%Q ", build_file, f, exe_name); + int result = 0; + if (cc == "cl"_s) { + result = OS_SystemF("cl %Q -Fe:%Q -WX -W3 -wd4200 -diagnostics:column -nologo -Zi", build_file, exe_name); + } + else if (cc == "clang"_s) { + result = OS_SystemF("clang -Wno-writable-strings %Q -o %Q -g", build_file, exe_name); + } + else { + IO_Assert(cc == "gcc"_s); + result = OS_SystemF("gcc -Wno-write-strings %Q -o %Q -g", build_file, exe_name); + } + if (result != 0) { IO_Printf("FAILED compilation of the build file!\n"); return result; @@ -50,7 +68,11 @@ int main(int argument_count, char **arguments) { // Run the build file double time = OS_GetTime(); if (build_file.str) { +#if OS_WINDOWS int result = OS_SystemF("%.*s", S8_Expand(exe_name)); +#else + int result = OS_SystemF("./%.*s", S8_Expand(exe_name)); +#endif if (result != 0) { printf("FAILED execution of the build file!\n"); return result; diff --git a/build.sh b/build.sh index 2be6354..5f29ccf 100644 --- a/build.sh +++ b/build.sh @@ -2,15 +2,17 @@ mkdir build cd build set -e - -gcc -o test_filesystem ../test/test_filesystem.c -Wno-write-strings -./test_filesystem -gcc -o test_array ../test/test_array.cpp -fno-exceptions -fno-rtti -Wno-write-strings -./test_array -gcc -o test_table ../test/test_table.cpp -fno-exceptions -fno-rtti -Wno-write-strings -./test_table -gcc -o compile_as_c ../test/main.c -./compile_as_c +gcc -o bld ../bld_main.cpp -fno-exceptions -fno-rtti -Wno-write-strings +cd .. +./build/bld +# gcc -o test_filesystem ../test/test_filesystem.c -Wno-write-strings +# ./test_filesystem +# gcc -o test_array ../test/test_array.cpp -fno-exceptions -fno-rtti -Wno-write-strings +# ./test_array +# gcc -o test_table ../test/test_table.cpp -fno-exceptions -fno-rtti -Wno-write-strings +# ./test_table +# gcc -o compile_as_c ../test/main.c +# ./compile_as_c #-Wno-writable-strings cd .. \ No newline at end of file diff --git a/filesystem.c b/filesystem.c index 1ef0b90..c5a1d65 100644 --- a/filesystem.c +++ b/filesystem.c @@ -414,44 +414,59 @@ OS_API S8_String OS_GetWorkingDir(MA_Arena *arena) { } OS_API void OS_SetWorkingDir(S8_String path) { - IO_Assert(path.str[path.len] == 0); - chdir(path.str); + MA_Checkpoint scratch = MA_GetScratch(); + S8_String copy = S8_Copy(scratch.arena, path); + chdir(copy.str); + MA_ReleaseScratch(scratch); } OS_API S8_String OS_GetAbsolutePath(MA_Arena *arena, S8_String relative) { - IO_Assert(relative.str[relative.len] == 0); + MA_Checkpoint scratch = MA_GetScratch1(arena); + S8_String copy = S8_Copy(scratch.arena, relative); char *buffer = (char *)MA_PushSizeNonZeroed(arena, PATH_MAX); - realpath((char *)relative.str, buffer); + realpath((char *)copy.str, buffer); S8_String result = S8_MakeFromChar(buffer); + + MA_ReleaseScratch(scratch); return result; } OS_API bool OS_FileExists(S8_String path) { - IO_Assert(path.str[path.len] == 0); + MA_Checkpoint scratch = MA_GetScratch(); + S8_String copy = S8_Copy(scratch.arena, path); bool result = false; - if (access((char *)path.str, F_OK) == 0) { + if (access((char *)copy.str, F_OK) == 0) { result = true; } + + MA_ReleaseScratch(scratch); return result; } OS_API bool OS_IsDir(S8_String path) { - IO_Assert(path.str[path.len] == 0); + MA_Checkpoint scratch = MA_GetScratch(); + S8_String copy = S8_Copy(scratch.arena, path); + struct stat s; - if (stat(path.str, &s) != 0) + if (stat(copy.str, &s) != 0) return false; + bool result = S_ISDIR(s.st_mode); + MA_ReleaseScratch(scratch); return result; } OS_API bool OS_IsFile(S8_String path) { - IO_Assert(path.str[path.len] == 0); + MA_Checkpoint scratch = MA_GetScratch(); + S8_String copy = S8_Copy(scratch.arena, path); + struct stat s; - if (stat(path.str, &s) != 0) + if (stat(copy.str, &s) != 0) return false; bool result = S_ISREG(s.st_mode); + MA_ReleaseScratch(scratch); return result; } @@ -466,7 +481,8 @@ OS_API double OS_GetTime(void) { OS_API S8_List OS_ListDir(MA_Arena *arena, S8_String path, unsigned flags) { IO_Assert((flags & OS_RECURSIVE) == 0); - IO_Assert(path.str[path.len] == 0); + MA_Checkpoint scratch = MA_GetScratch1(arena); + path = S8_Copy(scratch.arena, path); S8_List result = {0}; struct dirent *dir = 0; @@ -483,25 +499,28 @@ OS_API S8_List OS_ListDir(MA_Arena *arena, S8_String path, unsigned flags) { continue; } - S8_String n = S8_Format(arena, "%Q/%s", path, dir->d_name); + S8_String n = S8_Format(scratch.arena, "%Q/%s", path, dir->d_name); if ((flags & OS_RELATIVE_PATHS) == 0) { - n = OS_GetAbsolutePath(arena, n); + n = OS_GetAbsolutePath(scratch.arena, n); } if (dir->d_type == DT_DIR) { - n = S8_Format(arena, "%Q/", n); + n = S8_Format(scratch.arena, "%Q/", n); } - S8_AddNode(arena, &result, n); + S8_AddNode(arena, &result, S8_Copy(arena, n)); } closedir(d); } + MA_ReleaseScratch(scratch); return result; } OS_API OS_Result OS_MakeDir(S8_String path) { - IO_Assert(path.str[path.len]); + MA_Checkpoint scratch = MA_GetScratch(); + path = S8_Copy(scratch.arena, path); int error = mkdir(path.str, 0755); + MA_ReleaseScratch(scratch); return error == 0 ? OS_SUCCESS : OS_FAILURE; } @@ -523,12 +542,15 @@ OS_API OS_Result OS_DeleteDir(S8_String path, unsigned flags) { } OS_API int64_t OS_GetFileModTime(S8_String file) { - IO_Assert(file.str[file.len] == 0); + MA_Checkpoint scratch = MA_GetScratch(); + file = S8_Copy(scratch.arena, file); struct stat attrib = {}; stat(file.str, &attrib); struct timespec ts = attrib.st_mtim; int64_t result = (((int64_t)ts.tv_sec) * 1000000ll) + ((int64_t)ts.tv_nsec) / 1000ll; + + MA_ReleaseScratch(scratch); return result; } @@ -538,7 +560,8 @@ OS_API OS_Date OS_GetDate(void) { } OS_API OS_Result OS_AppendFile(S8_String path, S8_String string) { - IO_Assert(path.str[path.len] == 0); + MA_Checkpoint scratch = MA_GetScratch(); + path = S8_Copy(scratch.arena, path); OS_Result result = OS_FAILURE; FILE *f = fopen((const char *)path.str, "a"); @@ -555,11 +578,14 @@ OS_API OS_Result OS_AppendFile(S8_String path, S8_String string) { result = OS_FAILURE; } } + + MA_ReleaseScratch(scratch); return result; } OS_API S8_String OS_ReadFile(MA_Arena *arena, S8_String path) { - IO_Assert(path.str[path.len] == 0); + MA_Checkpoint scratch = MA_GetScratch1(arena); + path = S8_Copy(scratch.arena, path); S8_String result = {}; FILE *f = fopen(path.str, "rb"); @@ -574,6 +600,8 @@ OS_API S8_String OS_ReadFile(MA_Arena *arena, S8_String path) { fclose(f); } + + MA_ReleaseScratch(scratch); return result; } @@ -598,7 +626,8 @@ OS_API OS_Result OS_WriteFile(S8_String path, S8_String string) { } #else OS_API OS_Result OS_WriteFile(S8_String path, S8_String string) { - IO_Assert(path.str[path.len] == 0); + MA_Checkpoint scratch = MA_GetScratch(); + path = S8_Copy(scratch.arena, path); OS_Result result = OS_FAILURE; FILE *f = fopen((const char *)path.str, "w"); @@ -615,6 +644,8 @@ OS_API OS_Result OS_WriteFile(S8_String path, S8_String string) { result = OS_FAILURE; } } + + MA_ReleaseScratch(scratch); return result; } #endif diff --git a/test/test_arena.cpp b/test/test_arena.cpp index b061d13..5e89c90 100644 --- a/test/test_arena.cpp +++ b/test/test_arena.cpp @@ -71,9 +71,11 @@ void TestBootstrapExclusive() { } int main() { + IO_Printf("test_arena.cpp - "); TestScratch(); TestBuffer(); TestCreateAllocate(); TestBootstrap(); TestBootstrapExclusive(); + IO_Printf("DONE\n"); } \ No newline at end of file diff --git a/test/test_array.cpp b/test/test_array.cpp index 5632728..d2cf480 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -117,11 +117,13 @@ void TestCopy() { } int main() { + IO_Printf("test_array.cpp - "); TestExclusiveArenaBackedArray(); TestRemoveForLoop(); TestBasic(); TestReverseLoop(); TestCopy(); + IO_Printf("DONE\n"); return 0; } \ No newline at end of file diff --git a/test/test_filesystem.c b/test/test_filesystem.c index f89520f..fbbc9e0 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -1,6 +1,7 @@ #include "../core.c" int main() { + IO_Printf("test_filesystem.c - "); MA_Arena arena = {}; S8_String read_file_path = S8_Lit("../test/data/read_file"); @@ -102,4 +103,5 @@ int main() { } } } + IO_Printf("DONE\n"); } \ No newline at end of file diff --git a/test/test_table.cpp b/test/test_table.cpp index 9ae6d22..2b67cf5 100644 --- a/test/test_table.cpp +++ b/test/test_table.cpp @@ -37,7 +37,9 @@ void TestStrings() { } int main() { + IO_Printf("test_table.cpp - "); TestSimpleInsertAndIntegrity(); TestStrings(); + IO_Printf("DONE\n"); return 0; } \ No newline at end of file