comparison scripts/pkg/pkg.m @ 6614:3a53d0f3e0e4

[project @ 2007-05-12 05:50:03 by dbateman]
author dbateman
date Sat, 12 May 2007 05:50:04 +0000
parents 3ea308b4b37e
children 66e30383481b
comparison
equal deleted inserted replaced
6613:b85dd243601d 6614:3a53d0f3e0e4
42 ## even if the package requests that it is. 42 ## even if the package requests that it is.
43 ## 43 ##
44 ## If @var{option} is @code{-auto} the package manager will 44 ## If @var{option} is @code{-auto} the package manager will
45 ## automatically load the installed package when starting Octave, 45 ## automatically load the installed package when starting Octave,
46 ## even if the package requests that it isn't. 46 ## even if the package requests that it isn't.
47 ##
48 ## Final if @var{option} is @code{-verbose} the package manager will
49 ## print the output of all of the commands that are performed
47 ## @item uninstall 50 ## @item uninstall
48 ## Uninstall named packages. For example, 51 ## Uninstall named packages. For example,
49 ## @example 52 ## @example
50 ## pkg uninstall image 53 ## pkg uninstall image
51 ## @end example 54 ## @end example
150 endif 153 endif
151 files = {}; 154 files = {};
152 deps = true; 155 deps = true;
153 auto = 0; 156 auto = 0;
154 action = "none"; 157 action = "none";
158 verbose = false;
155 for i = 1:length (varargin) 159 for i = 1:length (varargin)
156 switch (varargin{i}) 160 switch (varargin{i})
157 case "-nodeps" 161 case "-nodeps"
158 deps = false; 162 deps = false;
159 case "-noauto" 163 case "-noauto"
160 auto = -1; 164 auto = -1;
161 case "-auto" 165 case "-auto"
162 auto = 1; 166 auto = 1;
167 case "-verbose"
168 verbose = true;
163 case {"list", "install", "uninstall", "load", "unload", ... 169 case {"list", "install", "uninstall", "load", "unload", ...
164 "prefix", "local_list", "global_list"} 170 "prefix", "local_list", "global_list"}
165 action = varargin{i}; 171 action = varargin{i};
166 otherwise 172 otherwise
167 files{end+1} = varargin{i}; 173 files{end+1} = varargin{i};
184 190
185 case "install" 191 case "install"
186 if (length (files) == 0) 192 if (length (files) == 0)
187 error ("you must specify at least one filename when calling 'pkg install'"); 193 error ("you must specify at least one filename when calling 'pkg install'");
188 endif 194 endif
189 install (files, deps, auto, prefix, local_list, global_list); 195 install (files, deps, auto, prefix, verbose, local_list, global_list);
190 196
191 case "uninstall" 197 case "uninstall"
192 if (length (files) == 0) 198 if (length (files) == 0)
193 error ("you must specify at least one package when calling 'pkg uninstall'"); 199 error ("you must specify at least one package when calling 'pkg uninstall'");
194 endif 200 endif
195 uninstall (files, deps, local_list, global_list); 201 uninstall (files, deps, verbose, local_list, global_list);
196 202
197 case "load" 203 case "load"
198 if (length (files) == 0) 204 if (length (files) == 0)
199 error ("you must specify at least one package, 'all' or 'auto' when calling 'pkg load'"); 205 error ("you must specify at least one package, 'all' or 'auto' when calling 'pkg load'");
200 endif 206 endif
258 auto = true; 264 auto = true;
259 endif 265 endif
260 endif 266 endif
261 endfunction 267 endfunction
262 268
263 function install (files, handle_deps, autoload, prefix, local_list, global_list) 269 function install (files, handle_deps, autoload, prefix, verbose, local_list, global_list)
264 global_install = issuperuser (); 270 global_install = issuperuser ();
265 271
266 # Check that the directory in prefix exist. If it doesn't: create it! 272 # Check that the directory in prefix exist. If it doesn't: create it!
267 if (! exist (prefix, "dir")) 273 if (! exist (prefix, "dir"))
268 warning ("creating installation directory %s", prefix); 274 warning ("creating installation directory %s", prefix);
388 try 394 try
389 for i = 1:length (descriptions) 395 for i = 1:length (descriptions)
390 desc = descriptions{i}; 396 desc = descriptions{i};
391 pdir = packdirs{i}; 397 pdir = packdirs{i};
392 prepare_installation (desc, pdir); 398 prepare_installation (desc, pdir);
393 configure_make (desc, pdir); 399 configure_make (desc, pdir, verbose);
394 endfor 400 endfor
395 catch 401 catch
396 ## Something went wrong, delete tmpdirs 402 ## Something went wrong, delete tmpdirs
397 for i = 1:length (tmpdirs) 403 for i = 1:length (tmpdirs)
398 rm_rf (tmpdirs{i}); 404 rm_rf (tmpdirs{i});
401 end_try_catch 407 end_try_catch
402 408
403 ## Uninstall the packages that will be replaced 409 ## Uninstall the packages that will be replaced
404 try 410 try
405 for i = packages_to_uninstall 411 for i = packages_to_uninstall
406 uninstall ({installed_packages{i}.name}, false, local_list, 412 uninstall ({installed_packages{i}.name}, false, verbose, local_list,
407 global_list); 413 global_list);
408 endfor 414 endfor
409 catch 415 catch
410 ## Something went wrong, delete tmpdirs 416 ## Something went wrong, delete tmpdirs
411 for i = 1:length (tmpdirs) 417 for i = 1:length (tmpdirs)
487 endif 493 endif
488 endfor 494 endfor
489 495
490 ## Add the newly installed packages to the path, so the user 496 ## Add the newly installed packages to the path, so the user
491 ## can begin usings them. 497 ## can begin usings them.
498 arch = getarch();
492 if (length (descriptions) > 0) 499 if (length (descriptions) > 0)
493 dirs = cell (1, length (descriptions)); 500 dirs = {};
494 for i = 1:length (descriptions) 501 for i = 1:length (descriptions)
495 dirs{i} = descriptions{i}.dir; 502 dirs{end + 1} = descriptions{i}.dir;
503 if (exist (fullfile (descriptions{i}.dir, arch), "dir"))
504 dirs{end + 1} = fullfile (descriptions{i}.dir, arch);
505 endif
496 endfor 506 endfor
497 addpath (dirs{:}); 507 addpath (dirs{:});
498 endif 508 endif
499 endfunction 509 endfunction
500 510
501 function uninstall (pkgnames, handle_deps, local_list, global_list) 511 function uninstall (pkgnames, handle_deps, verbose, local_list, global_list)
502 ## Get the list of installed packages 512 ## Get the list of installed packages
503 [local_packages, global_packages] = installed_packages(local_list, 513 [local_packages, global_packages] = installed_packages(local_list,
504 global_list); 514 global_list);
505 if (issuperuser ()) 515 if (issuperuser ())
506 installed_packages = {local_packages{:}, global_packages{:}}; 516 installed_packages = {local_packages{:}, global_packages{:}};
571 ## Delete the directories containing the packages 581 ## Delete the directories containing the packages
572 for i = delete_idx 582 for i = delete_idx
573 desc = installed_packages{i}; 583 desc = installed_packages{i};
574 ## If an 'on_uninstall.m' exist, call it! 584 ## If an 'on_uninstall.m' exist, call it!
575 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file")) 585 if (exist (fullfile (desc.dir, "packinfo", "on_uninstall.m"), "file"))
576 try 586 wd = pwd ();
577 wd = pwd (); 587 cd (fullfile(desc.dir, "packinfo"));
578 cd (fullfile(desc.dir, "packinfo")); 588 on_uninstall (desc);
579 on_uninstall (desc); 589 cd (wd);
580 cd (wd);
581 catch
582 ## XXX: Should this rather be an error?
583 warning ("the 'on_uninstall' script retsurned the following error: %s",
584 lasterr ());
585 cd (wd);
586 end_try_catch
587 endif 590 endif
588 ## Do the actual deletion 591 ## Do the actual deletion
589 rmpath (desc.dir); 592 rmpath (desc.dir);
593 if (exist (fullfile (desc.dir, getarch()), "dir"))
594 rmpath (fullfile (desc.dir, getarch ()));
595 endif
590 if (exist (desc.dir, "dir")) 596 if (exist (desc.dir, "dir"))
591 [status, msg] = rm_rf (desc.dir); 597 [status, msg] = rm_rf (desc.dir);
592 if (status != 1) 598 if (status != 1)
593 error ("couldn't delete directory %s: %s", desc.dir, msg); 599 error ("couldn't delete directory %s: %s", desc.dir, msg);
594 endif 600 endif
645 msg); 651 msg);
646 endif 652 endif
647 endif 653 endif
648 endfunction 654 endfunction
649 655
650 function configure_make (desc, packdir) 656 function configure_make (desc, packdir, verbose)
651 ## Perform ./configure, make, make install in "src" 657 ## Perform ./configure, make, make install in "src"
652 if (exist (fullfile (packdir, "src"), "dir")) 658 if (exist (fullfile (packdir, "src"), "dir"))
653 src = fullfile (packdir, "src"); 659 src = fullfile (packdir, "src");
654 ## configure 660 ## configure
655 if (exist (fullfile (src, "configure"), "file")) 661 if (exist (fullfile (src, "configure"), "file"))
656 [status, output] = system (strcat ("cd ", src, "; ./configure --prefix=", 662 [status, output] = system (strcat ("cd ", src, "; ./configure --prefix=",
657 desc.dir)); 663 desc.dir));
664 if (verbose)
665 printf("%s", output);
666 endif
658 if (status != 0) 667 if (status != 0)
659 rm_rf (desc.dir); 668 rm_rf (desc.dir);
660 error ("the configure script returned the following error: %s", output); 669 error ("the configure script returned the following error: %s", output);
661 endif 670 endif
662 endif 671 endif
663 672
664 ## make 673 ## make
665 if (exist (fullfile (src, "Makefile"), "file")) 674 if (exist (fullfile (src, "Makefile"), "file"))
666 [status, output] = system (strcat ("export INSTALLDIR=", desc.dir, 675 [status, output] = system (strcat ("export INSTALLDIR=", desc.dir,
667 "; make -C ", src)); 676 "; make -C ", src));
677 if (verbose)
678 printf("%s", output);
679 endif
668 if (status != 0) 680 if (status != 0)
669 rm_rf (desc.dir); 681 rm_rf (desc.dir);
670 error ("'make' returned the following error: %s", output); 682 error ("'make' returned the following error: %s", output);
671 endif 683 endif
672 %# make install 684 %# make install
673 %[status, output] = system(["export INSTALLDIR=" desc.dir "; make install -C " src]); 685 %[status, output] = system(["export INSTALLDIR=" desc.dir "; make install -C " src]);
686 %if (verbose)
687 % printf("%s", output);
688 %endif
674 %if (status != 0) 689 %if (status != 0)
675 % rm_rf(desc.dir); 690 % rm_rf(desc.dir);
676 % error("'make install' returned the following error: %s", output); 691 % error("'make install' returned the following error: %s", output);
677 %endif 692 %endif
678 endif 693 endif
679 694
680 ## Copy files to "inst" (this is instead of 'make install') 695 ## Copy files to "inst" and "inst/arch" (this is instead of 'make install')
681 files = fullfile (src, "FILES"); 696 files = fullfile (src, "FILES");
682 instdir = fullfile (packdir, "inst"); 697 instdir = fullfile (packdir, "inst");
698 archdir = fullfile (packdir, "inst", getarch ());
683 if (exist (files, "file")) 699 if (exist (files, "file"))
684 ## Get file names 700 ## Get file names
685 [fid, msg] = fopen (files, "r"); 701 [fid, msg] = fopen (files, "r");
686 if (fid < 0) 702 if (fid < 0)
687 error ("couldn't open %s: %s", files, msg); 703 error ("couldn't open %s: %s", files, msg);
701 delete_idx(end+1) = i; 717 delete_idx(end+1) = i;
702 endif 718 endif
703 endfor 719 endfor
704 fn(delete_idx) = []; 720 fn(delete_idx) = [];
705 filenames = sprintf ("%s ", fn{:}); 721 filenames = sprintf ("%s ", fn{:});
722
723 filenames = split_by (filenames, " ");
724 archindependent = filenames;
725 mex = regexp (filenames, '^.*\.mex');
726 archindependent(cellfun ("isempty", mex) == 0) = [];
727 mex (cellfun ("isempty", mex)) = [];
728 mex = cellfun (@(x) x(1), mex);
729 oct = regexp (filenames, '^.*\.oct');
730 archindependent(cellfun ("isempty", oct) == 0) = [];
731 oct (cellfun ("isempty", oct)) = [];
732 oct = cellfun (@(x) x(1), oct);
733 archdependent = [oct, mex];
706 else 734 else
707 m = dir (fullfile (src, "*.m")); 735 m = dir (fullfile (src, "*.m"));
708 oct = dir (fullfile (src, "*.oct")); 736 oct = dir (fullfile (src, "*.oct"));
709 mex = dir (fullfile (src, "*.mex")); 737 mex = dir (fullfile (src, "*.mex"));
738 archdependent = "";
739 archindependent = "";
710 filenames = ""; 740 filenames = "";
711 if (length (m) > 0) 741 if (length (m) > 0)
712 filenames = sprintf (fullfile (src, "%s "), m.name); 742 filenames = sprintf (fullfile (src, "%s "), m.name);
743 archindependent = sprintf (fullfile (src, "%s "), m.name);
713 endif 744 endif
714 if (length (oct) > 0) 745 if (length (oct) > 0)
715 filenames = [filenames, " ", sprintf(fullfile(src, "%s "), oct.name)]; 746 filenames = [filenames, " ", sprintf(fullfile(src, "%s "), oct.name)];
747 archdependent = [archdependent, " ", ...
748 sprintf(fullfile(src, "%s "), oct.name)];
716 endif 749 endif
717 if (length (mex) > 0) 750 if (length (mex) > 0)
718 filenames = [filenames, " ", sprintf(fullfile(src, "%s "), mex.name)]; 751 filenames = [filenames, " ", sprintf(fullfile(src, "%s "), mex.name)];
719 endif 752 archdependent = [archdependent, " ", ...
720 endif 753 sprintf(fullfile(src, "%s "), mex.name)];
721 filenames = split_by (filenames, " "); 754 endif
755 filenames = split_by (filenames, " ");
756 archdependent = split_by (archdependent, " ");
757 archindependent = split_by (archindependent, " ");
758 endif
722 759
723 if (! all (isspace (filenames))) 760 if (! all (isspace (filenames)))
724 mkdir (instdir); 761 mkdir (instdir);
725 [status, output] = copyfile (filenames, instdir); 762 if (! all (isspace (archindependent)))
726 if (status != 1) 763 [status, output] = copyfile (archindependent, instdir);
764 if (status != 1)
727 rm_rf (desc.dir); 765 rm_rf (desc.dir);
728 error ("Couldn't copy files from 'src' to 'inst': %s", output); 766 error ("Couldn't copy files from 'src' to 'inst': %s", output);
729 endif 767 endif
768 endif
769 if (! all (isspace (archdependent)))
770 mkdir (archdir);
771 [status, output] = copyfile (archdependent, archdir);
772 if (status != 1)
773 rm_rf (desc.dir);
774 error ("Couldn't copy files from 'src' to 'inst': %s", output);
775 endif
776 endif
730 endif 777 endif
731 endif 778 endif
732 endfunction 779 endfunction
733 780
734 function pkg = extract_pkg (nm, pat) 781 function pkg = extract_pkg (nm, pat)
1294 endif 1341 endif
1295 endfor 1342 endfor
1296 dirs = unique(dirs); 1343 dirs = unique(dirs);
1297 endif 1344 endif
1298 1345
1346 ## Check for architecture dependent directories
1347 arch = getarch();
1348 archdirs = {};
1349 for i = 1:length (dirs)
1350 tmpdir = fullfile (dirs{i}, arch);
1351 if (exist (tmpdir, "dir"))
1352 archdirs{end + 1} = dirs{i};
1353 archdirs{end + 1} = tmpdir;
1354 endif
1355 endfor
1356 if (length (archdirs) > 0)
1357 dirs = archdirs;
1358 endif
1359
1299 ## Load the packages 1360 ## Load the packages
1300 if (length (dirs) > 0) 1361 if (length (dirs) > 0)
1301 addpath (dirs{:}); 1362 addpath (dirs{:});
1302 endif 1363 endif
1303 1364
1337 endif 1398 endif
1338 dirs{end+1} = pdirs{idx}; 1399 dirs{end+1} = pdirs{idx};
1339 endfor 1400 endfor
1340 endif 1401 endif
1341 1402
1403 ## Check for architecture dependent directories
1404 arch = getarch();
1405 archdirs = {};
1406 for i = 1:length (dirs)
1407 tmpdir = fullfile (dirs{i}, arch);
1408 if (exist (tmpdir, "dir"))
1409 archdirs{end + 1} = dirs{i};
1410 archdirs{end + 1} = tmpdir;
1411 endif
1412 endfor
1413 if (length (archdirs) > 0)
1414 dirs = archdirs;
1415 endif
1416
1342 ## Unload the packages 1417 ## Unload the packages
1343 for i = 1:length (dirs) 1418 for i = 1:length (dirs)
1344 d = dirs{i}; 1419 d = dirs{i};
1345 idx = strcmp (p, d); 1420 idx = strcmp (p, d);
1346 if (any (idx)) 1421 if (any (idx))
1386 return 1461 return
1387 endif 1462 endif
1388 endfor 1463 endfor
1389 emp = true; 1464 emp = true;
1390 endfunction 1465 endfunction
1466
1467 function arch = getarch ()
1468 persistent _arch = [octave_config_info("canonical_host_type"), "-", ...
1469 octave_config_info("api_version")];
1470 arch = _arch;
1471 endfunction