octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pkg dependencies


From: David Bateman
Subject: pkg dependencies
Date: Tue, 05 Jun 2007 00:30:08 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

At the moment the dependency checking code in pkg just ensures that all
dependencies of a package to load are also loaded. However, if the
PKG_ADD file also has a dependency on the other packages, then the order
in which the packages are loaded is important. This is the case between
the jhandles and java packages.

The attached patch addresses this issue, but there ae probably other
ways of doing this that might be cleaner. So comments would be welcome..

D.
Index: scripts/pkg/pkg.m
===================================================================
RCS file: /usr/local/cvsroot/octave/scripts/pkg/pkg.m,v
retrieving revision 1.51
diff -u -r1.51 pkg.m
--- scripts/pkg/pkg.m   3 Jun 2007 22:17:01 -0000       1.51
+++ scripts/pkg/pkg.m   4 Jun 2007 22:17:36 -0000
@@ -692,16 +692,12 @@
 
   ## Add the newly installed packages to the path, so the user
   ## can begin usings them.
-  arch = getarch();
   if (length (descriptions) > 0)
     dirs = {};
     for i = 1:length (descriptions)
       dirs{end + 1} = descriptions{i}.dir;
-      if (exist (fullfile (descriptions{i}.dir, arch), "dir"))
-       dirs{end + 1} = fullfile (descriptions{i}.dir, arch);
-      endif
     endfor
-    addpath (dirs{:});
+    load_in_order (dirs, local_list, global_list);
   endif
 endfunction
 
@@ -1675,34 +1671,10 @@
        endfor
       endif
     endfor
-    dirs = unique(dirs);
   endif
 
-  ## Check for architecture dependent directories
-  arch = getarch();
-  archdirs = {};
-  for i = 1:length (dirs)
-    tmpdir = fullfile (dirs{i}, arch);
-    archdirs{end + 1} = dirs{i};
-    if (exist (tmpdir, "dir"))
-      archdirs{end + 1} = tmpdir;
-    endif
-  endfor
-  if (length (archdirs) > 0)
-    dirs = archdirs;
-  endif
-
-  ## Load the packages
-  if (length (dirs) > 0)
-    addpath (dirs{:});
-  endif
-
-  ## Add local binaries, if any, to the EXEC_PATH
-  for i = 1:length (dirs)
-   if (exist (fullfile (dirs{i}, "bin"), "dir"))
-     EXEC_PATH (strcat (fullfile(dirs{i}, "bin"), ":", EXEC_PATH ()));
-   endif
-  endfor
+  ## Load the packages, but take care of the ordering of dependencies
+  load_in_order (dirs, local_list, global_list);
 endfunction
 
 function unload_packages (files, handle_deps, local_list, global_list)
@@ -1826,3 +1798,69 @@
     [status, output] = system (cmd);
   endif
 endfunction
+
+function loaddirs = load_in_order (dirs, local_list, global_list)
+  installed_packages = installed_packages (local_list, global_list);
+  dirs = load_order (dirs, installed_packages);
+  dirs = unique(dirs);
+
+  ## Add local binaries, if any, to the EXEC_PATH
+  arch = getarch ();
+  archdirs = {};
+  for i = 1:length (dirs)
+   archdirs {end + 1} = dirs{i};
+   tmpdir = fullfile (dirs{i}, arch);
+   if (exist (tmpdir, "dir"))
+     archdirs{end + 1} = tmpdir;
+   endif
+   if (exist (fullfile (dirs{i}, "bin"), "dir"))
+     EXEC_PATH (strcat (fullfile(dirs{i}, "bin"), ":", EXEC_PATH ()));
+   endif
+  endfor
+
+  ## Load the packages
+  if (length (archdirs) > 0)
+    addpath (archdirs{:});
+  endif
+endfunction
+
+function [loaddirs, installed_packages] = load_order (dirs, installed_packages)
+  loaddirs = {};
+  for i = 1 : length(dirs)
+    found = -1;
+    for j = 1 : length (installed_packages)
+      if (strcmp (installed_packages{j}.dir, dirs{i}))
+        found = j;
+        break;
+      endif
+    endfor
+    if (found < 1)
+      warning ("pkg: trying to load non existent package, %s", dirs{i}); 
+    elseif (! installed_packages{found}.loaded)
+      dep = installed_packages{found}.depends;
+      if (isempty (dep) || (length (dep) == 1 && 
+                           strcmp(dep{1}.package, "octave")))
+        loaddirs {end + 1} = dirs{i};
+        installed_packages{found}.loaded = true;
+      else
+        newdirs = {};
+        deps = installed_packages{found}.depends;
+        for k = 1 : length (deps)
+          for j = 1 : length (installed_packages)
+            if (strcmp (installed_packages{j}.name, deps{k}.package))
+              newdirs {end + 1} = installed_packages{j}.dir;
+             break;
+            endif
+          endfor
+        endfor
+
+        [loaddirs2, installed_packages] = ...
+           load_order(newdirs, installed_packages);
+        loaddirs = [loaddirs, loaddirs2];
+
+        loaddirs {end + 1} = dirs{i};
+        installed_packages{found}.loaded = true;
+      endif
+    endif
+  endfor
+endfunction

reply via email to

[Prev in Thread] Current Thread [Next in Thread]