Add delete testing for windows and update "clean"

This commit is contained in:
Christoffer Lerno
2023-10-11 13:05:29 +02:00
committed by Christoffer Lerno
parent b657724d9b
commit db3e9c7ec7
6 changed files with 18 additions and 11 deletions

View File

@@ -45,8 +45,11 @@ jobs:
- name: Build testproject - name: Build testproject
run: | run: |
cd resources/testproject cd resources/testproject
..\..\build\${{ matrix.build_type }}\c3c.exe --debug-log run hello_world_win32 ..\..\build\${{ matrix.build_type }}\c3c.exe --debug-log --emit-llvm run hello_world_win32
dir build\llvm_ir
..\..\build\${{ matrix.build_type }}\c3c.exe clean ..\..\build\${{ matrix.build_type }}\c3c.exe clean
dir build\llvm_ir
- name: Build testproject lib - name: Build testproject lib
run: | run: |

View File

@@ -854,7 +854,7 @@ static void execute_scripts(void)
StringSlice call = slice_next_token(&execs, ' '); StringSlice call = slice_next_token(&execs, ' ');
if (call.len < 3 || call.ptr[call.len - 3] != '.' || call.ptr[call.len - 2] != 'c' || call.ptr[call.len - 2] != '3') if (call.len < 3 || call.ptr[call.len - 3] != '.' || call.ptr[call.len - 2] != 'c' || call.ptr[call.len - 2] != '3')
{ {
(void)execute_cmd(exec); (void) execute_cmd(exec, false);
continue; continue;
} }
scratch_buffer_clear(); scratch_buffer_clear();

View File

@@ -257,11 +257,11 @@ void resolve_libraries(void)
} }
FOREACH_BEGIN(const char *exec, library->execs) FOREACH_BEGIN(const char *exec, library->execs)
printf("] Execute '%s' for library '%s':", exec, library->provides); printf("] Execute '%s' for library '%s':", exec, library->provides);
puts(execute_cmd(exec)); puts(execute_cmd(exec, false));
FOREACH_END(); FOREACH_END();
FOREACH_BEGIN(const char *exec, target->execs) FOREACH_BEGIN(const char *exec, target->execs)
printf("] Execute '%s' for library '%s':", exec, library->provides); printf("] Execute '%s' for library '%s':", exec, library->provides);
puts(execute_cmd(exec)); puts(execute_cmd(exec, false));
FOREACH_END(); FOREACH_END();
} }
} }

View File

@@ -284,7 +284,7 @@ static Decl **sema_run_exec(CompilationUnit *unit, Decl *decl)
} }
else else
{ {
const char *output = execute_cmd(scratch_buffer_to_string()); const char *output = execute_cmd(scratch_buffer_to_string(), false);
file = source_file_text_load(scratch_buffer_to_string(), output); file = source_file_text_load(scratch_buffer_to_string(), output);
} }
if (old_path) if (old_path)

View File

@@ -481,15 +481,15 @@ bool file_delete_file(const char *path)
#endif #endif
} }
bool file_delete_all_files_in_dir_with_suffix(const char *path, const char *suffix) void file_delete_all_files_in_dir_with_suffix(const char *path, const char *suffix)
{ {
assert(path); assert(path);
#if (_MSC_VER) #if (_MSC_VER)
const char *cmd = "del /q \"%s\\*%s\""; const char *cmd = "del /q \"%s\\*%s\" >nul 2>&1";
#else #else
const char *cmd = "rm -f %s/*%s"; const char *cmd = "rm -f %s/*%s";
#endif #endif
return execute_cmd(str_printf(cmd, path, suffix)) == 0; execute_cmd(str_printf(cmd, path, suffix), true);
} }
#if (_MSC_VER) #if (_MSC_VER)
@@ -571,7 +571,7 @@ void file_add_wildcard_files(const char ***files, const char *path, bool recursi
#endif #endif
#define BUFSIZE 1024 #define BUFSIZE 1024
const char *execute_cmd(const char *cmd) const char *execute_cmd(const char *cmd, bool ignore_failure)
{ {
char buffer[BUFSIZE]; char buffer[BUFSIZE];
char *output = ""; char *output = "";
@@ -579,11 +579,13 @@ const char *execute_cmd(const char *cmd)
#if (_MSC_VER) #if (_MSC_VER)
if (!(process = _wpopen(win_utf8to16(cmd), L"r"))) if (!(process = _wpopen(win_utf8to16(cmd), L"r")))
{ {
if (ignore_failure) return "";
error_exit("Failed to open a pipe for command '%s'.", cmd); error_exit("Failed to open a pipe for command '%s'.", cmd);
} }
#else #else
if (!(process = popen(cmd, "r"))) if (!(process = popen(cmd, "r")))
{ {
if (ignore_failure) return "";
error_exit("Failed to open a pipe for command '%s'.", cmd); error_exit("Failed to open a pipe for command '%s'.", cmd);
} }
#endif #endif
@@ -598,6 +600,7 @@ const char *execute_cmd(const char *cmd)
#endif #endif
if (err) if (err)
{ {
if (ignore_failure) return "";
error_exit("Failed to execute '%s'.", cmd); error_exit("Failed to execute '%s'.", cmd);
} }

View File

@@ -72,7 +72,8 @@ bool file_namesplit(const char *path, char** filename_ptr, char** directory_ptr)
const char* file_expand_path(const char* path); const char* file_expand_path(const char* path);
const char* find_lib_dir(void); const char* find_lib_dir(void);
const char *find_rel_exe_dir(const char *dir); const char *find_rel_exe_dir(const char *dir);
bool file_delete_all_files_in_dir_with_suffix(const char *dir, const char *suffix);
void file_delete_all_files_in_dir_with_suffix(const char *dir, const char *suffix);
bool file_delete_file(const char *path); bool file_delete_file(const char *path);
bool file_is_dir(const char *file); bool file_is_dir(const char *file);
bool file_exists(const char *path); bool file_exists(const char *path);
@@ -86,7 +87,7 @@ bool file_has_suffix_in_list(const char *file_name, int name_len, const char **s
void file_add_wildcard_files(const char ***files, const char *path, bool recursive, const char **suffix_list, int suffix_count); void file_add_wildcard_files(const char ***files, const char *path, bool recursive, const char **suffix_list, int suffix_count);
const char *file_append_path(const char *path, const char *name); const char *file_append_path(const char *path, const char *name);
const char *execute_cmd(const char *cmd); const char *execute_cmd(const char *cmd, bool ignore_failure);
bool execute_cmd_failable(const char *cmd, const char **result); bool execute_cmd_failable(const char *cmd, const char **result);
void *cmalloc(size_t size); void *cmalloc(size_t size);
void *ccalloc(size_t size, size_t elements); void *ccalloc(size_t size, size_t elements);