aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-04-26 22:56:32 +0100
committergingerBill <bill@gingerbill.org>2021-04-26 22:56:32 +0100
commit06e0da97b7a7fbda942141818ac2fd34e6dde6eb (patch)
treeb6dbad76227d32129f81eb55c755d6fb0673599e /src/main.cpp
parent04535b291310ff53c19fdc96817f2a651b540907 (diff)
Implement `ODIN_ROOT` #913
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index fbce4838c..251616b56 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1916,6 +1916,24 @@ void print_show_unused(Checker *c) {
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) {
if (arg_count < 2) {
@@ -1939,6 +1957,10 @@ int main(int arg_count, char const **arg_ptr) {
init_keyword_hash_table();
global_big_int_init();
+ if (!check_env()) {
+ return 1;
+ }
+
array_init(&library_collections, heap_allocator());
// 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")));