Skip to content
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

[RFC/WIP] Add a secondary location for a sysimage in $HOME/.julia/$VERSION/sys.so #25324

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
27 changes: 26 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel)
free(free_path);
free_path = NULL;
if (jl_options.image_file) {
char *homedir_path = NULL;
if (rel == JL_IMAGE_JULIA_HOME && !isabspath(jl_options.image_file)) {
// build time path, relative to JULIA_BINDIR
free_path = (char*)malloc(PATH_MAX);
Expand All @@ -536,14 +537,38 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel)
if (n >= PATH_MAX || n < 0) {
jl_error("fatal error: jl_options.image_file path too long");
}
jl_options.image_file = free_path;
// Now we have the path to the bindir sysimg we can check whether
// the homedir is more up to date.
homedir_path = jl_get_homedir_sysimg_path();
uv_stat_t stbuf;
// check if file exists.
if (jl_stat(homedir_path, (char*)&stbuf) == 0 && (stbuf.st_mode & S_IFMT) == S_IFREG) {
// get modtime
double mtime_homedir = (double)stbuf.st_mtim.tv_sec + (double)stbuf.st_mtim.tv_nsec * 1e-9;
double mtime_bindir = 0.0;
if (jl_stat(free_path, (char*)&stbuf) == 0 && (stbuf.st_mode & S_IFMT) == S_IFREG) {
mtime_bindir = (double)stbuf.st_mtim.tv_sec + (double)stbuf.st_mtim.tv_nsec * 1e-9;
}
if (mtime_bindir >= mtime_homedir) {
// sysimg in bindir is newer
jl_options.image_file = free_path;
} else {
jl_options.image_file = homedir_path;
}
} else {
jl_options.image_file = free_path;
}
}
if (jl_options.image_file)
jl_options.image_file = abspath(jl_options.image_file, 0);
if (free_path) {
free(free_path);
free_path = NULL;
}
if (homedir_path) {
free(homedir_path);
homedir_path = NULL;
}
}
if (jl_options.outputo)
jl_options.outputo = abspath(jl_options.outputo, 0);
Expand Down
17 changes: 17 additions & 0 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ JL_DLLEXPORT const char *jl_get_default_sysimg_path(void)
return &system_image_path[1];
}

JL_DLLEXPORT char *jl_get_homedir_sysimg_path(void)
{
size_t size = PATH_MAX;
char *homedir = (char*) malloc(size);
if (uv_os_homedir(homedir, &size) != 0) {
free(homedir);
jl_error("fatal error: path of home dir is to large.");
}
char *path = (char*) malloc(PATH_MAX);
int n = snprintf(path, PATH_MAX, "%s" PATHSEPSTRING "%s" PATHSEPSTRING "v%s" PATHSEPSTRING "%s%s", homedir, ".julia", JULIA_VERSION_STRING , "sys", shlib_ext);
if (n >= PATH_MAX || n < 0) {
jl_error("fatal error: Can't construct sysimage path");
}
free(homedir);
return path;
}


jl_options_t jl_options = { 0, // quiet
-1, // banner
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ JL_DLLEXPORT void jl_init(void);
JL_DLLEXPORT void jl_init_with_image(const char *julia_bindir,
const char *image_relative_path);
JL_DLLEXPORT const char *jl_get_default_sysimg_path(void);
JL_DLLEXPORT char *jl_get_homedir_sysimg_path(void);
JL_DLLEXPORT int jl_is_initialized(void);
JL_DLLEXPORT void jl_atexit_hook(int status);
JL_DLLEXPORT void JL_NORETURN jl_exit(int status);
Expand Down