changeset 16824:51bcaa55f120

pkg: display output of shell commands on real time if verbose. * pkg/private/shell.m: display output of commands in real time and return empty string when verbose. Also small refactor: create the 'special' command for windows on its condition block rather than calling system() there to reduce code duplication. * pkg/private/configure_make.m: adjust call to shell() in order to display output of `configure' and `make' on real time if verbose.
author Carnë Draug <carandraug+dev@gmail.com>
date Sun, 23 Jun 2013 13:25:26 +0100
parents ffc246701137
children 71fc195d3e84
files scripts/pkg/private/configure_make.m scripts/pkg/private/shell.m
diffstat 2 files changed, 27 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/pkg/private/configure_make.m
+++ b/scripts/pkg/private/configure_make.m
@@ -36,6 +36,7 @@
             "OCTAVE"; octave_binary;
             "INSTALLDIR"; desc.dir};
     scenv = sprintf ("%s=\"%s\" ", cenv{:});
+
     ## Configure.
     if (exist (fullfile (src, "configure"), "file"))
       flags = "";
@@ -53,24 +54,23 @@
       endif
       [status, output] = shell (cstrcat ("cd '", src, "'; ", scenv,
                                          "./configure --prefix=\"",
-                                         desc.dir, "\"", flags));
+                                         desc.dir, "\"", flags),
+                                verbose);
       if (status != 0)
         rmdir (desc.dir, "s");
-        error ("the configure script returned the following error: %s", output);
-      elseif (verbose)
-        printf ("%s", output);
+        disp (output);
+        error ("pkg: error running the configure script for %s.", desc.name);
       endif
-
     endif
 
     ## Make.
     if (exist (fullfile (src, "Makefile"), "file"))
-      [status, output] = shell (cstrcat (scenv, "make -C '", src, "'"));
+      [status, output] = shell (cstrcat (scenv, "make -C '", src, "'"),
+                                verbose);
       if (status != 0)
         rmdir (desc.dir, "s");
-        error ("'make' returned the following error: %s", output);
-      elseif (verbose)
-        printf ("%s", output);
+        disp (output);
+        error ("pkg: error running `make' for the %s package.", desc.name);
       endif
     endif
 
--- a/scripts/pkg/private/shell.m
+++ b/scripts/pkg/private/shell.m
@@ -17,12 +17,14 @@
 ## along with Octave; see the file COPYING.  If not, see
 ## <http://www.gnu.org/licenses/>.
 
-## -*- texinfo -*-
-## @deftypefn {Function File} {[@var{status}, @var{output}] =} shell (@var{cmd})
-## Undocumented internal function.
-## @end deftypefn
+## Executes a shell command. In the end it calls system() but in case of
+## windows will first check if sh.exe works.
+##
+## If VERBOSE is true, it will prints the output to STDOUT in real time and
+## the second output argument will be an empty string. Otherwise, it will
+## contain the output of the execeuted command.
 
-function [status, output] = shell (cmd)
+function [status, output] = shell (cmd, verbose)
   persistent have_sh;
 
   cmd = strrep (cmd, "\\", "/");
@@ -35,12 +37,20 @@
       endif
     endif
     if (have_sh)
-      [status, output] = system (cstrcat ("sh.exe -c \"", cmd, "\""));
+      cmd = cstrcat ("sh.exe -c \"", cmd, "\"");
     else
-      error ("Can not find the command shell");
+      error ("pkg: unable to find the command shell.");
     endif
+  endif
+  ## if verbose, we want to display the output in real time. To do this, we
+  ## must call system with 1 output argument. But then the variable `output'
+  ## won't exist. So we initialize it empty. If an error does occur, and we
+  ## are verbose we will return an empty string but it's all fine since
+  ## the error message has already been displayed.
+  output = "";
+  if (verbose)
+    [status] = system (cmd);
   else
     [status, output] = system (cmd);
   endif
 endfunction
-