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