view scripts/pkg/private/get_inverse_dependencies.m @ 28023:915b3630eed0

pkg.m: Don't unload dependency packages when their dependers are loaded (bug #57522). * pkg.m: Explain "-nodeps" option for "pkg load" and "pkg unload"; add one more example with dependency. * get_inverse_dependencies.m: New function. * scripts/pkg/module.mk: Add get_inverse_dependencies.m to build system. * unload_packages.m: rewrite parts of code; when checking input mention all requested but non-installed packages instead of just the first; track down loaded depender packages and if found, emit a sensible error message; process handle_deps argument ('-nodeps'). * describe.m: Also display installed packages that depend on requested package.
author Philip Nienhuis <prnienhuis@users.sf.net>
date Sat, 25 Jan 2020 15:26:07 +0100
parents
children f6f9341c46c1
line wrap: on
line source

########################################################################
##
## Copyright (C) 2020 The Octave Project Developers
##
## See the file COPYRIGHT.md in the top-level directory of this
## distribution or <https://octave.org/copyright/>.
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <https://www.gnu.org/licenses/>.
##
########################################################################

## -*- texinfo -*-
## @deftypefn {} {@var{installed_pkgs_list} =} get_inverse_dependencies (@var{installed_pkgs_lst})
## Find inverse dependencies, if any, for each package, and store in
## the struct field "invdeps".
##
## @end deftypefn

function installed_pkgs_lst = get_inverse_dependencies (installed_pkgs_lst)

  for i = 1:numel (installed_pkgs_lst)
    installed_pkgs_lst{i}.invdeps = {};  # initialize invdeps field
  endfor

  for i = 1:numel (installed_pkgs_lst)
#    keyboard;
    pdeps = installed_pkgs_lst{i}.depends;
    for j = 1:numel (pdeps)
      pdep_nm = pdeps{j}.package;
      if (! strcmp (pdep_nm, "octave"))
        idx = cellfun (@(S) strcmp (S.name, pdep_nm), installed_pkgs_lst);
        installed_pkgs_lst{idx}.invdeps(end+1) = {installed_pkgs_lst{i}.name};
      endif
    endfor
  endfor

endfunction