mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Improve error handling for missing library collection provided by the compiler
This commit is contained in:
+16
-10
@@ -876,7 +876,7 @@ gb_internal String internal_odin_root_dir(void) {
|
|||||||
|
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
|
|
||||||
gb_internal String path_to_fullpath(gbAllocator a, String s);
|
gb_internal String path_to_fullpath(gbAllocator a, String s, bool *ok_);
|
||||||
|
|
||||||
gb_internal String internal_odin_root_dir(void) {
|
gb_internal String internal_odin_root_dir(void) {
|
||||||
String path = global_module_path;
|
String path = global_module_path;
|
||||||
@@ -930,7 +930,7 @@ gb_internal String internal_odin_root_dir(void) {
|
|||||||
// NOTE: Linux / Unix is unfinished and not tested very well.
|
// NOTE: Linux / Unix is unfinished and not tested very well.
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
gb_internal String path_to_fullpath(gbAllocator a, String s);
|
gb_internal String path_to_fullpath(gbAllocator a, String s, bool *ok_);
|
||||||
|
|
||||||
gb_internal String internal_odin_root_dir(void) {
|
gb_internal String internal_odin_root_dir(void) {
|
||||||
String path = global_module_path;
|
String path = global_module_path;
|
||||||
@@ -1091,7 +1091,7 @@ gb_internal String internal_odin_root_dir(void) {
|
|||||||
gb_global BlockingMutex fullpath_mutex;
|
gb_global BlockingMutex fullpath_mutex;
|
||||||
|
|
||||||
#if defined(GB_SYSTEM_WINDOWS)
|
#if defined(GB_SYSTEM_WINDOWS)
|
||||||
gb_internal String path_to_fullpath(gbAllocator a, String s) {
|
gb_internal String path_to_fullpath(gbAllocator a, String s, bool *ok_) {
|
||||||
String result = {};
|
String result = {};
|
||||||
|
|
||||||
String16 string16 = string_to_string16(heap_allocator(), s);
|
String16 string16 = string_to_string16(heap_allocator(), s);
|
||||||
@@ -1117,7 +1117,9 @@ gb_internal String path_to_fullpath(gbAllocator a, String s) {
|
|||||||
result.text[i] = '/';
|
result.text[i] = '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ok_) *ok_ = true;
|
||||||
} else {
|
} else {
|
||||||
|
if (ok_) *ok_ = false;
|
||||||
mutex_unlock(&fullpath_mutex);
|
mutex_unlock(&fullpath_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1129,7 +1131,11 @@ gb_internal String path_to_fullpath(gbAllocator a, String s) {
|
|||||||
mutex_lock(&fullpath_mutex);
|
mutex_lock(&fullpath_mutex);
|
||||||
p = realpath(cast(char *)s.text, 0);
|
p = realpath(cast(char *)s.text, 0);
|
||||||
mutex_unlock(&fullpath_mutex);
|
mutex_unlock(&fullpath_mutex);
|
||||||
if(p == nullptr) return String{};
|
if(p == nullptr) {
|
||||||
|
if (ok_) *ok_ = false;
|
||||||
|
return String{};
|
||||||
|
}
|
||||||
|
if (ok_) *ok_ = true;
|
||||||
return make_string_c(p);
|
return make_string_c(p);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -1137,7 +1143,7 @@ gb_internal String path_to_fullpath(gbAllocator a, String s) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
gb_internal String get_fullpath_relative(gbAllocator a, String base_dir, String path) {
|
gb_internal String get_fullpath_relative(gbAllocator a, String base_dir, String path, bool *ok_) {
|
||||||
u8 *str = gb_alloc_array(heap_allocator(), u8, base_dir.len+1+path.len+1);
|
u8 *str = gb_alloc_array(heap_allocator(), u8, base_dir.len+1+path.len+1);
|
||||||
defer (gb_free(heap_allocator(), str));
|
defer (gb_free(heap_allocator(), str));
|
||||||
|
|
||||||
@@ -1159,11 +1165,11 @@ gb_internal String get_fullpath_relative(gbAllocator a, String base_dir, String
|
|||||||
|
|
||||||
String res = make_string(str, i);
|
String res = make_string(str, i);
|
||||||
res = string_trim_whitespace(res);
|
res = string_trim_whitespace(res);
|
||||||
return path_to_fullpath(a, res);
|
return path_to_fullpath(a, res, ok_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gb_internal String get_fullpath_base_collection(gbAllocator a, String path) {
|
gb_internal String get_fullpath_base_collection(gbAllocator a, String path, bool *ok_) {
|
||||||
String module_dir = odin_root_dir();
|
String module_dir = odin_root_dir();
|
||||||
|
|
||||||
String base = str_lit("base/");
|
String base = str_lit("base/");
|
||||||
@@ -1180,10 +1186,10 @@ gb_internal String get_fullpath_base_collection(gbAllocator a, String path) {
|
|||||||
|
|
||||||
String res = make_string(str, i);
|
String res = make_string(str, i);
|
||||||
res = string_trim_whitespace(res);
|
res = string_trim_whitespace(res);
|
||||||
return path_to_fullpath(a, res);
|
return path_to_fullpath(a, res, ok_);
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal String get_fullpath_core_collection(gbAllocator a, String path) {
|
gb_internal String get_fullpath_core_collection(gbAllocator a, String path, bool *ok_) {
|
||||||
String module_dir = odin_root_dir();
|
String module_dir = odin_root_dir();
|
||||||
|
|
||||||
String core = str_lit("core/");
|
String core = str_lit("core/");
|
||||||
@@ -1200,7 +1206,7 @@ gb_internal String get_fullpath_core_collection(gbAllocator a, String path) {
|
|||||||
|
|
||||||
String res = make_string(str, i);
|
String res = make_string(str, i);
|
||||||
res = string_trim_whitespace(res);
|
res = string_trim_whitespace(res);
|
||||||
return path_to_fullpath(a, res);
|
return path_to_fullpath(a, res, ok_);
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal bool show_error_line(void) {
|
gb_internal bool show_error_line(void) {
|
||||||
|
|||||||
+2
-2
@@ -774,7 +774,7 @@ gb_internal void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *
|
|||||||
gb_internal AstPackage *get_runtime_package(CheckerInfo *info) {
|
gb_internal AstPackage *get_runtime_package(CheckerInfo *info) {
|
||||||
String name = str_lit("runtime");
|
String name = str_lit("runtime");
|
||||||
gbAllocator a = heap_allocator();
|
gbAllocator a = heap_allocator();
|
||||||
String path = get_fullpath_base_collection(a, name);
|
String path = get_fullpath_base_collection(a, name, nullptr);
|
||||||
defer (gb_free(a, path.text));
|
defer (gb_free(a, path.text));
|
||||||
auto found = string_map_get(&info->packages, path);
|
auto found = string_map_get(&info->packages, path);
|
||||||
if (found == nullptr) {
|
if (found == nullptr) {
|
||||||
@@ -795,7 +795,7 @@ gb_internal AstPackage *get_core_package(CheckerInfo *info, String name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gbAllocator a = heap_allocator();
|
gbAllocator a = heap_allocator();
|
||||||
String path = get_fullpath_core_collection(a, name);
|
String path = get_fullpath_core_collection(a, name, nullptr);
|
||||||
defer (gb_free(a, path.text));
|
defer (gb_free(a, path.text));
|
||||||
auto found = string_map_get(&info->packages, path);
|
auto found = string_map_get(&info->packages, path);
|
||||||
if (found == nullptr) {
|
if (found == nullptr) {
|
||||||
|
|||||||
+17
-7
@@ -807,9 +807,10 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gbAllocator a = heap_allocator();
|
gbAllocator a = heap_allocator();
|
||||||
String fullpath = path_to_fullpath(a, path);
|
bool path_ok = false;
|
||||||
if (!path_is_directory(fullpath)) {
|
String fullpath = path_to_fullpath(a, path, &path_ok);
|
||||||
gb_printf_err("Library collection '%.*s' path must be a directory, got '%.*s'\n", LIT(name), LIT(fullpath));
|
if (!path_ok || !path_is_directory(fullpath)) {
|
||||||
|
gb_printf_err("Library collection '%.*s' path must be a directory, got '%.*s'\n", LIT(name), LIT(path_ok ? fullpath : path));
|
||||||
gb_free(a, fullpath.text);
|
gb_free(a, fullpath.text);
|
||||||
bad_flags = true;
|
bad_flags = true;
|
||||||
break;
|
break;
|
||||||
@@ -2395,9 +2396,18 @@ int main(int arg_count, char const **arg_ptr) {
|
|||||||
TIME_SECTION("init default library collections");
|
TIME_SECTION("init default library collections");
|
||||||
array_init(&library_collections, heap_allocator());
|
array_init(&library_collections, heap_allocator());
|
||||||
// NOTE(bill): 'core' cannot be (re)defined by the user
|
// NOTE(bill): 'core' cannot be (re)defined by the user
|
||||||
add_library_collection(str_lit("base"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("base")));
|
|
||||||
add_library_collection(str_lit("core"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("core")));
|
auto const &add_collection = [](String const &name) {
|
||||||
add_library_collection(str_lit("vendor"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("vendor")));
|
bool ok = false;
|
||||||
|
add_library_collection(name, get_fullpath_relative(heap_allocator(), odin_root_dir(), name, &ok));
|
||||||
|
if (!ok) {
|
||||||
|
compiler_error("Cannot find the library collection '%.*s'. Is the ODIN_ROOT set up correctly?", LIT(name));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
add_collection(str_lit("base"));
|
||||||
|
add_collection(str_lit("core"));
|
||||||
|
add_collection(str_lit("vendor"));
|
||||||
|
|
||||||
TIME_SECTION("init args");
|
TIME_SECTION("init args");
|
||||||
map_init(&build_context.defined_values);
|
map_init(&build_context.defined_values);
|
||||||
@@ -2581,7 +2591,7 @@ int main(int arg_count, char const **arg_ptr) {
|
|||||||
// NOTE(bill): add 'shared' directory if it is not already set
|
// NOTE(bill): add 'shared' directory if it is not already set
|
||||||
if (!find_library_collection_path(str_lit("shared"), nullptr)) {
|
if (!find_library_collection_path(str_lit("shared"), nullptr)) {
|
||||||
add_library_collection(str_lit("shared"),
|
add_library_collection(str_lit("shared"),
|
||||||
get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("shared")));
|
get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("shared"), nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
init_build_context(selected_target_metrics ? selected_target_metrics->metrics : nullptr, selected_subtarget);
|
init_build_context(selected_target_metrics ? selected_target_metrics->metrics : nullptr, selected_subtarget);
|
||||||
|
|||||||
+12
-3
@@ -5519,7 +5519,8 @@ gb_internal bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node
|
|||||||
if (has_windows_drive) {
|
if (has_windows_drive) {
|
||||||
*path = file_str;
|
*path = file_str;
|
||||||
} else {
|
} else {
|
||||||
String fullpath = string_trim_whitespace(get_fullpath_relative(permanent_allocator(), base_dir, file_str));
|
bool ok = false;
|
||||||
|
String fullpath = string_trim_whitespace(get_fullpath_relative(permanent_allocator(), base_dir, file_str, &ok));
|
||||||
*path = fullpath;
|
*path = fullpath;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -6141,7 +6142,11 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) {
|
|||||||
{ // Add these packages serially and then process them parallel
|
{ // Add these packages serially and then process them parallel
|
||||||
TokenPos init_pos = {};
|
TokenPos init_pos = {};
|
||||||
{
|
{
|
||||||
String s = get_fullpath_base_collection(permanent_allocator(), str_lit("runtime"));
|
bool ok = false;
|
||||||
|
String s = get_fullpath_base_collection(permanent_allocator(), str_lit("runtime"), &ok);
|
||||||
|
if (!ok) {
|
||||||
|
compiler_error("Unable to find The 'base:runtime' package. Is the ODIN_ROOT set up correctly?");
|
||||||
|
}
|
||||||
try_add_import_path(p, s, s, init_pos, Package_Runtime);
|
try_add_import_path(p, s, s, init_pos, Package_Runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6149,7 +6154,11 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) {
|
|||||||
p->init_fullpath = init_fullpath;
|
p->init_fullpath = init_fullpath;
|
||||||
|
|
||||||
if (build_context.command_kind == Command_test) {
|
if (build_context.command_kind == Command_test) {
|
||||||
String s = get_fullpath_core_collection(permanent_allocator(), str_lit("testing"));
|
bool ok = false;
|
||||||
|
String s = get_fullpath_core_collection(permanent_allocator(), str_lit("testing"), &ok);
|
||||||
|
if (!ok) {
|
||||||
|
compiler_error("Unable to find The 'core:testing' package. Is the ODIN_ROOT set up correctly?");
|
||||||
|
}
|
||||||
try_add_import_path(p, s, s, init_pos, Package_Normal);
|
try_add_import_path(p, s, s, init_pos, Package_Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user