mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Implement ODIN_ROOT #913
This commit is contained in:
+30
-3
@@ -450,8 +450,35 @@ bool find_library_collection_path(String name, String *path) {
|
|||||||
String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1};
|
String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1};
|
||||||
String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1};
|
String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1};
|
||||||
|
|
||||||
#if defined(GB_SYSTEM_WINDOWS)
|
|
||||||
|
String internal_odin_root_dir(void);
|
||||||
String odin_root_dir(void) {
|
String odin_root_dir(void) {
|
||||||
|
if (global_module_path_set) {
|
||||||
|
return global_module_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
gbAllocator a = heap_allocator();
|
||||||
|
char const *found = gb_get_env("ODIN_ROOT", a);
|
||||||
|
if (found) {
|
||||||
|
String path = path_to_full_path(a, make_string_c(found));
|
||||||
|
if (path[path.len-1] != '/' && path[path.len-1] != '\\') {
|
||||||
|
#if defined(GB_SYSTEM_WINDOWS)
|
||||||
|
path = concatenate_strings(a, path, WIN32_SEPARATOR_STRING);
|
||||||
|
#else
|
||||||
|
path = concatenate_strings(a, path, NIX_SEPARATOR_STRING);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
global_module_path = path;
|
||||||
|
global_module_path_set = true;
|
||||||
|
return global_module_path;
|
||||||
|
}
|
||||||
|
return internal_odin_root_dir();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(GB_SYSTEM_WINDOWS)
|
||||||
|
String internal_odin_root_dir(void) {
|
||||||
String path = global_module_path;
|
String path = global_module_path;
|
||||||
isize len, i;
|
isize len, i;
|
||||||
gbTempArenaMemory tmp;
|
gbTempArenaMemory tmp;
|
||||||
@@ -510,7 +537,7 @@ String odin_root_dir(void) {
|
|||||||
|
|
||||||
String path_to_fullpath(gbAllocator a, String s);
|
String path_to_fullpath(gbAllocator a, String s);
|
||||||
|
|
||||||
String odin_root_dir(void) {
|
String internal_odin_root_dir(void) {
|
||||||
String path = global_module_path;
|
String path = global_module_path;
|
||||||
isize len, i;
|
isize len, i;
|
||||||
gbTempArenaMemory tmp;
|
gbTempArenaMemory tmp;
|
||||||
@@ -568,7 +595,7 @@ String odin_root_dir(void) {
|
|||||||
|
|
||||||
String path_to_fullpath(gbAllocator a, String s);
|
String path_to_fullpath(gbAllocator a, String s);
|
||||||
|
|
||||||
String odin_root_dir(void) {
|
String internal_odin_root_dir(void) {
|
||||||
String path = global_module_path;
|
String path = global_module_path;
|
||||||
isize len, i;
|
isize len, i;
|
||||||
gbTempArenaMemory tmp;
|
gbTempArenaMemory tmp;
|
||||||
|
|||||||
@@ -1916,6 +1916,24 @@ void print_show_unused(Checker *c) {
|
|||||||
print_usage_line(0, "");
|
print_usage_line(0, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_env(void) {
|
||||||
|
gbAllocator a = heap_allocator();
|
||||||
|
char const *odin_root = gb_get_env("ODIN_ROOT", a);
|
||||||
|
defer (gb_free(a, cast(void *)odin_root));
|
||||||
|
if (odin_root) {
|
||||||
|
if (!gb_file_exists(odin_root)) {
|
||||||
|
gb_printf_err("Invalid ODIN_ROOT, directory does not exist, got %s\n", odin_root);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String path = make_string_c(odin_root);
|
||||||
|
if (!path_is_directory(path)) {
|
||||||
|
gb_printf_err("Invalid ODIN_ROOT, expected a directory, got %s\n", odin_root);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int arg_count, char const **arg_ptr) {
|
int main(int arg_count, char const **arg_ptr) {
|
||||||
if (arg_count < 2) {
|
if (arg_count < 2) {
|
||||||
@@ -1939,6 +1957,10 @@ int main(int arg_count, char const **arg_ptr) {
|
|||||||
init_keyword_hash_table();
|
init_keyword_hash_table();
|
||||||
global_big_int_init();
|
global_big_int_init();
|
||||||
|
|
||||||
|
if (!check_env()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
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("core"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("core")));
|
add_library_collection(str_lit("core"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("core")));
|
||||||
|
|||||||
Reference in New Issue
Block a user