7017
|
1 ## Copyright (C) 2005, 2006, 2007 S�ren Hauberg |
5801
|
2 ## |
6440
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6440
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
5801
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
5801
|
18 |
|
19 ## -*- texinfo -*- |
6032
|
20 ## @deftypefn {Command} pkg @var{command} @var{pkg_name} |
|
21 ## @deftypefnx {Command} pkg @var{command} @var{option} @var{pkg_name} |
|
22 ## This command interacts with the package manager. Different actions will |
6378
|
23 ## be taken depending on the value of @var{command}. |
6032
|
24 ## |
|
25 ## @table @samp |
|
26 ## @item install |
6070
|
27 ## Install named packages. For example, |
|
28 ## @example |
|
29 ## pkg install image-1.0.0.tar.gz |
|
30 ## @end example |
|
31 ## @noindent |
|
32 ## installs the package found in the file @code{image-1.0.0.tar.gz}. |
|
33 ## |
6645
|
34 ## The @var{option} variable can contain options that affect the manner |
|
35 ## in which a package is installed. These options can be one or more of |
|
36 ## |
|
37 ## @table @code |
|
38 ## @item -nodeps |
|
39 ## The package manager will disable the dependency checking. That way it |
|
40 ## is possible to install a package even if it depends on another package |
|
41 ## that's not installed on the system. @strong{Use this option with care.} |
|
42 ## |
|
43 ## @item -noauto |
|
44 ## The package manager will not automatically load the installed package |
|
45 ## when starting Octave, even if the package requests that it is. |
6258
|
46 ## |
6645
|
47 ## @item -auto |
|
48 ## The package manager will automatically load the installed package when |
|
49 ## starting Octave, even if the package requests that it isn't. |
|
50 ## |
|
51 ## @item -local |
|
52 ## A local installation is forced, even if the user has system privileges. |
6258
|
53 ## |
6645
|
54 ## @item -global |
|
55 ## A global installation is forced, even if the user doesn't normally have |
|
56 ## system privileges |
6614
|
57 ## |
6645
|
58 ## @item -verbose |
|
59 ## The package manager will print the output of all of the commands that are |
|
60 ## performed. |
|
61 ## @end table |
|
62 ## |
6032
|
63 ## @item uninstall |
6070
|
64 ## Uninstall named packages. For example, |
|
65 ## @example |
|
66 ## pkg uninstall image |
|
67 ## @end example |
|
68 ## @noindent |
|
69 ## removes the @code{image} package from the system. If another installed |
|
70 ## package depends on the @code{image} package an error will be issued. |
|
71 ## The package can be uninstalled anyway by using the @code{-nodeps} option. |
6032
|
72 ## @item load |
6070
|
73 ## Add named packages to the path. After loading a package it is |
|
74 ## possible to use the functions provided by the package. For example, |
|
75 ## @example |
|
76 ## pkg load image |
|
77 ## @end example |
|
78 ## @noindent |
|
79 ## adds the @code{image} package to the path. It is possible to load all |
|
80 ## installed packages at once with the command |
|
81 ## @example |
|
82 ## pkg load all |
|
83 ## @end example |
6203
|
84 ## @item unload |
|
85 ## Removes named packages from the path. After unloading a package it is |
|
86 ## no longer possible to use the functions provided by the package. |
|
87 ## This command behaves like the @code{load} command. |
6032
|
88 ## @item list |
6070
|
89 ## Show a list of the currently installed packages. By requesting one or two |
|
90 ## output argument it is possible to get a list of the currently installed |
|
91 ## packages. For example, |
|
92 ## @example |
|
93 ## installed_packages = pkg list; |
|
94 ## @end example |
|
95 ## @noindent |
|
96 ## returns a cell array containing a structure for each installed package. |
|
97 ## The command |
|
98 ## @example |
|
99 ## [@var{user_packages}, @var{system_packages}] = pkg list |
|
100 ## @end example |
|
101 ## @noindent |
|
102 ## splits the list of installed packages into those who are installed by |
|
103 ## the current user, and those installed by the system administrator. |
7497
|
104 ## @item describe |
|
105 ## Show a short description of the named installed packages, with the option |
|
106 ## '-verbose' also list functions provided by the package, e.g.: |
|
107 ## @example |
|
108 ## pkg describe -verbose all |
|
109 ## @end example |
|
110 ## @noindent |
|
111 ## will describe all installed packages and the functions they provide. |
|
112 ## If one output is requested a cell of structure containing the |
|
113 ## description and list of functions of each package is returned as |
|
114 ## output rather than printed on screen: |
|
115 ## @example |
|
116 ## desc = pkg ("describe", "secs1d", "image") |
|
117 ## @end example |
|
118 ## @noindent |
|
119 ## If any of the requested packages is not installed, pkg returns an |
|
120 ## error, unless a second output is requested: |
|
121 ## @example |
|
122 ## [ desc, flag] = pkg ("describe", "secs1d", "image") |
|
123 ## @end example |
|
124 ## @noindent |
|
125 ## @var{flag} will take one of the values "Not installed", "Loaded" or |
|
126 ## "Not loaded" for each of the named packages. |
6034
|
127 ## @item prefix |
6070
|
128 ## Set the installation prefix directory. For example, |
|
129 ## @example |
|
130 ## pkg prefix ~/my_octave_packages |
|
131 ## @end example |
|
132 ## @noindent |
|
133 ## sets the installation prefix to @code{~/my_octave_packages}. |
|
134 ## Packages will be installed in this directory. |
6034
|
135 ## |
6070
|
136 ## It is possible to get the current installation prefix by requesting an |
|
137 ## output argument. For example, |
|
138 ## @example |
|
139 ## p = pkg prefix |
|
140 ## @end example |
6925
|
141 ## |
|
142 ## The location in which to install the architecture dependent files can be |
|
143 ## independent specified with an addition argument. For example |
|
144 ## |
|
145 ## @example |
|
146 ## pkg prefix ~/my_octave_packages ~/my_octave_packages_for_my_pc |
|
147 ## @end example |
6189
|
148 ## @item local_list |
|
149 ## Set the file in which to look for information on the locally |
|
150 ## installed packages. Locally installed packages are those that are |
|
151 ## typically available only to the current user. For example |
|
152 ## @example |
|
153 ## pkg local_list ~/.octave_packages |
|
154 ## @end example |
|
155 ## It is possible to get the current value of local_list with the following |
|
156 ## @example |
|
157 ## pkg local_list |
|
158 ## @end example |
|
159 ## @item global_list |
|
160 ## Set the file in which to look for, for information on the globally |
|
161 ## installed packages. Globally installed packages are those that are |
|
162 ## typically available to all users. For example |
|
163 ## @example |
|
164 ## pkg global_list /usr/share/octave/octave_packages |
|
165 ## @end example |
|
166 ## It is possible to get the current value of global_list with the following |
|
167 ## @example |
|
168 ## pkg global_list |
|
169 ## @end example |
6645
|
170 ## @item rebuild |
|
171 ## Rebuilds the package database from the installed directories. This can |
|
172 ## be used in cases where for some reason the package database is corrupted. |
|
173 ## It can also take the @code{-auto} and @code{-noauto} options to allow the |
|
174 ## autolaoding state of a package to be changed. For example |
|
175 ## |
|
176 ## @example |
|
177 ## pkg rebuild -noauto image |
|
178 ## @end example |
|
179 ## |
|
180 ## will remove the autoloading status of the image package. |
6675
|
181 ## @item build |
|
182 ## Builds a binary form of a package or packages. The binary file produced |
|
183 ## will itself be an Octave package that can be installed normally with |
|
184 ## @code{pkg}. The form of the command to build a binary package is |
|
185 ## |
|
186 ## @example |
|
187 ## pkg build builddir image-1.0.0.tar.gz @dots{} |
|
188 ## @end example |
|
189 ## |
|
190 ## @noindent |
|
191 ## where @code{buiddir} is the name of a directory where the temporary |
|
192 ## installation will be produced and the binary packages will be found. |
|
193 ## The options @code{-verbose} and @code{-nodeps} are respected, while |
|
194 ## the other options are ignored. |
6032
|
195 ## @end table |
5801
|
196 ## @end deftypefn |
5947
|
197 |
|
198 ## PKG_ADD: mark_as_command pkg |
|
199 |
6496
|
200 function [local_packages, global_packages] = pkg (varargin) |
|
201 ## Installation prefix (XXX: what should these be on windows?) |
6645
|
202 persistent user_prefix = false; |
6496
|
203 persistent prefix = -1; |
6925
|
204 persistent archprefix = -1; |
6496
|
205 persistent local_list = tilde_expand (fullfile("~", ".octave_packages")); |
|
206 persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", |
|
207 "octave_packages"); |
|
208 mlock (); |
6189
|
209 |
6925
|
210 global_install = issuperuser (); |
6683
|
211 |
6496
|
212 if (prefix == -1) |
6645
|
213 if (global_install) |
6496
|
214 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); |
6937
|
215 archprefix = fullfile (octave_config_info ("libexecdir"), "octave", "packages"); |
6496
|
216 else |
|
217 prefix = fullfile ("~", "octave"); |
6925
|
218 archprefix = prefix; |
5801
|
219 endif |
6645
|
220 prefix = tilde_expand (prefix); |
6925
|
221 archprefix = tilde_expand (archprefix); |
6496
|
222 endif |
|
223 |
7497
|
224 available_actions = {"list", "install", "uninstall", "load", "unload", "prefix", ... |
|
225 "local_list", "global_list", "rebuild", "build","describe"}; |
6496
|
226 ## Handle input |
|
227 if (length (varargin) == 0 || ! iscellstr (varargin)) |
|
228 print_usage (); |
|
229 endif |
|
230 files = {}; |
|
231 deps = true; |
|
232 auto = 0; |
|
233 action = "none"; |
6614
|
234 verbose = false; |
6496
|
235 for i = 1:length (varargin) |
|
236 switch (varargin{i}) |
|
237 case "-nodeps" |
|
238 deps = false; |
|
239 case "-noauto" |
|
240 auto = -1; |
|
241 case "-auto" |
|
242 auto = 1; |
6614
|
243 case "-verbose" |
|
244 verbose = true; |
6645
|
245 case "-local" |
|
246 global_install = false; |
|
247 if (! user_prefix) |
6729
|
248 prefix = tilde_expand (fullfile ("~", "octave")); |
6645
|
249 endif |
|
250 case "-global" |
|
251 global_install = true; |
|
252 if (! user_prefix) |
|
253 prefix = fullfile (OCTAVE_HOME (), "share", "octave", "packages"); |
|
254 endif |
7497
|
255 case available_actions |
6925
|
256 if (strcmp (action, "none")) |
6687
|
257 action = varargin{i}; |
|
258 else |
|
259 error ("more than one action specified"); |
|
260 endif |
6496
|
261 otherwise |
|
262 files{end+1} = varargin{i}; |
5801
|
263 endswitch |
6496
|
264 endfor |
|
265 |
|
266 ## Take action |
|
267 switch (action) |
|
268 case "list" |
|
269 if (nargout == 0) |
|
270 installed_packages (local_list, global_list); |
|
271 elseif (nargout == 1) |
|
272 local_packages = installed_packages (local_list, global_list); |
|
273 elseif (nargout == 2) |
|
274 [local_packages, global_packages] = installed_packages (local_list, |
|
275 global_list); |
|
276 else |
|
277 error ("too many output arguments requested"); |
|
278 endif |
|
279 |
|
280 case "install" |
|
281 if (length (files) == 0) |
|
282 error ("you must specify at least one filename when calling 'pkg install'"); |
|
283 endif |
6925
|
284 install (files, deps, auto, prefix, archprefix, verbose, local_list, |
6645
|
285 global_list, global_install); |
6496
|
286 |
|
287 case "uninstall" |
|
288 if (length (files) == 0) |
|
289 error ("you must specify at least one package when calling 'pkg uninstall'"); |
|
290 endif |
6645
|
291 uninstall (files, deps, verbose, local_list, |
|
292 global_list, global_install); |
6496
|
293 |
|
294 case "load" |
|
295 if (length (files) == 0) |
|
296 error ("you must specify at least one package, 'all' or 'auto' when calling 'pkg load'"); |
|
297 endif |
|
298 load_packages (files, deps, local_list, global_list); |
|
299 |
|
300 case "unload" |
|
301 if (length (files) == 0) |
|
302 error ("you must specify at least one package or 'all' when calling 'pkg unload'"); |
|
303 endif |
|
304 unload_packages (files, deps, local_list, global_list); |
|
305 |
|
306 case "prefix" |
|
307 if (length (files) == 0 && nargout == 0) |
6925
|
308 printf ("Installation prefix: %s\n", prefix); |
|
309 printf ("Architecture dependent prefix: %s\n", archprefix); |
|
310 elseif (length (files) == 0 && nargout >= 1) |
6496
|
311 local_packages = prefix; |
6925
|
312 global_packages = archprefix; |
|
313 elseif (length (files) >= 1 && nargout <= 2 && ischar (files{1})) |
6496
|
314 prefix = files{1}; |
6675
|
315 prefix = absolute_pathname (prefix); |
|
316 local_packages = prefix; |
6645
|
317 user_prefix = true; |
6925
|
318 if (length (files) >= 2 && ischar (files{2})) |
|
319 archprefix = files{2}; |
|
320 try |
|
321 archprefix = absolute_pathname (archprefix); |
|
322 catch |
|
323 mkdir (archprefix); |
|
324 warning ("creating the directory %s\n", archprefix); |
|
325 archprefix = absolute_pathname (archprefix); |
|
326 end_try_catch |
|
327 global_packages = archprefix; |
|
328 endif |
6496
|
329 else |
|
330 error ("you must specify a prefix directory, or request an output argument"); |
|
331 endif |
|
332 |
|
333 case "local_list" |
|
334 if (length (files) == 0 && nargout == 0) |
|
335 disp (local_list); |
|
336 elseif (length (files) == 0 && nargout == 1) |
|
337 local_packages = local_list; |
|
338 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) |
6729
|
339 try |
|
340 local_list = absolute_pathname (files{1}); |
|
341 catch |
|
342 ## Force file to be created |
|
343 fclose (fopen (files{1}, 'wt')); |
|
344 local_list = absolute_pathname (files{1}); |
|
345 end_try_catch |
6496
|
346 else |
|
347 error ("you must specify a local_list file, or request an output argument"); |
|
348 endif |
|
349 |
|
350 case "global_list" |
|
351 if (length (files) == 0 && nargout == 0) |
|
352 disp(global_list); |
|
353 elseif (length (files) == 0 && nargout == 1) |
|
354 local_packages = global_list; |
|
355 elseif (length (files) == 1 && nargout == 0 && ischar (files{1})) |
6729
|
356 try |
|
357 global_list = absolute_pathname (files{1}); |
|
358 catch |
|
359 ## Force file to be created |
|
360 fclose (fopen (files{1}, 'wt')); |
|
361 global_list = absolute_pathname (files{1}); |
|
362 end_try_catch |
6496
|
363 else |
|
364 error ("you must specify a global_list file, or request an output argument"); |
|
365 endif |
6645
|
366 |
|
367 case "rebuild" |
|
368 if (global_install) |
6925
|
369 global_packages = rebuild (prefix, archprefix, global_list, files, |
|
370 auto, verbose); |
6695
|
371 global_packages = save_order (global_packages); |
6645
|
372 save (global_list, "global_packages"); |
6695
|
373 if (nargout > 0) |
|
374 local_packages = global_packages; |
|
375 endif |
6645
|
376 else |
6925
|
377 local_packages = rebuild (prefix, archprefix, local_list, files, auto, |
|
378 verbose); |
6695
|
379 local_packages = save_order (local_packages); |
6645
|
380 save (local_list, "local_packages"); |
6695
|
381 if (nargout == 0) |
|
382 clear ("local_packages"); |
|
383 endif |
6645
|
384 endif |
|
385 |
6675
|
386 case "build" |
|
387 if (length (files) < 2) |
|
388 error ("you must specify at least the build directory and one filename\nwhen calling 'pkg build'"); |
|
389 endif |
|
390 build (files, deps, auto, verbose); |
|
391 |
7497
|
392 case "describe" |
|
393 if (length (files) == 0) |
|
394 error ("you must specify at least one package or 'all' when calling 'pkg describe'"); |
|
395 endif |
|
396 ## XXX FIXME: the name of the output variables is inconsistent |
|
397 ## with their content |
|
398 switch (nargout) |
|
399 case 0 |
|
400 describe (files, verbose, local_list, global_list); |
|
401 case 1 |
|
402 pkg_desc_list = describe (files, verbose, local_list, ... |
|
403 global_list); |
|
404 local_packages = pkg_desc_list; |
|
405 case 2 |
|
406 [pkg_desc_list, flag] = describe (files, verbose, local_list, ... |
|
407 global_list); |
|
408 local_packages = pkg_desc_list; |
|
409 global_packages = flag; |
|
410 otherwise |
|
411 error ("you can request at most two outputs when calling 'pkg describe'"); |
|
412 endswitch |
|
413 |
6496
|
414 otherwise |
|
415 error ("you must specify a valid action for 'pkg'. See 'help pkg' for details"); |
|
416 endswitch |
|
417 endfunction |
|
418 |
6925
|
419 function descriptions = rebuild (prefix, archprefix, list, files, auto, verbose) |
6645
|
420 if (isempty (files)) |
|
421 [dirlist, err, msg] = readdir (prefix); |
|
422 if (err) |
|
423 error ("couldn't read directory %s: %s", prefix, msg); |
|
424 endif |
|
425 ## the two first entries of dirlist are "." and ".." |
|
426 dirlist([1,2]) = []; |
|
427 else |
|
428 old_descriptions = installed_packages (list, list); |
|
429 wd = pwd (); |
6663
|
430 unwind_protect |
|
431 cd (prefix); |
6696
|
432 dirlist = glob (cellfun(@(x) strcat(x, '-*'), files, 'UniformOutput', 0)); |
6663
|
433 unwind_protect_cleanup |
|
434 cd (wd); |
|
435 end_unwind_protect |
6645
|
436 endif |
|
437 descriptions = {}; |
|
438 for k = 1:length (dirlist) |
|
439 descfile = fullfile (prefix, dirlist{k}, "packinfo", "DESCRIPTION"); |
|
440 if (verbose) |
|
441 printf ("recreating package description from %s\n", dirlist{k}); |
|
442 endif |
|
443 if (exist (descfile, "file")) |
|
444 desc = get_description (descfile); |
|
445 desc.dir = fullfile (prefix, dirlist{k}); |
6925
|
446 desc.archprefix = fullfile (archprefix, strcat (desc.name, "-", |
|
447 desc.version)); |
6645
|
448 if (auto != 0) |
|
449 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) |
|
450 unlink (fullfile (desc.dir, "packinfo", ".autoload")); |
|
451 endif |
|
452 if (auto < 0) |
|
453 desc.autoload = 0; |
|
454 elseif (auto > 0) |
|
455 desc.autoload = 1; |
|
456 fclose (fopen (fullfile (desc.dir, "packinfo", ".autoload"), "wt")); |
|
457 endif |
|
458 else |
|
459 if (exist (fullfile (desc.dir, "packinfo", ".autoload"), "file")) |
|
460 desc.autoload = 1; |
|
461 else |
|
462 desc.autoload = 0; |
|
463 endif |
|
464 endif |
|
465 descriptions{end + 1} = desc; |
|
466 elseif (verbose) |
|
467 warning ("directory %s is not a valid package", dirlist{k}); |
|
468 endif |
|
469 endfor |
|
470 |
6663
|
471 if (! isempty (files)) |
6645
|
472 ## We are rebuilding for a particular package(s) so we should take |
|
473 ## care to keep the other untouched packages in the descriptions |
6663
|
474 descriptions = {descriptions{:}, old_descriptions{:}}; |
6645
|
475 |
|
476 dup = []; |
|
477 for i = 1:length (descriptions) |
|
478 if (find (dup, i)) |
|
479 continue; |
|
480 endif |
|
481 for j = (i+1):length (descriptions) |
|
482 if (find (dup, j)) |
|
483 continue; |
|
484 endif |
|
485 if (strcmp (descriptions{i}.name, descriptions{j}.name)) |
|
486 dup = [dup, j]; |
|
487 endif |
|
488 endfor |
|
489 endfor |
|
490 if (! isempty (dup)) |
|
491 descriptions (dup) = []; |
|
492 endif |
|
493 endif |
|
494 endfunction |
|
495 |
6675
|
496 function build (files, handle_deps, autoload, verbose) |
|
497 if (length (files) < 1) |
|
498 error ("insufficient number of files"); |
|
499 endif |
|
500 builddir = files{1}; |
|
501 if (! exist (builddir, "dir")) |
|
502 warning ("creating build directory %s", builddir); |
|
503 [status, msg] = mkdir (builddir); |
|
504 if (status != 1) |
|
505 error ("could not create installation directory: %s", msg); |
|
506 endif |
6496
|
507 endif |
6675
|
508 builddir = absolute_pathname (builddir); |
|
509 installdir = fullfile (builddir, "install"); |
|
510 if (! exist (installdir, "dir")) |
|
511 [status, msg] = mkdir (installdir); |
|
512 if (status != 1) |
|
513 error ("could not create installation directory: %s", msg); |
|
514 endif |
|
515 endif |
|
516 files(1) = []; |
|
517 buildlist = fullfile (builddir, "octave_packages"); |
6925
|
518 install (files, handle_deps, autoload, installdir, installdir, verbose, |
6675
|
519 buildlist, "", false); |
|
520 unwind_protect |
|
521 repackage (builddir, buildlist); |
|
522 unwind_protect_cleanup |
|
523 unload_packages ({"all"}, handle_deps, buildlist, ""); |
|
524 if (exist (installdir, "dir")) |
|
525 rm_rf (installdir); |
|
526 endif |
|
527 if (exist (buildlist, "file")) |
|
528 unlink (buildlist); |
|
529 endif |
|
530 end_unwind_protect |
5801
|
531 endfunction |
|
532 |
6925
|
533 function install (files, handle_deps, autoload, prefix, archprefix, verbose, |
|
534 local_list, global_list, global_install) |
6496
|
535 |
|
536 # Check that the directory in prefix exist. If it doesn't: create it! |
|
537 if (! exist (prefix, "dir")) |
|
538 warning ("creating installation directory %s", prefix); |
|
539 [status, msg] = mkdir (prefix); |
|
540 if (status != 1) |
|
541 error ("could not create installation directory: %s", msg); |
|
542 endif |
|
543 endif |
|
544 |
|
545 ## Get the list of installed packages |
|
546 [local_packages, global_packages] = installed_packages (local_list, |
|
547 global_list); |
|
548 |
6820
|
549 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496
|
550 |
|
551 if (global_install) |
|
552 packages = global_packages; |
|
553 else |
|
554 packages = local_packages; |
|
555 endif |
|
556 |
|
557 ## Uncompress the packages and read the DESCRIPTION files |
|
558 tmpdirs = packdirs = descriptions = {}; |
|
559 try |
6683
|
560 ## Warn about non existent files |
|
561 for i = 1:length (files) |
|
562 if (isempty (glob(files{i}))) |
|
563 warning ("file %s does not exist", files{i}); |
|
564 endif |
|
565 endfor |
|
566 |
6496
|
567 ## Unpack the package files and read the DESCRIPTION files |
|
568 files = glob (files); |
|
569 packages_to_uninstall = []; |
|
570 for i = 1:length (files) |
|
571 tgz = files{i}; |
|
572 |
6645
|
573 if (exist (tgz, "file")) |
|
574 ## Create a temporary directory |
|
575 tmpdir = tmpnam (); |
|
576 tmpdirs{end+1} = tmpdir; |
|
577 if (verbose) |
|
578 printf ("mkdir (%s)\n", tmpdir); |
|
579 endif |
|
580 [status, msg] = mkdir (tmpdir); |
|
581 if (status != 1) |
|
582 error ("couldn't create temporary directory: %s", msg); |
|
583 endif |
6496
|
584 |
6645
|
585 ## Uncompress the package |
|
586 if (verbose) |
|
587 printf ("untar (%s, %s)\n", tgz, tmpdir); |
|
588 endif |
|
589 untar (tgz, tmpdir); |
6496
|
590 |
6645
|
591 ## Get the name of the directories produced by tar |
|
592 [dirlist, err, msg] = readdir (tmpdir); |
|
593 if (err) |
|
594 error ("couldn't read directory produced by tar: %s", msg); |
|
595 endif |
6496
|
596 |
6645
|
597 if (length (dirlist) > 3) |
|
598 error ("bundles of packages are not allowed") |
6496
|
599 endif |
|
600 |
6645
|
601 ## the two first entries of dirlist are "." and ".." |
|
602 for k = 3:length (dirlist) |
|
603 packdir = fullfile (tmpdir, dirlist{k}); |
|
604 packdirs{end+1} = packdir; |
6496
|
605 |
6645
|
606 ## Make sure the package contains necessary files |
|
607 verify_directory (packdir); |
|
608 |
|
609 ## Read the DESCRIPTION file |
|
610 filename = fullfile (packdir, "DESCRIPTION"); |
|
611 desc = get_description (filename); |
6496
|
612 |
6645
|
613 ## Verify that package name corresponds with filename |
|
614 [dummy, nm] = fileparts (tgz); |
|
615 if ((length (nm) >= length (desc.name)) |
|
616 && ! strcmp (desc.name, nm(1:length(desc.name)))) |
6925
|
617 error ("package name '%s' doesn't correspond to its filename '%s'", |
|
618 desc.name, nm); |
6496
|
619 endif |
6645
|
620 |
|
621 ## Set default installation directory |
|
622 desc.dir = fullfile (prefix, strcat (desc.name, "-", desc.version)); |
|
623 |
6925
|
624 ## Set default architectire dependent installation directory |
|
625 desc.archprefix = fullfile (archprefix, strcat (desc.name, "-", |
|
626 desc.version)); |
|
627 |
6645
|
628 ## Save desc |
|
629 descriptions{end+1} = desc; |
|
630 |
|
631 ## Are any of the new packages already installed? |
|
632 ## If so we'll remove the old version. |
|
633 for j = 1:length (packages) |
|
634 if (strcmp (packages{j}.name, desc.name)) |
|
635 packages_to_uninstall(end+1) = j; |
|
636 endif |
|
637 endfor |
|
638 endfor |
|
639 endif |
6496
|
640 endfor |
|
641 catch |
|
642 ## Something went wrong, delete tmpdirs |
|
643 for i = 1:length (tmpdirs) |
|
644 rm_rf (tmpdirs{i}); |
|
645 endfor |
6655
|
646 rethrow (lasterror ()); |
6496
|
647 end_try_catch |
|
648 |
|
649 ## Check dependencies |
|
650 if (handle_deps) |
|
651 ok = true; |
|
652 error_text = ""; |
|
653 for i = 1:length (descriptions) |
|
654 desc = descriptions{i}; |
|
655 idx2 = complement (i, 1:length(descriptions)); |
6695
|
656 if (global_install) |
|
657 ## Global installation is not allowed to have dependencies on locally |
|
658 ## installed packages |
|
659 idx1 = complement (packages_to_uninstall, |
|
660 1:length(global_packages)); |
|
661 pseudo_installed_packages = {global_packages{idx1}, ... |
|
662 descriptions{idx2}}; |
|
663 else |
|
664 idx1 = complement (packages_to_uninstall, |
|
665 1:length(local_packages)); |
|
666 pseudo_installed_packages = {local_packages{idx1}, ... |
|
667 global_packages{:}, ... |
|
668 descriptions{idx2}}; |
|
669 endif |
6496
|
670 bad_deps = get_unsatisfied_deps (desc, pseudo_installed_packages); |
|
671 ## Are there any unsatisfied dependencies? |
|
672 if (! isempty (bad_deps)) |
|
673 ok = false; |
|
674 for i = 1:length (bad_deps) |
|
675 dep = bad_deps{i}; |
|
676 error_text = strcat (error_text, " ", desc.name, " needs ", |
|
677 dep.package, " ", dep.operator, " ", |
|
678 dep.version, "\n"); |
|
679 endfor |
|
680 endif |
|
681 endfor |
|
682 |
|
683 ## Did we find any unsatisfied dependencies? |
|
684 if (! ok) |
|
685 error ("the following dependencies where unsatisfied:\n %s", error_text); |
|
686 endif |
|
687 endif |
|
688 |
|
689 ## Prepare each package for installation |
|
690 try |
|
691 for i = 1:length (descriptions) |
|
692 desc = descriptions{i}; |
|
693 pdir = packdirs{i}; |
|
694 prepare_installation (desc, pdir); |
6614
|
695 configure_make (desc, pdir, verbose); |
6496
|
696 endfor |
|
697 catch |
|
698 ## Something went wrong, delete tmpdirs |
|
699 for i = 1:length (tmpdirs) |
|
700 rm_rf (tmpdirs{i}); |
|
701 endfor |
6655
|
702 rethrow (lasterror ()); |
6496
|
703 end_try_catch |
|
704 |
|
705 ## Uninstall the packages that will be replaced |
|
706 try |
|
707 for i = packages_to_uninstall |
6695
|
708 if (global_install) |
|
709 uninstall ({global_packages{i}.name}, false, verbose, local_list, |
|
710 global_list, global_install); |
|
711 else |
|
712 uninstall ({local_packages{i}.name}, false, verbose, local_list, |
|
713 global_list, global_install); |
|
714 endif |
6496
|
715 endfor |
|
716 catch |
|
717 ## Something went wrong, delete tmpdirs |
|
718 for i = 1:length (tmpdirs) |
|
719 rm_rf (tmpdirs{i}); |
|
720 endfor |
6655
|
721 rethrow (lasterror ()); |
6496
|
722 end_try_catch |
|
723 |
|
724 ## Install each package |
|
725 try |
|
726 for i = 1:length (descriptions) |
|
727 desc = descriptions{i}; |
|
728 pdir = packdirs{i}; |
6925
|
729 copy_files (desc, pdir, global_install); |
|
730 create_pkgadddel (desc, pdir, "PKG_ADD", global_install); |
|
731 create_pkgadddel (desc, pdir, "PKG_DEL", global_install); |
|
732 finish_installation (desc, pdir, global_install) |
6496
|
733 endfor |
|
734 catch |
|
735 ## Something went wrong, delete tmpdirs |
|
736 for i = 1:length (tmpdirs) |
|
737 rm_rf (tmpdirs{i}); |
|
738 endfor |
|
739 for i = 1:length (descriptions) |
|
740 rm_rf (descriptions{i}.dir); |
6925
|
741 rm_rf (getarchdir (descriptions{i})); |
6496
|
742 endfor |
6655
|
743 rethrow (lasterror ()); |
6496
|
744 end_try_catch |
|
745 |
|
746 ## Check if the installed directory is empty. If it is remove it |
|
747 ## from the list |
|
748 for i = length (descriptions):-1:1 |
6925
|
749 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) && |
|
750 dirempty (getarchdir (descriptions{i}))) |
6655
|
751 warning ("package %s is empty\n", descriptions{i}.name); |
6496
|
752 rm_rf (descriptions{i}.dir); |
6925
|
753 rm_rf (getarchdir (descriptions{i})); |
6496
|
754 descriptions(i) = []; |
|
755 endif |
|
756 endfor |
|
757 |
|
758 ## If the package requested that it is autoloaded, or the installer |
|
759 ## requested that it is, then mark the package as autoloaded. |
|
760 for i = length (descriptions):-1:1 |
|
761 if (autoload > 0 || (autoload == 0 && isautoload (descriptions(i)))) |
|
762 fclose (fopen (fullfile (descriptions{i}.dir, "packinfo", |
|
763 ".autoload"), "wt")); |
6695
|
764 descriptions{i}.autoload = 1; |
6496
|
765 endif |
|
766 endfor |
|
767 |
|
768 ## Add the packages to the package list |
|
769 try |
|
770 if (global_install) |
|
771 idx = complement (packages_to_uninstall, 1:length(global_packages)); |
6695
|
772 global_packages = save_order ({global_packages{idx}, descriptions{:}}); |
6496
|
773 save (global_list, "global_packages"); |
6820
|
774 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496
|
775 else |
|
776 idx = complement (packages_to_uninstall, 1:length(local_packages)); |
6695
|
777 local_packages = save_order ({local_packages{idx}, descriptions{:}}); |
6496
|
778 save (local_list, "local_packages"); |
6820
|
779 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496
|
780 endif |
|
781 catch |
|
782 ## Something went wrong, delete tmpdirs |
|
783 for i = 1:length (tmpdirs) |
|
784 rm_rf (tmpdirs{i}); |
|
785 endfor |
|
786 for i = 1:length (descriptions) |
|
787 rm_rf (descriptions{i}.dir); |
|
788 endfor |
|
789 if (global_install) |
6695
|
790 printf ("error: couldn't append to %s\n", global_list); |
6496
|
791 else |
6695
|
792 printf ("error: couldn't append to %s\n", local_list); |
6496
|
793 endif |
6695
|
794 rethrow (lasterror ()); |
6496
|
795 end_try_catch |
|
796 |
|
797 ## All is well, let's clean up |
|
798 for i = 1:length (tmpdirs) |
|
799 [status, msg] = rm_rf (tmpdirs{i}); |
|
800 if (status != 1) |
|
801 warning ("couldn't clean up after my self: %s\n", msg); |
|
802 endif |
|
803 endfor |
|
804 |
|
805 ## Add the newly installed packages to the path, so the user |
7192
|
806 ## can begin using them. Only load them if they are marked autoload |
6496
|
807 if (length (descriptions) > 0) |
6695
|
808 idx = []; |
6496
|
809 for i = 1:length (descriptions) |
6695
|
810 if (isautoload (descriptions(i))) |
7192
|
811 nm = descriptions{i}.name; |
|
812 for j = 1:length (installed_pkgs_lst) |
|
813 if (strcmp (nm, installed_pkgs_lst{j}.name)) |
|
814 idx (end + 1) = j; |
|
815 break; |
|
816 endif |
|
817 endfor |
6614
|
818 endif |
6496
|
819 endfor |
6925
|
820 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
|
821 global_install); |
6496
|
822 endif |
|
823 endfunction |
|
824 |
6645
|
825 function uninstall (pkgnames, handle_deps, verbose, local_list, |
|
826 global_list, global_install) |
6496
|
827 ## Get the list of installed packages |
|
828 [local_packages, global_packages] = installed_packages(local_list, |
|
829 global_list); |
6645
|
830 if (global_install) |
6820
|
831 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496
|
832 else |
6820
|
833 installed_pkgs_lst = local_packages; |
6496
|
834 endif |
|
835 |
6820
|
836 num_packages = length (installed_pkgs_lst); |
6496
|
837 delete_idx = []; |
|
838 for i = 1:num_packages |
6820
|
839 cur_name = installed_pkgs_lst{i}.name; |
6496
|
840 if (any (strcmp (cur_name, pkgnames))) |
|
841 delete_idx(end+1) = i; |
|
842 endif |
|
843 endfor |
|
844 |
|
845 ## Are all the packages that should be uninstalled already installed? |
|
846 if (length (delete_idx) != length (pkgnames)) |
6645
|
847 if (global_install) |
6496
|
848 ## Try again for a locally installed package |
6820
|
849 installed_pkgs_lst = local_packages; |
6496
|
850 |
6820
|
851 num_packages = length (installed_pkgs_lst); |
6496
|
852 delete_idx = []; |
|
853 for i = 1:num_packages |
6820
|
854 cur_name = installed_pkgs_lst{i}.name; |
6496
|
855 if (any (strcmp (cur_name, pkgnames))) |
|
856 delete_idx(end+1) = i; |
|
857 endif |
|
858 endfor |
|
859 if (length (delete_idx) != length (pkgnames)) |
|
860 ## XXX: We should have a better error message |
6655
|
861 warning ("some of the packages you want to uninstall are not installed"); |
6496
|
862 endif |
|
863 else |
|
864 ## XXX: We should have a better error message |
6655
|
865 warning ("some of the packages you want to uninstall are not installed."); |
6496
|
866 endif |
|
867 endif |
|
868 |
|
869 ## Compute the packages that will remain installed |
|
870 idx = complement (delete_idx, 1:num_packages); |
6820
|
871 remaining_packages = {installed_pkgs_lst{idx}}; |
6496
|
872 |
|
873 ## Check dependencies |
|
874 if (handle_deps) |
|
875 error_text = ""; |
|
876 for i = 1:length (remaining_packages) |
|
877 desc = remaining_packages{i}; |
|
878 bad_deps = get_unsatisfied_deps (desc, remaining_packages); |
|
879 |
|
880 ## Will the uninstallation break any dependencies? |
|
881 if (! isempty (bad_deps)) |
|
882 for i = 1:length (bad_deps) |
|
883 dep = bad_deps{i}; |
|
884 error_text = strcat (error_text, " ", desc.name, " needs ", |
|
885 dep.package, " ", dep.operator, " ", |
|
886 dep.version, "\n"); |
|
887 endfor |
|
888 endif |
|
889 endfor |
|
890 |
|
891 if (! isempty (error_text)) |
|
892 error ("the following dependencies where unsatisfied:\n %s", error_text); |
|
893 endif |
|
894 endif |
|
895 |
|
896 ## Delete the directories containing the packages |
|
897 for i = delete_idx |
6820
|
898 desc = installed_pkgs_lst{i}; |
6496
|
899 ## If an 'on_uninstall.m' exist, call it! |
|
900 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file")) |
6614
|
901 wd = pwd (); |
|
902 cd (fullfile(desc.dir, "packinfo")); |
|
903 on_uninstall (desc); |
|
904 cd (wd); |
6496
|
905 endif |
|
906 ## Do the actual deletion |
6675
|
907 if (desc.loaded) |
|
908 rmpath (desc.dir); |
6925
|
909 if (exist (getarchdir (desc))) |
|
910 rmpath (getarchdir (desc)); |
6675
|
911 endif |
6614
|
912 endif |
6496
|
913 if (exist (desc.dir, "dir")) |
|
914 [status, msg] = rm_rf (desc.dir); |
|
915 if (status != 1) |
|
916 error ("couldn't delete directory %s: %s", desc.dir, msg); |
|
917 endif |
6925
|
918 [status, msg] = rm_rf (getarchdir (desc)); |
|
919 if (status != 1) |
|
920 error ("couldn't delete directory %s: %s", getarchdir (desc), msg); |
|
921 endif |
|
922 if (dirempty (desc.archprefix)) |
|
923 rm_rf (desc.archprefix); |
|
924 endif |
6496
|
925 else |
|
926 warning ("directory %s previously lost", desc.dir); |
|
927 endif |
|
928 endfor |
|
929 |
|
930 ## Write a new ~/.octave_packages |
6645
|
931 if (global_install) |
6496
|
932 if (length (remaining_packages) == 0) |
|
933 unlink (global_list); |
|
934 else |
6695
|
935 global_packages = save_order (remaining_packages); |
6496
|
936 save (global_list, "global_packages"); |
|
937 endif |
|
938 else |
|
939 if (length (remaining_packages) == 0) |
|
940 unlink (local_list); |
|
941 else |
6695
|
942 local_packages = save_order (remaining_packages); |
6496
|
943 save (local_list, "local_packages"); |
|
944 endif |
|
945 endif |
|
946 |
|
947 endfunction |
|
948 |
7497
|
949 function [pkg_desc_list, flag] = describe (pkgnames, verbose, |
|
950 local_list, global_list) |
|
951 |
|
952 ## Get the list of installed packages |
|
953 installed_pkgs_lst = installed_packages(local_list, global_list); |
|
954 num_packages = length (installed_pkgs_lst); |
|
955 |
|
956 |
|
957 describe_all = false; |
|
958 if (any (strcmp ('all', pkgnames))) |
|
959 describe_all = true; |
|
960 flag{1:num_packages} = "Not Loaded"; |
|
961 num_pkgnames = num_packages; |
|
962 else |
|
963 num_pkgnames = length (pkgnames); |
|
964 flag{1:num_pkgnames} = "Not installed"; |
|
965 end |
|
966 |
|
967 for i = 1:num_packages |
|
968 curr_name= installed_pkgs_lst{i}.name; |
|
969 if (describe_all) |
|
970 name_pos = i; |
|
971 else |
|
972 name_pos = find(strcmp (curr_name, pkgnames)); |
|
973 end |
|
974 if (!isempty(name_pos)) |
|
975 if (installed_pkgs_lst{i}.loaded) |
|
976 flag{name_pos} = "Loaded"; |
|
977 else |
|
978 flag{name_pos} = "Not loaded"; |
|
979 endif |
|
980 |
|
981 pkg_desc_list{name_pos}.name = ... |
|
982 installed_pkgs_lst{i}.name; |
|
983 pkg_desc_list{name_pos}.description = ... |
|
984 installed_pkgs_lst{i}.description; |
|
985 pkg_desc_list{name_pos}.provides = ... |
|
986 parse_pkg_idx(installed_pkgs_lst{i}.dir); |
|
987 |
|
988 endif |
|
989 endfor |
|
990 |
|
991 non_inst = find(strcmp(flag,"Not installed")); |
|
992 if (!isempty(non_inst) && (nargout<2)) |
|
993 non_inst_str = sprintf(" %s ",pkgnames{non_inst}); |
|
994 error("some packages are not installed: %s",non_inst_str); |
|
995 endif |
|
996 |
|
997 if (nargout == 0) |
|
998 for i=1:num_pkgnames |
|
999 print_package_description (pkg_desc_list{i}.name, |
|
1000 pkg_desc_list{i}.provides, |
|
1001 pkg_desc_list{i}.description, |
|
1002 flag{i}, verbose); |
|
1003 endfor |
|
1004 endif |
|
1005 |
|
1006 endfunction |
|
1007 |
6496
|
1008 ########################################################## |
|
1009 ## A U X I L I A R Y F U N C T I O N S ## |
|
1010 ########################################################## |
|
1011 |
7497
|
1012 ## This function reads an INDEX file |
|
1013 function [pkg_idx_struct] = parse_pkg_idx(packdir) |
|
1014 |
|
1015 fINDEX = fullfile (packdir, "packinfo", "INDEX"); |
|
1016 |
|
1017 if (!exist(fINDEX, "file") ) |
|
1018 error("could not find any INDEX file in directory %s, \ |
|
1019 \ntry 'pkg rebuild all' to generate missing INDEX files", packdir); |
|
1020 endif |
|
1021 |
|
1022 |
|
1023 [fid, msg] = fopen(fINDEX,"r"); |
|
1024 if (fid == -1) |
|
1025 error("the INDEX file %s could not be read: %s", |
|
1026 fINDEX, msg); |
|
1027 endif |
|
1028 |
|
1029 cat_num = 1; |
|
1030 pkg_idx_struct{1}.category = "Uncategorized"; |
|
1031 pkg_idx_struct{1}.functions = {}; |
|
1032 |
|
1033 |
|
1034 line = fgetl(fid); |
|
1035 while ((isempty(strfind(line,">>"))) && (! feof (fid))) |
|
1036 line = fgetl(fid); |
|
1037 endwhile |
|
1038 |
|
1039 while ((! feof (fid) ) || (line != -1)) |
|
1040 if (!any(!isspace(line)) || (line(1) == "#") || any(line=="=")) |
|
1041 ## Comments, blank lines or comments about unimplemented |
|
1042 ## functions: do nothing |
|
1043 ## XXX: probably comments and pointers to external functions |
|
1044 ## could be treated better when printing to screen? |
|
1045 elseif (!isempty(strfind(line,">>"))) |
|
1046 ## Skip package name and description as they are in |
|
1047 ## DESCRIPTION already |
|
1048 elseif (!isspace(line(1))) |
|
1049 ## Category |
|
1050 if ( !isempty(pkg_idx_struct{cat_num}.functions)) |
|
1051 pkg_idx_struct{++cat_num}.functions = {}; |
|
1052 endif |
|
1053 pkg_idx_struct{cat_num}.category = deblank(line); |
|
1054 else |
|
1055 ## Function names |
|
1056 while (any(!isspace(line))) |
|
1057 [fun_name, line] = strtok(line); |
|
1058 pkg_idx_struct{cat_num}.functions{end+1} = deblank(fun_name); |
|
1059 endwhile |
|
1060 endif |
|
1061 line = fgetl(fid); |
|
1062 endwhile |
|
1063 fclose (fid); |
|
1064 endfunction |
|
1065 |
|
1066 function print_package_description (pkg_name, pkg_idx_struct, |
|
1067 pkg_desc, status, verbose) |
|
1068 |
|
1069 printf("---\nPackage name:\n\t%s\n", pkg_name); |
|
1070 printf("Short description:\n\t%s\n", pkg_desc); |
|
1071 printf("Status:\n\t%s\n", status); |
|
1072 if (verbose) |
|
1073 printf("---\nProvides:\n"); |
|
1074 for i=1:length(pkg_idx_struct) |
|
1075 if (!isempty(pkg_idx_struct{i}.functions)) |
|
1076 printf("%s\n", pkg_idx_struct{i}.category); |
|
1077 for j=1:length(pkg_idx_struct{i}.functions) |
|
1078 printf("\t%s\n", pkg_idx_struct{i}.functions{j}); |
|
1079 endfor |
|
1080 endif |
|
1081 endfor |
|
1082 endif |
|
1083 |
|
1084 endfunction |
|
1085 |
|
1086 |
6675
|
1087 function pth = absolute_pathname (pth) |
|
1088 [status, msg, msgid] = fileattrib(pth); |
6729
|
1089 if (status != 1) |
|
1090 error ("could not find the file or path %s", pth); |
|
1091 else |
|
1092 pth = msg.Name; |
|
1093 endif |
6675
|
1094 endfunction |
|
1095 |
|
1096 function repackage (builddir, buildlist) |
|
1097 packages = installed_packages (buildlist, buildlist); |
|
1098 |
|
1099 wd = pwd(); |
|
1100 for i = 1 : length(packages) |
|
1101 pack = packages{i}; |
|
1102 unwind_protect |
|
1103 cd (builddir); |
|
1104 mkdir (pack.name); |
|
1105 mkdir (fullfile (pack.name, "inst")); |
|
1106 copyfile (fullfile (pack.dir, "*"), fullfile (pack.name, "inst")); |
|
1107 movefile (fullfile (pack.name, "inst","packinfo", "*"), pack.name); |
|
1108 if (exist (fullfile (pack.name, "inst","packinfo", ".autoload"), "file")) |
|
1109 unlink (fullfile (pack.name, "inst","packinfo", ".autoload")); |
|
1110 endif |
|
1111 rmdir (fullfile (pack.name, "inst", "packinfo")); |
|
1112 if (exist (fullfile (pack.name, "inst", "doc"), "dir")) |
|
1113 movefile (fullfile (pack.name, "inst", "doc"), pack.name); |
|
1114 endif |
|
1115 if (exist (fullfile (pack.name, "inst", "bin"), "dir")) |
|
1116 movefile (fullfile (pack.name, "inst", "bin"), pack.name); |
|
1117 endif |
6925
|
1118 archdir = fullfile (pack.archprefix, strcat (pack.name, "-", |
|
1119 pack.version), getarch ()); |
6675
|
1120 if (exist (archdir, "dir")) |
|
1121 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) |
|
1122 unlink (fullfile (pack.name, "inst", "PKG_ADD")); |
|
1123 endif |
|
1124 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) |
|
1125 unlink (fullfile (pack.name, "inst", "PKG_DEL")); |
|
1126 endif |
|
1127 if (exist (fullfile (archdir, "PKG_ADD"), "file")) |
|
1128 movefile (fullfile (archdir, "PKG_ADD"), |
|
1129 fullfile (pack.name, "PKG_ADD")); |
|
1130 endif |
|
1131 if (exist (fullfile (archdir, "PKG_DEL"), "file")) |
|
1132 movefile (fullfile (archdir, "PKG_DEL"), |
|
1133 fullfile (pack.name, "PKG_DEL")); |
|
1134 endif |
|
1135 else |
|
1136 if (exist (fullfile (pack.name, "inst", "PKG_ADD"), "file")) |
|
1137 movefile (fullfile (pack.name, "inst", "PKG_ADD"), |
|
1138 fullfile (pack.name, "PKG_ADD")); |
|
1139 endif |
|
1140 if (exist (fullfile (pack.name, "inst", "PKG_DEL"), "file")) |
|
1141 movefile (fullfile (pack.name, "inst", "PKG_DEL"), |
|
1142 fullfile (pack.name, "PKG_DEL")); |
|
1143 endif |
|
1144 endif |
|
1145 tfile = strcat (pack.name, "-", pack.version, ".tar"); |
|
1146 tar (tfile, pack.name); |
6925
|
1147 try |
|
1148 gzip (tfile); |
|
1149 unlink (tfile); |
|
1150 catch |
|
1151 warning ("failed to compress %s", tfile); |
|
1152 end_try_catch |
6675
|
1153 unwind_protect_cleanup |
|
1154 if (exist (pack.name, "dir")) |
|
1155 rm_rf (pack.name); |
|
1156 endif |
|
1157 cd (wd); |
|
1158 end_unwind_protect |
|
1159 endfor |
|
1160 endfunction |
|
1161 |
|
1162 function auto = isautoload (desc) |
6695
|
1163 auto = false; |
|
1164 if (isfield (desc{1}, "autoload")) |
|
1165 a = desc{1}.autoload; |
|
1166 if ((isnumeric (a) && a > 0) |
|
1167 || (ischar (a) && (strcmpi (a, "true") |
6675
|
1168 || strcmpi (a, "on") |
|
1169 || strcmpi (a, "yes") |
|
1170 || strcmpi (a, "1")))) |
6695
|
1171 auto = true; |
|
1172 endif |
6675
|
1173 endif |
|
1174 endfunction |
|
1175 |
6496
|
1176 function prepare_installation (desc, packdir) |
|
1177 ## Is there a pre_install to call? |
|
1178 if (exist (fullfile (packdir, "pre_install.m"), "file")) |
|
1179 wd = pwd (); |
|
1180 try |
|
1181 cd (packdir); |
|
1182 pre_install (desc); |
|
1183 cd (wd); |
|
1184 catch |
|
1185 cd (wd); |
6695
|
1186 rethrow (lasterror ()); |
6496
|
1187 end_try_catch |
|
1188 endif |
|
1189 |
|
1190 ## If the directory "inst" doesn't exist, we create it |
|
1191 inst_dir = fullfile (packdir, "inst"); |
|
1192 if (! exist (inst_dir, "dir")) |
|
1193 [status, msg] = mkdir (inst_dir); |
|
1194 if (status != 1) |
|
1195 rm_rf (desc.dir); |
|
1196 error ("the 'inst' directory did not exist and could not be created: %s", |
|
1197 msg); |
6258
|
1198 endif |
|
1199 endif |
|
1200 endfunction |
|
1201 |
6614
|
1202 function configure_make (desc, packdir, verbose) |
6496
|
1203 ## Perform ./configure, make, make install in "src" |
|
1204 if (exist (fullfile (packdir, "src"), "dir")) |
|
1205 src = fullfile (packdir, "src"); |
|
1206 ## configure |
|
1207 if (exist (fullfile (src, "configure"), "file")) |
7111
|
1208 flags = ""; |
|
1209 if (isempty (getenv ("CC"))) |
|
1210 flags = strcat (flags, " CC=\"", octave_config_info ("CC"), "\""); |
|
1211 endif |
|
1212 if (isempty (getenv ("CXX"))) |
|
1213 flags = strcat (flags, " CXX=\"", octave_config_info ("CXX"), "\""); |
|
1214 endif |
|
1215 if (isempty (getenv ("AR"))) |
|
1216 flags = strcat (flags, " AR=\"", octave_config_info ("AR"), "\""); |
|
1217 endif |
|
1218 if (isempty (getenv ("RANLIB"))) |
|
1219 flags = strcat (flags, " RANLIB=\"", octave_config_info ("RANLIB"), "\""); |
|
1220 endif |
6645
|
1221 [status, output] = shell (strcat ("cd ", src, "; ./configure --prefix=\"", |
7111
|
1222 desc.dir, "\"", flags)); |
6496
|
1223 if (status != 0) |
|
1224 rm_rf (desc.dir); |
|
1225 error ("the configure script returned the following error: %s", output); |
6675
|
1226 elseif (verbose) |
|
1227 printf("%s", output); |
6496
|
1228 endif |
6675
|
1229 |
5801
|
1230 endif |
|
1231 |
6496
|
1232 ## make |
|
1233 if (exist (fullfile (src, "Makefile"), "file")) |
6645
|
1234 [status, output] = shell (strcat ("export INSTALLDIR=\"", desc.dir, |
|
1235 "\"; make -C ", src)); |
6496
|
1236 if (status != 0) |
|
1237 rm_rf (desc.dir); |
|
1238 error ("'make' returned the following error: %s", output); |
6675
|
1239 elseif (verbose) |
|
1240 printf("%s", output); |
6496
|
1241 endif |
5801
|
1242 endif |
|
1243 |
6614
|
1244 ## Copy files to "inst" and "inst/arch" (this is instead of 'make install') |
6496
|
1245 files = fullfile (src, "FILES"); |
|
1246 instdir = fullfile (packdir, "inst"); |
6614
|
1247 archdir = fullfile (packdir, "inst", getarch ()); |
6950
|
1248 |
6655
|
1249 ## Get file names |
6496
|
1250 if (exist (files, "file")) |
|
1251 [fid, msg] = fopen (files, "r"); |
|
1252 if (fid < 0) |
|
1253 error ("couldn't open %s: %s", files, msg); |
5971
|
1254 endif |
6496
|
1255 filenames = char (fread (fid))'; |
|
1256 fclose (fid); |
|
1257 if (filenames(end) == "\n") |
|
1258 filenames(end) = []; |
6258
|
1259 endif |
6655
|
1260 filenames = split_by (filenames, "\n"); |
6496
|
1261 delete_idx = []; |
6655
|
1262 for i = 1:length (filenames) |
|
1263 if (! all (isspace (filenames{i}))) |
|
1264 filenames{i} = fullfile (src, filenames{i}); |
6496
|
1265 else |
|
1266 delete_idx(end+1) = i; |
|
1267 endif |
5971
|
1268 endfor |
6655
|
1269 filenames(delete_idx) = []; |
6496
|
1270 else |
|
1271 m = dir (fullfile (src, "*.m")); |
|
1272 oct = dir (fullfile (src, "*.oct")); |
|
1273 mex = dir (fullfile (src, "*.mex")); |
6614
|
1274 archdependent = ""; |
|
1275 archindependent = ""; |
6496
|
1276 filenames = ""; |
|
1277 if (length (m) > 0) |
|
1278 filenames = sprintf (fullfile (src, "%s "), m.name); |
|
1279 endif |
|
1280 if (length (oct) > 0) |
6675
|
1281 filenames = strcat (filenames, " ", sprintf(fullfile(src, "%s "), ... |
|
1282 oct.name)); |
6496
|
1283 endif |
|
1284 if (length (mex) > 0) |
6675
|
1285 filenames = strcat (filenames, " ", sprintf(fullfile(src, "%s "), ... |
|
1286 mex.name)); |
6496
|
1287 endif |
6614
|
1288 filenames = split_by (filenames, " "); |
5971
|
1289 endif |
5801
|
1290 |
6950
|
1291 ## Split into architecture dependent and independent files |
7024
|
1292 if (isempty (filenames)) |
|
1293 idx = []; |
|
1294 else |
|
1295 idx = cellfun (@(x) is_architecture_dependent (x), filenames); |
|
1296 endif |
6950
|
1297 archdependent = filenames (idx); |
|
1298 archindependent = filenames (!idx); |
|
1299 |
6655
|
1300 ## Copy the files |
6496
|
1301 if (! all (isspace (filenames))) |
6655
|
1302 if (! exist (instdir, "dir")) |
|
1303 mkdir (instdir); |
|
1304 endif |
6614
|
1305 if (! all (isspace (archindependent))) |
6634
|
1306 if (verbose) |
|
1307 printf ("copyfile"); |
|
1308 printf (" %s", archindependent{:}); |
|
1309 printf ("%s\n", instdir); |
|
1310 endif |
6614
|
1311 [status, output] = copyfile (archindependent, instdir); |
|
1312 if (status != 1) |
6496
|
1313 rm_rf (desc.dir); |
|
1314 error ("Couldn't copy files from 'src' to 'inst': %s", output); |
6614
|
1315 endif |
|
1316 endif |
|
1317 if (! all (isspace (archdependent))) |
6634
|
1318 if (verbose) |
|
1319 printf ("copyfile"); |
|
1320 printf (" %s", archdependent{:}); |
|
1321 printf (" %s\n", archdir); |
|
1322 endif |
6655
|
1323 if (! exist (archdir, "dir")) |
|
1324 mkdir (archdir); |
|
1325 endif |
6614
|
1326 [status, output] = copyfile (archdependent, archdir); |
|
1327 if (status != 1) |
|
1328 rm_rf (desc.dir); |
|
1329 error ("Couldn't copy files from 'src' to 'inst': %s", output); |
|
1330 endif |
|
1331 endif |
5801
|
1332 endif |
6496
|
1333 endif |
5801
|
1334 endfunction |
|
1335 |
5971
|
1336 function pkg = extract_pkg (nm, pat) |
5955
|
1337 fid = fopen (nm, "rt"); |
5971
|
1338 pkg = ""; |
5955
|
1339 if (fid >= 0) |
6496
|
1340 while (! feof (fid)) |
5955
|
1341 ln = fgetl (fid); |
|
1342 if (ln > 0) |
6496
|
1343 t = regexp (ln, pat, "tokens"); |
|
1344 if (! isempty (t)) |
|
1345 pkg = strcat (pkg, "\n", t{1}{1}); |
5955
|
1346 endif |
|
1347 endif |
|
1348 endwhile |
6496
|
1349 if (! isempty (pkg)) |
|
1350 pkg = strcat (pkg, "\n"); |
5955
|
1351 endif |
|
1352 fclose (fid); |
|
1353 endif |
|
1354 endfunction |
|
1355 |
6925
|
1356 function create_pkgadddel (desc, packdir, nm, global_install) |
6675
|
1357 instpkg = fullfile (desc.dir, nm); |
|
1358 instfid = fopen (instpkg, "wt"); |
|
1359 ## If it is exists, most of the PKG_* file should go into the |
|
1360 ## architecture dependent directory so that the autoload/mfilename |
|
1361 ## commands work as expected. The only part that doesn't is the |
|
1362 ## part in the main directory. |
6925
|
1363 archdir = fullfile (getarchprefix (desc), strcat (desc.name, "-", |
|
1364 desc.version), getarch ()); |
|
1365 if (exist (getarchdir (desc, global_install), "dir")) |
|
1366 archpkg = fullfile (getarchdir (desc, global_install), nm); |
|
1367 archfid = fopen (archpkg, "at"); |
6675
|
1368 else |
|
1369 archpkg = instpkg; |
|
1370 archfid = instfid; |
|
1371 endif |
6634
|
1372 |
6675
|
1373 if (archfid >= 0 && instfid >= 0) |
5971
|
1374 ## Search all dot-m files for PKG commands |
6233
|
1375 lst = dir (fullfile(packdir, "inst", "*.m")); |
6496
|
1376 for i = 1:length (lst) |
6233
|
1377 nam = fullfile(packdir, "inst", lst(i).name); |
6675
|
1378 fwrite (instfid, extract_pkg (nam, ['^[#%][#%]* *' nm ': *(.*)$'])); |
5955
|
1379 endfor |
|
1380 |
5971
|
1381 ## Search all C++ source files for PKG commands |
6233
|
1382 lst = dir (fullfile(packdir, "src", "*.cc")); |
6496
|
1383 for i = 1:length (lst) |
6233
|
1384 nam = fullfile(packdir, "src", lst(i).name); |
6675
|
1385 fwrite (archfid, extract_pkg (nam, ['^//* *' nm ': *(.*)$'])); |
|
1386 fwrite (archfid, extract_pkg (nam, ['^/\** *' nm ': *(.*) *\*/$'])); |
5955
|
1387 endfor |
|
1388 |
5971
|
1389 ## Add developer included PKG commands |
6496
|
1390 packdirnm = fullfile (packdir, nm); |
|
1391 if (exist (packdirnm, "file")) |
6675
|
1392 fid = fopen (packdirnm, "rt"); |
|
1393 if (fid >= 0) |
|
1394 while (! feof (fid)) |
|
1395 ln = fgets (fid); |
5955
|
1396 if (ln > 0) |
6675
|
1397 fwrite (archfid, ln); |
5955
|
1398 endif |
|
1399 endwhile |
6675
|
1400 fclose (fid); |
5955
|
1401 endif |
|
1402 endif |
5971
|
1403 |
6675
|
1404 ## If the files is empty remove it |
|
1405 fclose (instfid); |
|
1406 t = dir (instpkg); |
5971
|
1407 if (t.bytes <= 0) |
6675
|
1408 unlink (instpkg); |
|
1409 endif |
|
1410 |
|
1411 if (instfid != archfid) |
|
1412 fclose (archfid); |
|
1413 t = dir (archpkg); |
|
1414 if (t.bytes <= 0) |
|
1415 unlink (archpkg); |
|
1416 endif |
5971
|
1417 endif |
5955
|
1418 endif |
|
1419 endfunction |
|
1420 |
6925
|
1421 function copy_files (desc, packdir, global_install) |
6496
|
1422 ## Create the installation directory |
|
1423 if (! exist (desc.dir, "dir")) |
|
1424 [status, output] = mkdir (desc.dir); |
|
1425 if (status != 1) |
|
1426 error ("couldn't create installation directory %s : %s", |
|
1427 desc.dir, output); |
6020
|
1428 endif |
6496
|
1429 endif |
6020
|
1430 |
6925
|
1431 octfiledir = getarchdir (desc); |
|
1432 |
6496
|
1433 ## Copy the files from "inst" to installdir |
|
1434 instdir = fullfile (packdir, "inst"); |
|
1435 if (! dirempty (instdir)) |
|
1436 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); |
|
1437 if (status != 1) |
|
1438 rm_rf (desc.dir); |
|
1439 error ("couldn't copy files to the installation directory"); |
5801
|
1440 endif |
6925
|
1441 if (exist (fullfile (desc.dir, getarch ()), "dir") && |
|
1442 ! strcmp (fullfile (desc.dir, getarch ()), octfiledir)) |
|
1443 if (! exist (octfiledir, "dir")) |
|
1444 ## Can be required to create upto three levels of dirs |
|
1445 octm1 = fileparts (octfiledir); |
|
1446 if (! exist (octm1, "dir")) |
|
1447 octm2 = fileparts (octm1); |
|
1448 if (! exist (octm2, "dir")) |
|
1449 octm3 = fileparts (octm2); |
|
1450 if (! exist (octm3, "dir")) |
|
1451 [status, output] = mkdir (octm3); |
|
1452 if (status != 1) |
|
1453 rm_rf (desc.dir); |
|
1454 error ("couldn't create installation directory %s : %s", |
|
1455 octm3, output); |
|
1456 endif |
|
1457 endif |
|
1458 [status, output] = mkdir (octm2); |
|
1459 if (status != 1) |
|
1460 rm_rf (desc.dir); |
|
1461 error ("couldn't create installation directory %s : %s", |
|
1462 octm2, output); |
|
1463 endif |
|
1464 endif |
|
1465 [status, output] = mkdir (octm1); |
|
1466 if (status != 1) |
|
1467 rm_rf (desc.dir); |
|
1468 error ("couldn't create installation directory %s : %s", |
|
1469 octm1, output); |
|
1470 endif |
|
1471 endif |
|
1472 [status, output] = mkdir (octfiledir); |
|
1473 if (status != 1) |
|
1474 rm_rf (desc.dir); |
|
1475 error ("couldn't create installation directory %s : %s", |
|
1476 octfiledir, output); |
|
1477 endif |
|
1478 endif |
|
1479 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), |
|
1480 octfiledir); |
|
1481 rm_rf (fullfile (desc.dir, getarch ())); |
|
1482 |
|
1483 if (status != 1) |
|
1484 rm_rf (desc.dir); |
|
1485 rm_rf (octfiledir); |
|
1486 error ("couldn't copy files to the installation directory"); |
|
1487 endif |
|
1488 endif |
|
1489 |
6496
|
1490 endif |
5801
|
1491 |
6496
|
1492 ## Create the "packinfo" directory |
|
1493 packinfo = fullfile (desc.dir, "packinfo"); |
|
1494 [status, msg] = mkdir (packinfo); |
|
1495 if (status != 1) |
|
1496 rm_rf (desc.dir); |
6925
|
1497 rm_rf (octfiledir); |
6496
|
1498 error ("couldn't create packinfo directory: %s", msg); |
|
1499 endif |
5801
|
1500 |
6496
|
1501 ## Copy DESCRIPTION |
|
1502 [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo); |
|
1503 if (status != 1) |
6925
|
1504 rm_rf (desc.dir); |
|
1505 rm_rf (octfiledir); |
|
1506 error ("couldn't copy DESCRIPTION: %s", output); |
6496
|
1507 endif |
5801
|
1508 |
6496
|
1509 ## Copy COPYING |
|
1510 [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo); |
|
1511 if (status != 1) |
6925
|
1512 rm_rf (desc.dir); |
|
1513 rm_rf (octfiledir); |
|
1514 error ("couldn't copy COPYING: %s", output); |
6496
|
1515 endif |
5993
|
1516 |
6496
|
1517 ## If the file ChangeLog exists, copy it |
|
1518 fChangeLog = fullfile(packdir, "ChangeLog"); |
|
1519 if (exist (fChangeLog, "file")) |
|
1520 [status, output] = copyfile (fChangeLog, packinfo); |
|
1521 if (status != 1) |
|
1522 rm_rf (desc.dir); |
6925
|
1523 rm_rf (octfiledir); |
6496
|
1524 error ("couldn't copy ChangeLog file: %s", output); |
6254
|
1525 endif |
6496
|
1526 endif |
6254
|
1527 |
6496
|
1528 ## Is there an INDEX file to copy or should we generate one? |
|
1529 fINDEX = fullfile (packdir, "INDEX"); |
|
1530 if (exist(fINDEX, "file")) |
|
1531 [status, output] = copyfile (fINDEX, packinfo); |
|
1532 if (status != 1) |
|
1533 rm_rf (desc.dir); |
6925
|
1534 rm_rf (octfiledir); |
6496
|
1535 error ("couldn't copy INDEX file: %s", output); |
5801
|
1536 endif |
6496
|
1537 else |
|
1538 try |
|
1539 write_INDEX (desc, fullfile (packdir, "inst"), |
6925
|
1540 fullfile (packinfo, "INDEX"), global_install); |
6496
|
1541 catch |
|
1542 rm_rf (desc.dir); |
6925
|
1543 rm_rf (octfiledir); |
6695
|
1544 rethrow (lasterror ()); |
6496
|
1545 end_try_catch |
|
1546 endif |
5971
|
1547 |
6496
|
1548 ## Is there an 'on_uninstall.m' to install? |
|
1549 fon_uninstall = fullfile(packdir, "on_uninstall.m"); |
|
1550 if (exist (fon_uninstall, "file")) |
|
1551 [status, output] = copyfile (fon_uninstall, packinfo); |
|
1552 if (status != 1) |
|
1553 rm_rf (desc.dir); |
6925
|
1554 rm_rf (octfiledir); |
6496
|
1555 error ("couldn't copy on_uninstall.m: %s", output); |
5971
|
1556 endif |
6496
|
1557 endif |
5971
|
1558 |
6496
|
1559 ## Is there a doc/ directory that needs to be installed |
|
1560 docdir = fullfile (packdir, "doc"); |
|
1561 if (exist (docdir, "dir") && ! dirempty (docdir)) |
6925
|
1562 [status, output] = copyfile (docdir, desc.dir); |
6496
|
1563 endif |
|
1564 |
|
1565 ## Is there a bin/ directory that needs to be installed |
6950
|
1566 ## FIXME: Need to treat architecture dependent files in bin/ |
6496
|
1567 bindir = fullfile (packdir, "bin"); |
|
1568 if (exist (bindir, "dir") && ! dirempty (bindir)) |
6925
|
1569 [status, output] = copyfile (bindir, desc.dir); |
6496
|
1570 endif |
5801
|
1571 endfunction |
|
1572 |
6925
|
1573 function finish_installation (desc, packdir, global_install) |
6496
|
1574 ## Is there a post-install to call? |
|
1575 if (exist (fullfile (packdir, "post_install.m"), "file")) |
|
1576 wd = pwd (); |
|
1577 try |
|
1578 cd (packdir); |
|
1579 post_install (desc); |
|
1580 cd (wd); |
|
1581 catch |
|
1582 cd (wd); |
|
1583 rm_rf (desc.dir); |
6925
|
1584 rm_rf (getarchdir (desc), global_install); |
6695
|
1585 rethrow (lasterror ()); |
6496
|
1586 end_try_catch |
|
1587 endif |
5801
|
1588 endfunction |
|
1589 |
|
1590 ## This function makes sure the package contains the |
|
1591 ## essential files. |
6496
|
1592 function verify_directory (dir) |
|
1593 needed_files = {"COPYING", "DESCRIPTION"}; |
|
1594 for f = needed_files |
|
1595 if (! exist (fullfile (dir, f{1}), "file")) |
|
1596 error ("package is missing file: %s", f{1}); |
|
1597 endif |
|
1598 endfor |
5801
|
1599 endfunction |
|
1600 |
|
1601 ## This function parses the DESCRIPTION file |
6496
|
1602 function desc = get_description (filename) |
|
1603 [fid, msg] = fopen (filename, "r"); |
|
1604 if (fid == -1) |
|
1605 error ("the DESCRIPTION file %s could not be read: %s", filename, msg); |
|
1606 endif |
|
1607 |
|
1608 desc = struct (); |
5801
|
1609 |
6496
|
1610 line = fgetl (fid); |
|
1611 while (line != -1) |
|
1612 if (line(1) == "#") |
|
1613 ## Comments, do nothing |
|
1614 elseif (isspace(line(1))) |
|
1615 ## Continuation lines |
|
1616 if (exist ("keyword", "var") && isfield (desc, keyword)) |
|
1617 desc.(keyword) = strcat (desc.(keyword), " ", rstrip(line)); |
|
1618 endif |
5801
|
1619 else |
6496
|
1620 ## Keyword/value pair |
|
1621 colon = find (line == ":"); |
|
1622 if (length (colon) == 0) |
|
1623 disp ("skipping line"); |
|
1624 else |
|
1625 colon = colon(1); |
|
1626 keyword = tolower (strip (line(1:colon-1))); |
|
1627 value = strip (line (colon+1:end)); |
|
1628 if (length (value) == 0) |
|
1629 fclose (fid); |
|
1630 error ("the keyword %s has an empty value", desc.keywords{end}); |
|
1631 endif |
|
1632 desc.(keyword) = value; |
|
1633 endif |
5801
|
1634 endif |
6496
|
1635 line = fgetl (fid); |
|
1636 endwhile |
|
1637 fclose (fid); |
|
1638 |
|
1639 ## Make sure all is okay |
|
1640 needed_fields = {"name", "version", "date", "title", ... |
|
1641 "author", "maintainer", "description"}; |
|
1642 for f = needed_fields |
|
1643 if (! isfield (desc, f{1})) |
|
1644 error ("description is missing needed field %s", f{1}); |
|
1645 endif |
|
1646 endfor |
|
1647 desc.version = fix_version (desc.version); |
|
1648 if (isfield (desc, "depends")) |
|
1649 desc.depends = fix_depends (desc.depends); |
|
1650 else |
|
1651 desc.depends = ""; |
|
1652 endif |
|
1653 desc.name = tolower (desc.name); |
5801
|
1654 endfunction |
|
1655 |
|
1656 ## Makes sure the version string v is a valid x.y.z version string |
|
1657 ## Examples: "0.1" => "0.1.0", "monkey" => error(...) |
6496
|
1658 function out = fix_version (v) |
|
1659 dots = find (v == "."); |
|
1660 if (length (dots) == 1) |
|
1661 major = str2num (v(1:dots-1)); |
|
1662 minor = str2num (v(dots+1:end)); |
|
1663 if (length (major) != 0 && length (minor) != 0) |
|
1664 out = sprintf ("%d.%d.0", major, minor); |
|
1665 return; |
5801
|
1666 endif |
6496
|
1667 elseif (length (dots) == 2) |
|
1668 major = str2num (v(1:dots(1)-1)); |
|
1669 minor = str2num (v(dots(1)+1:dots(2)-1)); |
|
1670 rev = str2num (v(dots(2)+1:end)); |
|
1671 if (length (major) != 0 && length (minor) != 0 && length (rev) != 0) |
|
1672 out = sprintf ("%d.%d.%d", major, minor, rev); |
|
1673 return; |
|
1674 endif |
|
1675 endif |
|
1676 error ("bad version string: %s", v); |
5801
|
1677 endfunction |
|
1678 |
|
1679 ## Makes sure the depends field is of the right format. |
|
1680 ## This function returns a cell of structures with the following fields: |
|
1681 ## package, version, operator |
6496
|
1682 function deps_cell = fix_depends (depends) |
|
1683 deps = split_by (tolower (depends), ","); |
|
1684 deps_cell = cell (1, length (deps)); |
|
1685 |
|
1686 ## For each dependency |
|
1687 for i = 1:length (deps) |
|
1688 dep = deps{i}; |
|
1689 lpar = find (dep == "("); |
|
1690 rpar = find (dep == ")"); |
|
1691 ## Does the dependency specify a version |
|
1692 ## Example: package(>= version) |
|
1693 if (length (lpar) == 1 && length (rpar) == 1) |
|
1694 package = tolower (strip (dep(1:lpar-1))); |
|
1695 sub = dep(lpar(1)+1:rpar(1)-1); |
|
1696 parts = split_by (sub, " "); |
|
1697 idx = []; |
|
1698 for r = 1:size (parts, 1) |
|
1699 if (length (parts{r}) > 0) |
|
1700 idx(end+1) = r; |
|
1701 endif |
|
1702 endfor |
|
1703 |
|
1704 if (length (idx) != 2) |
|
1705 error ("incorrect syntax for dependency `%s' in the DESCRIPTION file\n", |
|
1706 dep); |
|
1707 endif |
|
1708 operator = parts{idx(1)}; |
|
1709 if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="}))) |
|
1710 error ("unsupported operator: %s", operator); |
|
1711 endif |
|
1712 version = fix_version (parts{idx(2)}); |
|
1713 |
|
1714 ## If no version is specified for the dependency |
|
1715 ## we say that the version should be greater than |
|
1716 ## or equal to 0.0.0 |
|
1717 else |
|
1718 package = tolower (strip (dep)); |
|
1719 operator = ">="; |
|
1720 version = "0.0.0"; |
|
1721 endif |
|
1722 deps_cell{i} = struct ("package", package, "operator", operator, |
|
1723 "version", version); |
|
1724 endfor |
5801
|
1725 endfunction |
|
1726 |
|
1727 ## Strips the text of spaces from the right |
|
1728 ## Example: " hello world " => " hello world" (XXX: is this the same as deblank?) |
6496
|
1729 function text = rstrip (text) |
|
1730 chars = find (! isspace (text)); |
|
1731 if (length (chars) > 0) |
|
1732 ## XXX: shouldn't it be text = text(1:chars(end)); |
|
1733 text = text (chars(1):end); |
|
1734 else |
|
1735 text = ""; |
|
1736 endif |
5801
|
1737 endfunction |
|
1738 |
|
1739 ## Strips the text of spaces from the left and the right |
|
1740 ## Example: " hello world " => "hello world" |
6496
|
1741 function text = strip (text) |
|
1742 chars = find (! isspace (text)); |
|
1743 if (length (chars) > 0) |
|
1744 text = text(chars(1):chars(end)); |
|
1745 else |
|
1746 text = ""; |
|
1747 endif |
5801
|
1748 endfunction |
|
1749 |
|
1750 ## Splits the text into a cell array of strings by sep |
|
1751 ## Example: "A, B" => {"A", "B"} (with sep = ",") |
6496
|
1752 function out = split_by (text, sep) |
|
1753 text_matrix = split (text, sep); |
|
1754 num_words = size (text_matrix, 1); |
|
1755 out = cell (num_words, 1); |
|
1756 for i = 1:num_words |
|
1757 out{i} = strip (text_matrix(i, :)); |
|
1758 endfor |
5801
|
1759 endfunction |
|
1760 |
|
1761 ## Creates an INDEX file for a package that doesn't provide one. |
|
1762 ## 'desc' describes the package. |
7497
|
1763 ## 'dir' is the 'inst' direcotry in temporary directory. |
5801
|
1764 ## 'INDEX' is the name (including path) of resulting INDEX file. |
6925
|
1765 function write_INDEX (desc, dir, INDEX, global_install) |
6496
|
1766 ## Get names of functions in dir |
|
1767 [files, err, msg] = readdir (dir); |
|
1768 if (err) |
|
1769 error ("couldn't read directory %s: %s", dir, msg); |
|
1770 endif |
|
1771 |
6634
|
1772 ## Check for architecture dependent files |
6925
|
1773 tmpdir = getarchdir (desc); |
6634
|
1774 if (exist (tmpdir, "dir")) |
|
1775 [files2, err, msg] = readdir (tmpdir); |
|
1776 if (err) |
|
1777 error ("couldn't read directory %s: %s", tmpdir, msg); |
|
1778 endif |
|
1779 files = [files; files2]; |
|
1780 endif |
|
1781 |
6496
|
1782 functions = {}; |
|
1783 for i = 1:length (files) |
|
1784 file = files{i}; |
|
1785 lf = length (file); |
|
1786 if (lf > 2 && strcmp (file(end-1:end), ".m")) |
|
1787 functions{end+1} = file(1:end-2); |
|
1788 elseif (lf > 4 && strcmp (file(end-3:end), ".oct")) |
|
1789 functions{end+1} = file(1:end-4); |
5801
|
1790 endif |
6496
|
1791 endfor |
|
1792 |
|
1793 ## Does desc have a categories field? |
|
1794 if (! isfield (desc, "categories")) |
|
1795 error ("the DESCRIPTION file must have a Categories field, when no INDEX file is given"); |
|
1796 endif |
|
1797 categories = split_by (desc.categories, ","); |
|
1798 if (length (categories) < 1) |
|
1799 error ("the Category field is empty"); |
|
1800 endif |
|
1801 |
|
1802 ## Write INDEX |
|
1803 fid = fopen (INDEX, "w"); |
|
1804 if (fid == -1) |
|
1805 error ("couldn't open %s for writing.", INDEX); |
|
1806 endif |
|
1807 fprintf (fid, "%s >> %s\n", desc.name, desc.title); |
|
1808 fprintf (fid, "%s\n", categories{1}); |
|
1809 fprintf (fid, " %s\n", functions{:}); |
|
1810 fclose (fid); |
5801
|
1811 endfunction |
|
1812 |
6820
|
1813 function bad_deps = get_unsatisfied_deps (desc, installed_pkgs_lst) |
6496
|
1814 bad_deps = {}; |
5801
|
1815 |
6496
|
1816 ## For each dependency |
|
1817 for i = 1:length (desc.depends) |
|
1818 dep = desc.depends{i}; |
5801
|
1819 |
6496
|
1820 ## Is the current dependency Octave? |
|
1821 if (strcmp (dep.package, "octave")) |
|
1822 if (! compare_versions (OCTAVE_VERSION, dep.version, dep.operator)) |
|
1823 bad_deps{end+1} = dep; |
6258
|
1824 endif |
6496
|
1825 ## Is the current dependency not Octave? |
|
1826 else |
|
1827 ok = false; |
6820
|
1828 for i = 1:length (installed_pkgs_lst) |
|
1829 cur_name = installed_pkgs_lst{i}.name; |
|
1830 cur_version = installed_pkgs_lst{i}.version; |
6496
|
1831 if (strcmp (dep.package, cur_name) |
|
1832 && compare_versions (cur_version, dep.version, dep.operator)) |
|
1833 ok = true; |
|
1834 break; |
6258
|
1835 endif |
|
1836 endfor |
6496
|
1837 if (! ok) |
|
1838 bad_deps{end+1} = dep; |
|
1839 endif |
5801
|
1840 endif |
6496
|
1841 endfor |
|
1842 endfunction |
|
1843 |
|
1844 function [out1, out2] = installed_packages (local_list, global_list) |
|
1845 ## Get the list of installed packages |
|
1846 try |
|
1847 local_packages = load (local_list).local_packages; |
|
1848 catch |
|
1849 local_packages = {}; |
|
1850 end_try_catch |
|
1851 try |
6675
|
1852 global_packages = load (global_list).global_packages; |
6496
|
1853 catch |
|
1854 global_packages = {}; |
|
1855 end_try_catch |
6820
|
1856 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
6496
|
1857 |
|
1858 ## Eliminate duplicates in the installed package list. |
|
1859 ## Locally installed packages take precedence |
|
1860 dup = []; |
6820
|
1861 for i = 1:length (installed_pkgs_lst) |
6496
|
1862 if (find (dup, i)) |
|
1863 continue; |
5801
|
1864 endif |
6820
|
1865 for j = (i+1):length (installed_pkgs_lst) |
6496
|
1866 if (find (dup, j)) |
|
1867 continue; |
|
1868 endif |
6820
|
1869 if (strcmp (installed_pkgs_lst{i}.name, installed_pkgs_lst{j}.name)) |
6496
|
1870 dup = [dup, j]; |
|
1871 endif |
5987
|
1872 endfor |
6496
|
1873 endfor |
|
1874 if (! isempty(dup)) |
6820
|
1875 installed_pkgs_lst(dup) = []; |
6496
|
1876 endif |
|
1877 |
6616
|
1878 ## Now check if the package is loaded |
6645
|
1879 tmppath = strrep (path(), "\\", "/"); |
6820
|
1880 for i = 1:length (installed_pkgs_lst) |
|
1881 if (findstr (tmppath, strrep (installed_pkgs_lst{i}.dir, "\\", "/"))) |
|
1882 installed_pkgs_lst{i}.loaded = true; |
6616
|
1883 else |
6820
|
1884 installed_pkgs_lst{i}.loaded = false; |
6616
|
1885 endif |
|
1886 endfor |
6675
|
1887 for i = 1:length (local_packages) |
6776
|
1888 if (findstr (tmppath, strrep (local_packages{i}.dir, "\\", "/"))) |
6675
|
1889 local_packages{i}.loaded = true; |
|
1890 else |
|
1891 local_packages{i}.loaded = false; |
|
1892 endif |
|
1893 endfor |
|
1894 for i = 1:length (global_packages) |
6776
|
1895 if (findstr (tmppath, strrep (global_packages{i}.dir, "\\", "/"))) |
6675
|
1896 global_packages{i}.loaded = true; |
|
1897 else |
|
1898 global_packages{i}.loaded = false; |
|
1899 endif |
|
1900 endfor |
6616
|
1901 |
6496
|
1902 ## Should we return something? |
|
1903 if (nargout == 2) |
|
1904 out1 = local_packages; |
|
1905 out2 = global_packages; |
|
1906 return; |
|
1907 elseif (nargout == 1) |
6820
|
1908 out1 = installed_pkgs_lst; |
6496
|
1909 return; |
|
1910 endif |
|
1911 |
|
1912 ## We shouldn't return something, so we'll print something |
6820
|
1913 num_packages = length (installed_pkgs_lst); |
6496
|
1914 if (num_packages == 0) |
|
1915 printf ("no packages installed.\n"); |
|
1916 return; |
|
1917 endif |
|
1918 |
|
1919 ## Compute the maximal lengths of name, version, and dir |
|
1920 h1 = "Package Name"; |
|
1921 h2 = "Version"; |
|
1922 h3 = "Installation directory"; |
|
1923 max_name_length = length (h1); |
|
1924 max_version_length = length (h2); |
|
1925 names = cell (num_packages, 1); |
|
1926 for i = 1:num_packages |
|
1927 max_name_length = max (max_name_length, |
6820
|
1928 length (installed_pkgs_lst{i}.name)); |
6496
|
1929 max_version_length = max (max_version_length, |
6820
|
1930 length (installed_pkgs_lst{i}.version)); |
|
1931 names{i} = installed_pkgs_lst{i}.name; |
6496
|
1932 endfor |
6698
|
1933 max_dir_length = terminal_size()(2) - max_name_length - ... |
|
1934 max_version_length - 7; |
|
1935 if (max_dir_length < 20) |
|
1936 max_dir_length = Inf; |
|
1937 endif |
|
1938 |
6616
|
1939 h1 = postpad (h1, max_name_length + 1, " "); |
6496
|
1940 h2 = postpad (h2, max_version_length, " ");; |
|
1941 |
|
1942 ## Print a header |
|
1943 header = sprintf("%s | %s | %s\n", h1, h2, h3); |
|
1944 printf (header); |
|
1945 tmp = sprintf (repmat ("-", 1, length(header)-1)); |
|
1946 tmp(length(h1)+2) = "+"; |
|
1947 tmp(length(h1)+length(h2)+5) = "+"; |
|
1948 printf ("%s\n", tmp); |
|
1949 |
|
1950 ## Print the packages |
6616
|
1951 format = sprintf ("%%%ds %%1s| %%%ds | %%s\n", max_name_length, |
6496
|
1952 max_version_length); |
|
1953 [dummy, idx] = sort (names); |
|
1954 for i = 1:num_packages |
6820
|
1955 cur_name = installed_pkgs_lst{idx(i)}.name; |
|
1956 cur_version = installed_pkgs_lst{idx(i)}.version; |
|
1957 cur_dir = installed_pkgs_lst{idx(i)}.dir; |
6698
|
1958 if (length (cur_dir) > max_dir_length) |
|
1959 first_char = length (cur_dir) - max_dir_length + 4; |
|
1960 first_filesep = strfind (cur_dir(first_char:end), filesep()); |
|
1961 if (! isempty (first_filesep)) |
|
1962 cur_dir = strcat ("...", |
|
1963 cur_dir((first_char + first_filesep(1) - 1):end)); |
|
1964 else |
|
1965 cur_dir = strcat ("...", cur_dir(first_char:end)); |
|
1966 endif |
|
1967 endif |
6820
|
1968 if (installed_pkgs_lst{idx(i)}.loaded) |
6616
|
1969 cur_loaded = "*"; |
|
1970 else |
|
1971 cur_loaded = " "; |
|
1972 endif |
|
1973 printf (format, cur_name, cur_loaded, cur_version, cur_dir); |
6496
|
1974 endfor |
5801
|
1975 endfunction |
|
1976 |
6496
|
1977 function load_packages (files, handle_deps, local_list, global_list) |
6820
|
1978 installed_pkgs_lst = installed_packages (local_list, global_list); |
|
1979 num_packages = length (installed_pkgs_lst); |
6496
|
1980 |
|
1981 ## Read package names and installdirs into a more convenient format |
|
1982 pnames = pdirs = cell (1, num_packages); |
|
1983 for i = 1:num_packages |
6820
|
1984 pnames{i} = installed_pkgs_lst{i}.name; |
|
1985 pdirs{i} = installed_pkgs_lst{i}.dir; |
6496
|
1986 endfor |
|
1987 |
|
1988 ## load all |
|
1989 if (length (files) == 1 && strcmp (files{1}, "all")) |
6820
|
1990 idx = [1:length(installed_pkgs_lst)]; |
6496
|
1991 ## load auto |
6695
|
1992 elseif (length (files) == 1 && strcmp (files{1}, "auto")) |
|
1993 idx = []; |
6820
|
1994 for i = 1:length (installed_pkgs_lst) |
6496
|
1995 if (exist (fullfile (pdirs{i}, "packinfo", ".autoload"), "file")) |
6695
|
1996 idx (end + 1) = i; |
6496
|
1997 endif |
6037
|
1998 endfor |
6496
|
1999 ## load package_name1 ... |
|
2000 else |
6695
|
2001 idx = []; |
6496
|
2002 for i = 1:length (files) |
6695
|
2003 idx2 = find (strcmp (pnames, files{i})); |
|
2004 if (! any (idx2)) |
6496
|
2005 error ("package %s is not installed", files{i}); |
|
2006 endif |
6695
|
2007 idx (end + 1) = idx2; |
6496
|
2008 endfor |
|
2009 endif |
6037
|
2010 |
6695
|
2011 ## Load the packages, but take care of the ordering of dependencies |
6925
|
2012 load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, true); |
5801
|
2013 endfunction |
5928
|
2014 |
6496
|
2015 function unload_packages (files, handle_deps, local_list, global_list) |
6820
|
2016 installed_pkgs_lst = installed_packages (local_list, global_list); |
|
2017 num_packages = length (installed_pkgs_lst); |
6496
|
2018 |
|
2019 ## Read package names and installdirs into a more convenient format |
|
2020 pnames = pdirs = cell (1, num_packages); |
|
2021 for i = 1:num_packages |
6820
|
2022 pnames{i} = installed_pkgs_lst{i}.name; |
|
2023 pdirs{i} = installed_pkgs_lst{i}.dir; |
|
2024 pdeps{i} = installed_pkgs_lst{i}.depends; |
6496
|
2025 endfor |
|
2026 |
|
2027 ## Get the current octave path |
|
2028 p = split_by (path(), pathsep ()); |
6203
|
2029 |
6496
|
2030 ## unload all |
|
2031 if (length (files) == 1 && strcmp (files{1}, "all")) |
|
2032 dirs = pdirs; |
6925
|
2033 desc = installed_pkgs_lst; |
6496
|
2034 ## unload package_name1 ... |
|
2035 else |
|
2036 dirs = {}; |
6925
|
2037 desc = {}; |
6496
|
2038 for i = 1:length (files) |
7208
|
2039 idx = strcmp (pnames, files{i}); |
6496
|
2040 if (! any (idx)) |
|
2041 error ("package %s is not installed", files{i}); |
|
2042 endif |
7208
|
2043 dirs{end+1} = pdirs{idx}; |
|
2044 desc{end+1} = installed_pkgs_lst{idx}; |
6496
|
2045 endfor |
|
2046 endif |
|
2047 |
6614
|
2048 ## Check for architecture dependent directories |
|
2049 archdirs = {}; |
|
2050 for i = 1:length (dirs) |
7208
|
2051 tmpdir = getarchdir (desc{i}); |
6614
|
2052 if (exist (tmpdir, "dir")) |
7208
|
2053 archdirs{end+1} = dirs{i}; |
|
2054 archdirs{end+1} = tmpdir; |
6925
|
2055 else |
7208
|
2056 archdirs{end+1} = dirs{i}; |
6614
|
2057 endif |
|
2058 endfor |
|
2059 |
6496
|
2060 ## Unload the packages |
6925
|
2061 for i = 1:length (archdirs) |
|
2062 d = archdirs{i}; |
6496
|
2063 idx = strcmp (p, d); |
|
2064 if (any (idx)) |
|
2065 rmpath (d); |
|
2066 ## XXX: We should also check if we need to remove items from EXEC_PATH |
6203
|
2067 endif |
6496
|
2068 endfor |
6203
|
2069 endfunction |
|
2070 |
5928
|
2071 function [status_out, msg_out] = rm_rf (dir) |
6925
|
2072 if (exist (dir)) |
|
2073 crr = confirm_recursive_rmdir (); |
|
2074 unwind_protect |
|
2075 confirm_recursive_rmdir (false); |
|
2076 [status, msg] = rmdir (dir, "s"); |
|
2077 unwind_protect_cleanup |
|
2078 confirm_recursive_rmdir (crr); |
|
2079 end_unwind_protect |
|
2080 else |
|
2081 status = 1; |
|
2082 msg = ""; |
|
2083 endif |
5928
|
2084 if (nargout > 0) |
|
2085 status_out = status; |
|
2086 endif |
|
2087 if (nargout > 1) |
|
2088 msg_out = msg; |
|
2089 endif |
|
2090 endfunction |
5971
|
2091 |
|
2092 function emp = dirempty (nm, ign) |
6925
|
2093 if (exist (nm, "dir")) |
|
2094 if (nargin < 2) |
|
2095 ign = {".", ".."}; |
|
2096 else |
|
2097 ign = [{".", ".."}, ign]; |
|
2098 endif |
|
2099 l = dir (nm); |
|
2100 for i = 1:length (l) |
|
2101 found = false; |
|
2102 for j = 1:length (ign) |
|
2103 if (strcmp (l(i).name, ign{j})) |
|
2104 found = true; |
|
2105 break; |
|
2106 endif |
|
2107 endfor |
|
2108 if (! found) |
|
2109 emp = false; |
|
2110 return |
5971
|
2111 endif |
|
2112 endfor |
6925
|
2113 emp = true; |
|
2114 else |
|
2115 emp = true; |
|
2116 endif |
5971
|
2117 endfunction |
6614
|
2118 |
|
2119 function arch = getarch () |
6675
|
2120 persistent _arch = strcat (octave_config_info("canonical_host_type"), ... |
|
2121 "-", octave_config_info("api_version")); |
6614
|
2122 arch = _arch; |
|
2123 endfunction |
6645
|
2124 |
6925
|
2125 function archprefix = getarchprefix (desc, global_install) |
|
2126 if ((nargin == 2 && global_install) || (nargin < 2 && issuperuser ())) |
|
2127 archprefix = fullfile (octave_config_info ("libexecdir"), "octave", |
|
2128 "packages", strcat(desc.name, "-", desc.version)); |
|
2129 else |
|
2130 archprefix = desc.dir; |
|
2131 endif |
|
2132 endfunction |
|
2133 |
|
2134 function archdir = getarchdir (desc) |
|
2135 archdir = fullfile (desc.archprefix, getarch()); |
|
2136 endfunction |
|
2137 |
|
2138 function s = issuperuser () |
|
2139 if ((ispc () && ! isunix ()) || (geteuid() == 0)) |
|
2140 s = true; |
|
2141 else |
|
2142 s = false; |
|
2143 endif |
|
2144 endfunction |
|
2145 |
6645
|
2146 function [status, output] = shell (cmd) |
|
2147 persistent have_sh; |
|
2148 |
|
2149 cmd = strrep (cmd, "\\", "/"); |
|
2150 if (ispc () && ! isunix ()) |
|
2151 if (isempty(have_sh)) |
|
2152 if (system("sh.exe -c \"exit\"")) |
|
2153 have_sh = false; |
|
2154 else |
|
2155 have_sh = true; |
|
2156 endif |
|
2157 endif |
|
2158 if (have_sh) |
6675
|
2159 [status, output] = system (strcat ("sh.exe -c \"", cmd, "\"")); |
6645
|
2160 else |
|
2161 error ("Can not find the command shell") |
|
2162 endif |
|
2163 else |
|
2164 [status, output] = system (cmd); |
|
2165 endif |
|
2166 endfunction |
6695
|
2167 |
|
2168 function newdesc = save_order (desc) |
|
2169 newdesc = {}; |
|
2170 for i = 1 : length(desc) |
|
2171 deps = desc{i}.depends; |
|
2172 if (isempty (deps) || (length (deps) == 1 && |
|
2173 strcmp(deps{1}.package, "octave"))) |
|
2174 newdesc {end + 1} = desc{i}; |
|
2175 else |
|
2176 tmpdesc = {}; |
|
2177 for k = 1 : length (deps) |
|
2178 for j = 1 : length (desc) |
|
2179 if (strcmp (desc{j}.name, deps{k}.package)) |
7208
|
2180 tmpdesc{end+1} = desc{j}; |
6695
|
2181 break; |
|
2182 endif |
|
2183 endfor |
|
2184 endfor |
|
2185 if (! isempty (tmpdesc)) |
|
2186 newdesc = {newdesc{:}, save_order(tmpdesc){:}, desc{i}}; |
|
2187 else |
7208
|
2188 newdesc{end+1} = desc{i}; |
6695
|
2189 endif |
|
2190 endif |
|
2191 endfor |
|
2192 ## Eliminate the duplicates |
|
2193 idx = []; |
|
2194 for i = 1 : length (newdesc) |
|
2195 for j = (i + 1) : length (newdesc) |
|
2196 if (strcmp (newdesc{i}.name, newdesc{j}.name)) |
|
2197 idx (end + 1) = j; |
|
2198 endif |
|
2199 endfor |
|
2200 endfor |
|
2201 newdesc(idx) = []; |
|
2202 endfunction |
|
2203 |
6925
|
2204 function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst, |
|
2205 global_install) |
6820
|
2206 idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst); |
6695
|
2207 dirs = {}; |
|
2208 execpath = EXEC_PATH (); |
|
2209 for i = idx; |
6820
|
2210 ndir = installed_pkgs_lst{i}.dir; |
7208
|
2211 dirs{end+1} = ndir; |
6695
|
2212 if (exist (fullfile (dirs{end}, "bin"), "dir")) |
|
2213 execpath = strcat (fullfile(dirs{end}, "bin"), ":", execpath); |
|
2214 endif |
7208
|
2215 tmpdir = getarchdir (installed_pkgs_lst{i}); |
6695
|
2216 if (exist (tmpdir, "dir")) |
|
2217 dirs{end + 1} = tmpdir; |
6950
|
2218 if (exist (fullfile (dirs{end}, "bin"), "dir")) |
|
2219 execpath = strcat (fullfile(dirs{end}, "bin"), ":", execpath); |
|
2220 endif |
6695
|
2221 endif |
|
2222 endfor |
|
2223 |
|
2224 ## Load the packages |
|
2225 if (length (dirs) > 0) |
|
2226 addpath (dirs{:}); |
|
2227 endif |
|
2228 |
|
2229 ## Add the binaries to exec_path |
|
2230 if (! strcmp (EXEC_PATH, execpath)) |
|
2231 EXEC_PATH (execpath); |
|
2232 endif |
|
2233 endfunction |
|
2234 |
6820
|
2235 function idx = load_package_dirs (lidx, idx, handle_deps, installed_pkgs_lst) |
6695
|
2236 for i = lidx |
6820
|
2237 if (isfield (installed_pkgs_lst{i}, "loaded") && |
|
2238 installed_pkgs_lst{i}.loaded) |
6695
|
2239 continue; |
|
2240 else |
|
2241 if (handle_deps) |
6820
|
2242 deps = installed_pkgs_lst{i}.depends; |
6695
|
2243 if ((length (deps) > 1) || (length (deps) == 1 && |
|
2244 ! strcmp(deps{1}.package, "octave"))) |
|
2245 tmplidx = []; |
|
2246 for k = 1 : length (deps) |
6820
|
2247 for j = 1 : length (installed_pkgs_lst) |
|
2248 if (strcmp (installed_pkgs_lst{j}.name, deps{k}.package)) |
6695
|
2249 tmplidx (end + 1) = j; |
|
2250 break; |
|
2251 endif |
|
2252 endfor |
|
2253 endfor |
|
2254 idx = load_package_dirs (tmplidx, idx, handle_deps, |
6820
|
2255 installed_pkgs_lst); |
6695
|
2256 endif |
|
2257 endif |
|
2258 if (isempty (find(idx == i))) |
|
2259 idx (end + 1) = i; |
|
2260 endif |
|
2261 endif |
|
2262 endfor |
|
2263 endfunction |
6950
|
2264 |
|
2265 function dep = is_architecture_dependent (nm) |
7329
|
2266 persistent archdepsuffix = {".oct",".mex",".a",".lib",".so",".so.*",".dll","dylib"}; |
6950
|
2267 |
|
2268 dep = false; |
|
2269 for i = 1 : length (archdepsuffix) |
7208
|
2270 ext = archdepsuffix{i}; |
6950
|
2271 if (ext(end) == "*") |
|
2272 isglob = true; |
|
2273 ext(end) = []; |
|
2274 else |
|
2275 isglob = false; |
|
2276 endif |
|
2277 pos = findstr (nm, ext); |
|
2278 if (pos) |
7208
|
2279 if (! isglob && (length(nm) - pos(end) != length(ext) - 1)) |
6950
|
2280 continue; |
|
2281 endif |
|
2282 dep = true; |
|
2283 break; |
|
2284 endif |
|
2285 endfor |
|
2286 endfunction |
7497
|
2287 |
|
2288 |