bug fixes with path issues
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Mar 2022 03:23:21 +0000 (22:23 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Mar 2022 03:23:21 +0000 (22:23 -0500)
build.sh
include/bh.h
src/onyx.c
src/wasm_runtime.c

index e3a63e0148cca0aaee84987c73057344a8ae4284..03687aafff1d38a5323daf82a80fa09643da8ad4 100755 (executable)
--- 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"
index edcdbff9a505bcad1fac30c8f90dbbeccebd02d1..5bff4408ae5e0060051e2e03ae6e584858d9d36c 100644 (file)
@@ -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
index 7863d7446b36b9daf0d462435ed127c12740c710..2c0e2fb3bf848ea2533b851cd9e15ec782e2a701 100644 (file)
@@ -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;
index f760085e86fed5a86ec8b0596f68f2d0d2608c71..c07babf85cf73391269d74b9083c2ca6025f5c55 100644 (file)
@@ -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);