Skip to content

julia_init.c: Use JULIA_DEPOT_PATH and JULIA_LOAD_PATH from the environment #1032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions src/julia_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,45 @@ 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
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, path_sep);
}
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, path_sep);
}
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) {
Expand Down
Loading