Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete testing for windows and update "clean" #1043

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ jobs:
- name: Build testproject
run: |
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
dir build\llvm_ir


- name: Build testproject lib
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ static void execute_scripts(void)
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')
{
(void)execute_cmd(exec);
(void) execute_cmd(exec, false);
continue;
}
scratch_buffer_clear();
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/libraries.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ void resolve_libraries(void)
}
FOREACH_BEGIN(const char *exec, library->execs)
printf("] Execute '%s' for library '%s':", exec, library->provides);
puts(execute_cmd(exec));
puts(execute_cmd(exec, false));
FOREACH_END();
FOREACH_BEGIN(const char *exec, target->execs)
printf("] Execute '%s' for library '%s':", exec, library->provides);
puts(execute_cmd(exec));
puts(execute_cmd(exec, false));
FOREACH_END();
}
}
2 changes: 1 addition & 1 deletion src/compiler/sema_passes.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static Decl **sema_run_exec(CompilationUnit *unit, Decl *decl)
}
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);
}
if (old_path)
Expand Down
11 changes: 7 additions & 4 deletions src/utils/file_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,15 @@ bool file_delete_file(const char *path)
#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);
#if (_MSC_VER)
const char *cmd = "del /q \"%s\\*%s\"";
const char *cmd = "del /q \"%s\\*%s\" >nul 2>&1";
#else
const char *cmd = "rm -f %s/*%s";
#endif
return execute_cmd(str_printf(cmd, path, suffix)) == 0;
execute_cmd(str_printf(cmd, path, suffix), true);
}

#if (_MSC_VER)
Expand Down Expand Up @@ -571,19 +571,21 @@ void file_add_wildcard_files(const char ***files, const char *path, bool recursi
#endif

#define BUFSIZE 1024
const char *execute_cmd(const char *cmd)
const char *execute_cmd(const char *cmd, bool ignore_failure)
{
char buffer[BUFSIZE];
char *output = "";
FILE *process = NULL;
#if (_MSC_VER)
if (!(process = _wpopen(win_utf8to16(cmd), L"r")))
{
if (ignore_failure) return "";
error_exit("Failed to open a pipe for command '%s'.", cmd);
}
#else
if (!(process = popen(cmd, "r")))
{
if (ignore_failure) return "";
error_exit("Failed to open a pipe for command '%s'.", cmd);
}
#endif
Expand All @@ -598,6 +600,7 @@ const char *execute_cmd(const char *cmd)
#endif
if (err)
{
if (ignore_failure) return "";
error_exit("Failed to execute '%s'.", cmd);
}

Expand Down
5 changes: 3 additions & 2 deletions src/utils/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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* find_lib_dir(void);
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_is_dir(const char *file);
bool file_exists(const char *path);
Expand All @@ -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);
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);
void *cmalloc(size_t size);
void *ccalloc(size_t size, size_t elements);
Expand Down