changeset 17516:21656a949661

Add hook function to handle missing Octave components * __gripe_missing_component__.m: New internal function to handle errors due to missing Octave components. * scripts/help/module.mk (help_FCN_FILES): Add __gripe_missing_component__.m. * variables.cc (Vmissing_component_hook): New internal variable. * doc.m, mkoctfile.m, configure_make.m: Call __gripe_missing_component__ if required files are not found. * NEWS: Mention missing_component_hook.
author Mike Miller <mtmiller@ieee.org>
date Sun, 29 Sep 2013 16:06:41 -0400
parents c8c0dff02538
children 9c994995ddb0
files NEWS libinterp/corefcn/variables.cc scripts/help/__gripe_missing_component__.m scripts/help/doc.m scripts/help/module.mk scripts/miscellaneous/mkoctfile.m scripts/pkg/private/configure_make.m
diffstat 7 files changed, 110 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Sun Sep 29 20:56:39 2013 +0200
+++ b/NEWS	Sun Sep 29 16:06:41 2013 -0400
@@ -287,9 +287,9 @@
 
  ** Other new functions added in 3.8.0:
 
-      atan2d                     erfi             jit_startcnt
-      base64_decode              expint           lines
-      base64_encode              findfigs         linsolve
+      atan2d                     erfi             lines
+      base64_decode              expint           linsolve
+      base64_encode              findfigs         missing_component_hook
       betaincinv                 flintmax         polyeig
       built_in_docstrings_file   fminsearch       prefdir
       cmpermute                  gallery          preferences
@@ -303,7 +303,7 @@
       doc_cache_create           isequaln         strjoin
       ellipj                     jit_debug        struct2hdl
       ellipke                    jit_enable       tetramesh
-      erfcinv                                     waterfall
+      erfcinv                    jit_startcnt     waterfall
 
  ** Deprecated functions.
 
--- a/libinterp/corefcn/variables.cc	Sun Sep 29 20:56:39 2013 +0200
+++ b/libinterp/corefcn/variables.cc	Sun Sep 29 16:06:41 2013 -0400
@@ -2606,3 +2606,33 @@
 
   return retval;
 }
+
+static std::string Vmissing_component_hook;
+
+DEFUN (missing_component_hook, args, nargout,
+    "-*- texinfo -*-\n\
+@deftypefn  {Built-in Function} {@var{val} =} missing_component_hook ()\n\
+@deftypefnx {Built-in Function} {@var{old_val} =} missing_component_hook (@var{new_val})\n\
+@deftypefnx {Built-in Function} {} missing_component_hook (@var{new_val}, \"local\")\n\
+Query or set the internal variable that specifies the function to call when\n\
+a component of Octave is missing.  This can be useful for packagers that\n\
+may split the Octave installation into multiple sub-packages, for example,\n\
+to provide a hint to users for how to install the missing components.\n\
+\n\
+When called from inside a function with the @qcode{\"local\"} option, the\n\
+variable is changed locally for the function and any subroutines it calls.  \n\
+The original variable value is restored when exiting the function.\n\
+\n\
+The hook function is expected to be of the form\n\
+\n\
+@example\n\
+@var{fcn} (@var{component})\n\
+@end example\n\
+\n\
+Octave will call @var{fcn} with the name of the function that requires the\n\
+component and a string describing the missing component.  The hook function\n\
+should return an error message to be displayed.\n\
+@end deftypefn")
+{
+  return SET_INTERNAL_VARIABLE (missing_component_hook);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/help/__gripe_missing_component__.m	Sun Sep 29 16:06:41 2013 -0400
@@ -0,0 +1,56 @@
+## Copyright (C) 2013 Mike Miller
+##
+## 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
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} __gripe_missing_component__ (@var{caller}, @var{component})
+## Undocumented internal function.
+## @end deftypefn
+
+function __gripe_missing_component__ (caller, component)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  msg = "";
+  fcn = missing_component_hook ();
+
+  ftype = exist (fcn);
+  if (ftype == 2 || ftype == 3 || ftype == 5 || ftype == 103)
+    msg = feval (fcn, component);
+  endif
+
+  if (isempty (msg))
+    switch (component)
+      case "info-file"
+        msg = "unable to find the Octave info manual, Octave installation is incomplete";
+      case "mkoctfile"
+        msg = "unable to find the mkoctfile command, Octave installation is incomplete";
+      case "octave"
+        msg = "unable to find the octave executable, Octave installation is incomplete";
+      case "octave-config"
+        msg = "unable to find the octave-config command, Octave installation is incomplete";
+      otherwise
+        msg = ["unable to find required Octave component \"" component "\""];
+    endswitch
+  endif
+
+  error ("%s: %s\n", caller, msg);
+
+endfunction
+
--- a/scripts/help/doc.m	Sun Sep 29 20:56:39 2013 +0200
+++ b/scripts/help/doc.m	Sun Sep 29 16:06:41 2013 -0400
@@ -79,6 +79,10 @@
 
       if (err < 0)
         info_file_name = info_file ();
+
+        if (! exist (info_file_name, "file"))
+          __gripe_missing_component__ ("doc", "info-file");
+        endif
       endif
 
       ## FIXME -- don't change the order of the arguments below because
--- a/scripts/help/module.mk	Sun Sep 29 20:56:39 2013 +0200
+++ b/scripts/help/module.mk	Sun Sep 29 16:06:41 2013 -0400
@@ -5,6 +5,7 @@
   help/private/__strip_html_tags__.m
 
 help_FCN_FILES = \
+  help/__gripe_missing_component__.m \
   help/__makeinfo__.m \
   help/__unimplemented__.m \
   help/doc.m \
--- a/scripts/miscellaneous/mkoctfile.m	Sun Sep 29 20:56:39 2013 +0200
+++ b/scripts/miscellaneous/mkoctfile.m	Sun Sep 29 16:06:41 2013 -0400
@@ -146,6 +146,10 @@
 
   shell_script = fullfile (bindir, sprintf ("mkoctfile-%s", OCTAVE_VERSION));
 
+  if (! exist (shell_script, "file"))
+    __gripe_missing_component__ ("mkoctfile", "mkoctfile");
+  endif
+
   cmd = ['"' shell_script '"'];
   for i = 1:nargin
     cmd = [cmd ' "' varargin{i} '"'];
@@ -159,10 +163,7 @@
     printf ("%s", out);
   endif
 
-  if (sys == 127)
-    warning ("unable to find mkoctfile in expected location: '%s'",
-             shell_script);
-
+  if (sys != 0)
     warning ("mkoctfile exited with failure status");
   endif
 
--- a/scripts/pkg/private/configure_make.m	Sun Sep 29 20:56:39 2013 +0200
+++ b/scripts/pkg/private/configure_make.m	Sun Sep 29 16:06:41 2013 -0400
@@ -37,6 +37,16 @@
             "INSTALLDIR"; desc.dir};
     scenv = sprintf ("%s=\"%s\" ", cenv{:});
 
+    if (! exist (mkoctfile_program, "file"))
+      __gripe_missing_component__ ("pkg", "mkoctfile");
+    endif
+    if (! exist (octave_config_program, "file"))
+      __gripe_missing_component__ ("pkg", "octave-config");
+    endif
+    if (! exist (octave_binary, "file"))
+      __gripe_missing_component__ ("pkg", "octave");
+    endif
+
     ## Configure.
     if (exist (fullfile (src, "configure"), "file"))
       flags = "";