Skip to content

Commit 97adfe2

Browse files
committed
Update set_depot_load_path in the embedding wrapper
Also get the test working.
1 parent 37ce1ad commit 97adfe2

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

examples/MyApp/src/MyApp.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ function real_main()
3838
@show Base.PROGRAM_FILE
3939
@show DEPOT_PATH
4040
@show LOAD_PATH
41+
try
42+
@show ENV["JULIA_DEPOT_PATH"]
43+
catch
44+
end
45+
try
46+
@show ENV["JULIA_LOAD_PATH"]
47+
catch
48+
end
4149
@show pwd()
4250
@show Base.active_project()
4351
@show Sys.BINDIR

src/embedding_wrapper.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,45 @@ jl_value_t *checked_eval_string(const char *code) {
3737

3838
void set_depot_load_path(const char *root_dir) {
3939
#ifdef _WIN32
40+
char *path_sep = ";";
4041
char *julia_share_subdir = "\\share\\julia";
4142
#else
43+
char *path_sep = ":";
4244
char *julia_share_subdir = "/share/julia";
4345
#endif
44-
char *share_dir =
45-
calloc(sizeof(char), strlen(root_dir) + strlen(julia_share_subdir) + 1);
46-
strcat(share_dir, root_dir);
47-
strcat(share_dir, julia_share_subdir);
46+
int share_path_len = strlen(root_dir) + strlen(julia_share_subdir) + 1;
47+
48+
char *curr_depot_path = getenv("JULIA_DEPOT_PATH");
49+
int curr_depot_path_len = curr_depot_path == NULL ? 0 : strlen(curr_depot_path);
50+
int new_depot_path_len = curr_depot_path_len + 1 + share_path_len;
51+
char *new_depot_path = calloc(sizeof (char), new_depot_path_len);
52+
if (curr_depot_path_len > 0) {
53+
strcat(new_depot_path, curr_depot_path);
54+
strcat(new_depot_path, path_sep);
55+
}
56+
strcat(new_depot_path, root_dir);
57+
strcat(new_depot_path, julia_share_subdir);
58+
59+
char *curr_load_path = getenv("JULIA_LOAD_PATH");
60+
int curr_load_path_len = curr_load_path == NULL ? 0 : strlen(curr_load_path);
61+
int new_load_path_len = curr_load_path_len + 1 + share_path_len;
62+
char *new_load_path = calloc(sizeof (char), new_load_path_len);
63+
if (curr_load_path_len > 0) {
64+
strcat(new_load_path, curr_load_path);
65+
strcat(new_load_path, path_sep);
66+
}
67+
strcat(new_load_path, root_dir);
68+
strcat(new_load_path, julia_share_subdir);
4869

4970
#ifdef _WIN32
50-
_putenv_s("JULIA_DEPOT_PATH", share_dir);
51-
_putenv_s("JULIA_LOAD_PATH", share_dir);
71+
_putenv_s("JULIA_DEPOT_PATH", new_depot_path);
72+
_putenv_s("JULIA_LOAD_PATH", new_load_path);
5273
#else
53-
setenv("JULIA_DEPOT_PATH", share_dir, 1);
54-
setenv("JULIA_LOAD_PATH", share_dir, 1);
74+
setenv("JULIA_DEPOT_PATH", new_depot_path, 1);
75+
setenv("JULIA_LOAD_PATH", new_load_path, 1);
5576
#endif
77+
free(new_load_path);
78+
free(new_depot_path);
5679
}
5780

5881
// main function (windows UTF16 -> UTF8 argument conversion code copied from

0 commit comments

Comments
 (0)