From 055e0bf701211efaf95f169ea282fb1adab005cd Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 13 Mar 2022 22:23:21 -0500 Subject: [PATCH] bug fixes with path issues --- build.sh | 7 +++++-- include/bh.h | 21 +++++++++++++++++++++ src/onyx.c | 2 ++ src/wasm_runtime.c | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index e3a63e01..03687aaf 100755 --- a/build.sh +++ b/build.sh @@ -1,10 +1,12 @@ #!/bin/sh +INSTALL_DIR="/usr" + # Where the core libraries for Onyx will go. -CORE_DIR='/usr/share/onyx' +CORE_DIR="$INSTALL_DIR/share/onyx" # Where the onyx executable will be placed. -BIN_DIR='/usr/bin' +BIN_DIR="$INSTALL_DIR/bin" ARCH="$(uname -m)" @@ -72,6 +74,7 @@ compile() { compile echo "Installing onyx executable" +sudo mkdir -p "$BIN_DIR" sudo cp ./bin/onyx "$BIN_DIR/onyx" C_FILES="onyxrun wasm_runtime" diff --git a/include/bh.h b/include/bh.h index edcdbff9..5bff4408 100644 --- a/include/bh.h +++ b/include/bh.h @@ -379,6 +379,7 @@ i64 bh_file_size(bh_file* file); b32 bh_file_exists(char const* filename); char* bh_path_get_full_name(char const* filename, bh_allocator a); char* bh_path_get_parent(char const* filename, bh_allocator a); +char* bh_path_convert_separators(char* path); // This function returns a volatile pointer. Do not store it without copying! // `included_folders` is bh_arr(const char *). @@ -1717,6 +1718,26 @@ char* bh_lookup_file(char* filename, char* relative_to, char *suffix, b32 add_su return fn; } +// +// Modifies the path in-place. +char* bh_path_convert_separators(char* path) { +#if defined(_BH_LINUX) + #define DIR_SEPARATOR '/' + #define OTHER_SEPARATOR '\\' +#elif defined(_BH_WINDOWS) + #define DIR_SEPARATOR '\\' + #define OTHER_SEPARATOR '/' +#endif + + fori (i, 0, (i64) strlen(path)) { + if (path[i] == OTHER_SEPARATOR) { + path[i] = DIR_SEPARATOR; + } + } + + return path; +} + bh_dir bh_dir_open(char* path) { #ifdef _BH_WINDOWS diff --git a/src/onyx.c b/src/onyx.c index 7863d744..2c0e2fb3 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -353,6 +353,7 @@ static b32 process_load_entity(Entity* ent) { // This does not take into account #load_path'd folders... + bh_path_convert_separators(folder); bh_dir dir = bh_dir_open(folder); if (dir == NULL) { onyx_report_error(include->token->pos, Error_Critical, "Could not find folder '%s'.", folder); @@ -365,6 +366,7 @@ static b32 process_load_entity(Entity* ent) { while (bh_dir_read(dir, &entry)) { if (entry.type == BH_DIRENT_FILE && bh_str_ends_with(entry.name, ".onyx")) { bh_snprintf(fullpath, 511, "%s/%s", folder, entry.name); + bh_path_convert_separators(fullpath); u8* formatted_name = bh_path_get_full_name(fullpath, global_heap_allocator); success = process_source_file(formatted_name, include->token->pos); if (!success) break; diff --git a/src/wasm_runtime.c b/src/wasm_runtime.c index f760085e..c07babf8 100644 --- a/src/wasm_runtime.c +++ b/src/wasm_runtime.c @@ -140,6 +140,7 @@ static void onyx_lookup_and_load_custom_libraries(bh_buffer wasm_bytes) { char *lib_path = malloc(lib_path_length); strncpy(lib_path, wasm_bytes.data + cursor, lib_path_length); lib_path[lib_path_length] = '\0'; + bh_path_convert_separators(lib_path); cursor += lib_path_length; bh_arr_push(library_paths, lib_path); -- 2.25.1