mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-23 14:55:19 +00:00
Improve error handling for missing library collection provided by the compiler
This commit is contained in:
@@ -876,7 +876,7 @@ gb_internal String internal_odin_root_dir(void) {
|
||||
|
||||
#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) {
|
||||
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.
|
||||
#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) {
|
||||
String path = global_module_path;
|
||||
@@ -1091,7 +1091,7 @@ gb_internal String internal_odin_root_dir(void) {
|
||||
gb_global BlockingMutex fullpath_mutex;
|
||||
|
||||
#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 = {};
|
||||
|
||||
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] = '/';
|
||||
}
|
||||
}
|
||||
if (ok_) *ok_ = true;
|
||||
} else {
|
||||
if (ok_) *ok_ = false;
|
||||
mutex_unlock(&fullpath_mutex);
|
||||
}
|
||||
|
||||
@@ -1129,7 +1131,11 @@ gb_internal String path_to_fullpath(gbAllocator a, String s) {
|
||||
mutex_lock(&fullpath_mutex);
|
||||
p = realpath(cast(char *)s.text, 0);
|
||||
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);
|
||||
}
|
||||
#else
|
||||
@@ -1137,7 +1143,7 @@ gb_internal String path_to_fullpath(gbAllocator a, String s) {
|
||||
#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);
|
||||
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);
|
||||
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 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);
|
||||
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 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);
|
||||
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) {
|
||||
|
||||
@@ -774,7 +774,7 @@ gb_internal void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *
|
||||
gb_internal AstPackage *get_runtime_package(CheckerInfo *info) {
|
||||
String name = str_lit("runtime");
|
||||
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));
|
||||
auto found = string_map_get(&info->packages, path);
|
||||
if (found == nullptr) {
|
||||
@@ -795,7 +795,7 @@ gb_internal AstPackage *get_core_package(CheckerInfo *info, String name) {
|
||||
}
|
||||
|
||||
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));
|
||||
auto found = string_map_get(&info->packages, path);
|
||||
if (found == nullptr) {
|
||||
|
||||
24
src/main.cpp
24
src/main.cpp
@@ -807,9 +807,10 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
}
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
String fullpath = path_to_fullpath(a, path);
|
||||
if (!path_is_directory(fullpath)) {
|
||||
gb_printf_err("Library collection '%.*s' path must be a directory, got '%.*s'\n", LIT(name), LIT(fullpath));
|
||||
bool path_ok = false;
|
||||
String fullpath = path_to_fullpath(a, path, &path_ok);
|
||||
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);
|
||||
bad_flags = true;
|
||||
break;
|
||||
@@ -2395,9 +2396,18 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
TIME_SECTION("init default library collections");
|
||||
array_init(&library_collections, heap_allocator());
|
||||
// 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")));
|
||||
add_library_collection(str_lit("vendor"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("vendor")));
|
||||
|
||||
auto const &add_collection = [](String const &name) {
|
||||
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");
|
||||
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
|
||||
if (!find_library_collection_path(str_lit("shared"), nullptr)) {
|
||||
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);
|
||||
|
||||
@@ -5519,7 +5519,8 @@ gb_internal bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node
|
||||
if (has_windows_drive) {
|
||||
*path = file_str;
|
||||
} 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;
|
||||
}
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -6149,7 +6154,11 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) {
|
||||
p->init_fullpath = init_fullpath;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user