From fc1f6bb4824a4115c82a2a7417dd592905cf3606 Mon Sep 17 00:00:00 2001 From: K Pamnany Date: Fri, 28 Feb 2025 13:28:01 -0500 Subject: [PATCH 1/2] Use `JULIA_DEPOT_PATH` and `JULIA_LOAD_PATH` from the environment When these environment variables are set, use them. --- src/julia_init.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/julia_init.c b/src/julia_init.c index d35761fe..4721becb 100644 --- a/src/julia_init.c +++ b/src/julia_init.c @@ -46,19 +46,39 @@ void set_depot_load_path(const char *root_dir) { #else char *julia_share_subdir = "/share/julia"; #endif - char *share_dir = - calloc(sizeof(char), strlen(root_dir) + strlen(julia_share_subdir) + 1); - strcat(share_dir, root_dir); - strcat(share_dir, julia_share_subdir); + int share_path_len = strlen(root_dir) + strlen(julia_share_subdir) + 1; + + char *curr_depot_path = getenv("JULIA_DEPOT_PATH"); + int curr_depot_path_len = curr_depot_path == NULL ? 0 : strlen(curr_depot_path); + int new_depot_path_len = curr_depot_path_len + 1 + share_path_len; + char *new_depot_path = calloc(sizeof (char), new_depot_path_len); + if (curr_depot_path_len > 0) { + strcat(new_depot_path, curr_depot_path); + strcat(new_depot_path, ":"); + } + strcat(new_depot_path, root_dir); + strcat(new_depot_path, julia_share_subdir); + + char *curr_load_path = getenv("JULIA_LOAD_PATH"); + int curr_load_path_len = curr_load_path == NULL ? 0 : strlen(curr_load_path); + int new_load_path_len = curr_load_path_len + 1 + share_path_len; + char *new_load_path = calloc(sizeof (char), new_load_path_len); + if (curr_load_path_len > 0) { + strcat(new_load_path, curr_load_path); + strcat(new_load_path, ":"); + } + strcat(new_load_path, root_dir); + strcat(new_load_path, julia_share_subdir); #ifdef _WIN32 - _putenv_s("JULIA_DEPOT_PATH", share_dir); - _putenv_s("JULIA_LOAD_PATH", share_dir); + _putenv_s("JULIA_DEPOT_PATH", new_depot_path); + _putenv_s("JULIA_LOAD_PATH", new_load_path); #else - setenv("JULIA_DEPOT_PATH", share_dir, 1); - setenv("JULIA_LOAD_PATH", share_dir, 1); + setenv("JULIA_DEPOT_PATH", new_depot_path, 1); + setenv("JULIA_LOAD_PATH", new_load_path, 1); #endif - free(share_dir); + free(new_load_path); + free(new_depot_path); } void init_julia(int argc, char **argv) { From e29f517b5801a8ed33ae320e62533f3773ff3236 Mon Sep 17 00:00:00 2001 From: K Pamnany Date: Wed, 5 Mar 2025 11:56:11 -0500 Subject: [PATCH 2/2] Address review comment --- src/julia_init.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/julia_init.c b/src/julia_init.c index 4721becb..0dbf5234 100644 --- a/src/julia_init.c +++ b/src/julia_init.c @@ -42,8 +42,10 @@ const char *get_sysimage_path(const char *libname) { void set_depot_load_path(const char *root_dir) { #ifdef _WIN32 + char *path_sep = ";"; char *julia_share_subdir = "\\share\\julia"; #else + char *path_sep = ":"; char *julia_share_subdir = "/share/julia"; #endif int share_path_len = strlen(root_dir) + strlen(julia_share_subdir) + 1; @@ -54,7 +56,7 @@ void set_depot_load_path(const char *root_dir) { char *new_depot_path = calloc(sizeof (char), new_depot_path_len); if (curr_depot_path_len > 0) { strcat(new_depot_path, curr_depot_path); - strcat(new_depot_path, ":"); + strcat(new_depot_path, path_sep); } strcat(new_depot_path, root_dir); strcat(new_depot_path, julia_share_subdir); @@ -65,7 +67,7 @@ void set_depot_load_path(const char *root_dir) { char *new_load_path = calloc(sizeof (char), new_load_path_len); if (curr_load_path_len > 0) { strcat(new_load_path, curr_load_path); - strcat(new_load_path, ":"); + strcat(new_load_path, path_sep); } strcat(new_load_path, root_dir); strcat(new_load_path, julia_share_subdir);