diff options
author | Andy Wingo <wingo@pobox.com> | 2009-06-02 22:18:02 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-06-03 22:20:54 +0200 |
commit | 5b197db838ae12aae948eef92d79d1f37548bac4 (patch) | |
tree | e041f1f33e58b5e6a5a406338f3b9541454ec73f /libguile/load.c | |
parent | 2f9ae9b1040e1b9339bb0bc8b0013a5346622c44 (diff) | |
download | guile-5b197db838ae12aae948eef92d79d1f37548bac4.tar.gz |
separate the load-compiled path from the load path
* libguile/Makefile.am (libpath.h): Add definitions for SCM_CCACHE_DIR
and SCM_EFFECTIVE_VERSION. These are private, the header is not
installed. Add ccachedir to build-info. Rework some other build-info
definitions.
* libguile/load.c (scm_loc_load_compiled_path): New global, corresponding
to the new environment variable, GUILE_LOAD_COMPILED_PATH. Compiled
files will now be searched for in this path, and only in this path.
(scm_init_load_path): Init the load-compiled path too. We initialize it
with $pkglibdir/guile/$effective_version/ccache, and also with
$HOME/.guile-ccache/$effective_version/. This will respect the
libdir/datadir difference, and it is a preparation for automatic
compilation support.
(scm_primitive_load_path): Search only the GUILE_LOAD_COMPILED_PATH for
compiled files.
(scm_init_load): Cache scm_loc_load_compiled_path.
Diffstat (limited to 'libguile/load.c')
-rw-r--r-- | libguile/load.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/libguile/load.c b/libguile/load.c index 1b5b24f35..f41e269e3 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -53,6 +53,10 @@ #include <unistd.h> #endif /* HAVE_UNISTD_H */ +#ifdef HAVE_PWD_H +#include <pwd.h> +#endif /* HAVE_PWD_H */ + #ifndef R_OK #define R_OK 4 #endif @@ -174,7 +178,8 @@ static SCM *scm_loc_load_path; /* List of extensions we try adding to the filenames. */ static SCM *scm_loc_load_extensions; -/* Like %load-extensions, but for compiled files. */ +/* Like %load-path and %load-extensions, but for compiled files. */ +static SCM *scm_loc_load_compiled_path; static SCM *scm_loc_load_compiled_extensions; @@ -209,6 +214,7 @@ scm_init_load_path () { char *env; SCM path = SCM_EOL; + SCM cpath = SCM_EOL; #ifdef SCM_LIBRARY_DIR env = getenv ("GUILE_SYSTEM_PATH"); @@ -222,13 +228,48 @@ scm_init_load_path () path = scm_list_3 (scm_from_locale_string (SCM_SITE_DIR), scm_from_locale_string (SCM_LIBRARY_DIR), scm_from_locale_string (SCM_PKGDATA_DIR)); + + env = getenv ("GUILE_SYSTEM_COMPILED_PATH"); + if (env && strcmp (env, "") == 0) + /* like above */ + ; + else if (env) + cpath = scm_parse_path (scm_from_locale_string (env), cpath); + else + { + char *home; + + home = getenv ("HOME"); +#ifdef HAVE_GETPWENT + if (!home) + { + struct passwd *pwd; + pwd = getpwuid (getuid ()); + if (pwd) + home = pwd->pw_dir; + } +#endif /* HAVE_GETPWENT */ + if (home) + { char buf[1024]; + snprintf (buf, sizeof(buf), + "%s/.guile-ccache/" SCM_EFFECTIVE_VERSION, home); + cpath = scm_cons (scm_from_locale_string (buf), cpath); + } + + cpath = scm_cons (scm_from_locale_string (SCM_CCACHE_DIR), cpath); + } #endif /* SCM_LIBRARY_DIR */ env = getenv ("GUILE_LOAD_PATH"); if (env) path = scm_parse_path (scm_from_locale_string (env), path); + env = getenv ("GUILE_LOAD_COMPILED_PATH"); + if (env) + cpath = scm_parse_path (scm_from_locale_string (env), cpath); + *scm_loc_load_path = path; + *scm_loc_load_compiled_path = cpath; } SCM scm_listofnullstr; @@ -519,7 +560,7 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0, SCM full_filename, compiled_filename; full_filename = scm_sys_search_load_path (filename); - compiled_filename = scm_search_path (*scm_loc_load_path, + compiled_filename = scm_search_path (*scm_loc_load_compiled_path, filename, *scm_loc_load_compiled_extensions, SCM_BOOL_T); @@ -529,6 +570,7 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0, scm_list_1 (filename)); if (scm_is_false (compiled_filename)) + /* FIXME: autocompile here */ return scm_primitive_load (full_filename); if (scm_is_false (full_filename)) @@ -600,6 +642,8 @@ scm_init_load () = SCM_VARIABLE_LOC (scm_c_define ("%load-extensions", scm_list_2 (scm_from_locale_string (".scm"), scm_nullstr))); + scm_loc_load_compiled_path + = SCM_VARIABLE_LOC (scm_c_define ("%load-compiled-path", SCM_EOL)); scm_loc_load_compiled_extensions = SCM_VARIABLE_LOC (scm_c_define ("%load-compiled-extensions", scm_list_1 (scm_from_locale_string (".go")))); |