From 96943ca66f5b6c738fa5b23f7329cec30565c323 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 26 Feb 2025 02:35:28 +0100 Subject: [PATCH] Check exe and lib output so -o works with directories. Removed construct forms from Maybe. --- lib7/std/collections/maybe.c3 | 10 ---------- releasenotes.md | 1 + src/compiler/compiler.c | 16 ++++++++++++++++ src/utils/file_utils.c | 9 ++++++++- src/utils/lib.h | 1 + 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib7/std/collections/maybe.c3 b/lib7/std/collections/maybe.c3 index c5854e8da..dd5dea31f 100644 --- a/lib7/std/collections/maybe.c3 +++ b/lib7/std/collections/maybe.c3 @@ -28,16 +28,6 @@ fn Maybe value(Type val) return { .value = val, .has_value = true }; } -fn Maybe Maybe.with_value(Type val) @operator(construct) -{ - return { .value = val, .has_value = true }; -} - -fn Maybe Maybe.empty() @operator(construct) -{ - return { }; -} - const Maybe EMPTY = { }; macro Type! Maybe.get(self) diff --git a/releasenotes.md b/releasenotes.md index 41daf19c4..6aee5fe62 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -28,6 +28,7 @@ - Several fixes for .o files and -o output, improving handling and naming. - Fix bug casting bool to int to other int #1995. - `@if` declarations were missing from -P output #1973. +- Check exe and lib output so -o works with directories. ### Stdlib changes diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 82e5e615d..1100bbac1 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -658,6 +658,12 @@ void compiler_compile(void) create_output_dir(compiler.build.output_dir); output_exe = file_append_path(compiler.build.output_dir, output_exe); } + char *dir_path = file_get_dir(output_exe); + if (dir_path && strlen(dir_path) && !file_is_dir(dir_path)) + { + error_exit("Can't create '%s', the directory '%s' could not be found.", output_exe, dir_path); + } + if (file_is_dir(output_exe)) { error_exit("Cannot create exe with the name '%s' - there is already a directory with that name.", output_exe); @@ -757,6 +763,11 @@ void compiler_compile(void) create_output_dir(compiler.build.output_dir); output_static = file_append_path(compiler.build.output_dir, output_static); } + char *dir_path = file_get_dir(output_static); + if (dir_path && strlen(dir_path) && !file_is_dir(dir_path)) + { + error_exit("Can't create '%s', the directory '%s' could not be found.", output_static, dir_path); + } if (file_is_dir(output_static)) { error_exit("Cannot create a static library with the name '%s' - there is already a directory with that name.", output_exe); @@ -777,6 +788,11 @@ void compiler_compile(void) create_output_dir(compiler.build.output_dir); output_dynamic = file_append_path(compiler.build.output_dir, output_dynamic); } + char *dir_path = file_get_dir(output_dynamic); + if (dir_path && strlen(dir_path) && !file_is_dir(dir_path)) + { + error_exit("Can't create '%s', the directory '%s' could not be found.", output_dynamic, dir_path); + } if (file_is_dir(output_dynamic)) { error_exit("Cannot create a dynamic library with the name '%s' - there is already a directory with that name.", output_exe); diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index 295006963..7aef7e12e 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -169,7 +169,7 @@ bool file_namesplit(const char *path, char** filename_ptr, char** directory_ptr) if (file_len == 1 && path[0] == '.') return false; if (file_len == 2 && path[0] == '.' && path[1] == '.') return false; if (!file_len) return false; - *filename_ptr = str_copy(&path[len - file_len], file_len); + if (filename_ptr) *filename_ptr = str_copy(&path[len - file_len], file_len); if (!directory_ptr) return true; if (file_len < len) { @@ -422,6 +422,13 @@ DONE:; return lib_path; } +char *file_get_dir(const char *full_path) +{ + char *dir = NULL; + file_get_dir_and_filename_from_full(full_path, NULL, &dir); + return dir; +} + void file_get_dir_and_filename_from_full(const char *full_path, char **filename, char **dir_path) { if (!file_namesplit(full_path, filename, dir_path)) diff --git a/src/utils/lib.h b/src/utils/lib.h index e834a6a43..08ce69288 100644 --- a/src/utils/lib.h +++ b/src/utils/lib.h @@ -83,6 +83,7 @@ bool file_touch(const char *path); char *file_read_binary(const char *path, size_t *size); char *file_read_all(const char *path, size_t *return_size); size_t file_clean_buffer(char *buffer, const char *path, size_t file_size); +char *file_get_dir(const char *full_path); void file_get_dir_and_filename_from_full(const char *full_path, char **filename, char **dir_path); void file_find_top_dir(); bool file_has_suffix_in_list(const char *file_name, int name_len, const char **suffix_list, int suffix_count);