separate the load-compiled path from the load path
authorAndy Wingo <wingo@pobox.com>
Tue, 2 Jun 2009 20:18:02 +0000 (22:18 +0200)
committerAndy Wingo <wingo@pobox.com>
Wed, 3 Jun 2009 20:20:54 +0000 (22:20 +0200)
* 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.

libguile/Makefile.am
libguile/load.c

index fcf197a..b9e8e2b 100644 (file)
@@ -286,6 +286,8 @@ libpath.h: $(srcdir)/Makefile.in  $(top_builddir)/config.status
        @echo '#define SCM_PKGDATA_DIR "$(pkgdatadir)"' >> libpath.tmp
        @echo '#define SCM_LIBRARY_DIR "$(pkgdatadir)/$(GUILE_EFFECTIVE_VERSION)"'>>libpath.tmp
        @echo '#define SCM_SITE_DIR "$(pkgdatadir)/site"' >> libpath.tmp
+       @echo '#define SCM_CCACHE_DIR "$(pkglibdir)/$(GUILE_EFFECTIVE_VERSION)/ccache"' >> libpath.tmp
+       @echo '#define SCM_EFFECTIVE_VERSION "$(GUILE_EFFECTIVE_VERSION)"' >> libpath.tmp
        @echo '#define SCM_BUILD_INFO { \' >> libpath.tmp
        @echo ' { "srcdir", "'"`cd @srcdir@; pwd`"'" }, \' >> libpath.tmp
        @echo ' { "top_srcdir",    "@top_srcdir_absolute@" }, \' >> libpath.tmp
@@ -299,12 +301,13 @@ libpath.h: $(srcdir)/Makefile.in  $(top_builddir)/config.status
        @echo ' { "sharedstatedir", "@sharedstatedir@" }, \' >> libpath.tmp
        @echo ' { "localstatedir", "@localstatedir@" }, \' >> libpath.tmp
        @echo ' { "libdir",        "@libdir@" }, \' >> libpath.tmp
+       @echo ' { "ccachedir",     SCM_CCACHE_DIR }, \' >> libpath.tmp
        @echo ' { "infodir",       "@infodir@" }, \' >> libpath.tmp
        @echo ' { "mandir",        "@mandir@" }, \' >> libpath.tmp
        @echo ' { "includedir",    "@includedir@" }, \' >> libpath.tmp
-       @echo ' { "pkgdatadir",    "$(datadir)/@PACKAGE@" }, \' >> libpath.tmp
-       @echo ' { "pkglibdir",     "$(libdir)/@PACKAGE@" }, \' >> libpath.tmp
-       @echo ' { "pkgincludedir", "$(includedir)/@PACKAGE@" }, \' \
+       @echo ' { "pkgdatadir",    "@pkgdatadir@" }, \' >> libpath.tmp
+       @echo ' { "pkglibdir",     "@pkglibdir@" }, \' >> libpath.tmp
+       @echo ' { "pkgincludedir", "@pkgincludedir@" }, \' \
                >> libpath.tmp
        @echo ' { "guileversion", "@GUILE_VERSION@" }, \' >> libpath.tmp
        @echo ' { "libguileinterface", "@LIBGUILE_INTERFACE@" }, \' \
index 1b5b24f..f41e269 100644 (file)
 #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"))));