octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issues with build Fedora RPMs of octave packages


From: David Bateman
Subject: Re: Issues with build Fedora RPMs of octave packages
Date: Fri, 21 Sep 2007 11:33:59 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

David Bateman wrote:
> Orion Poplawski wrote:
>> David Bateman wrote:
>>> The binary architecture dependent files are under a separate directory in
>>>
>>>
>>> arch = strcat (octave_config_info("canonical_host_type"), ...
>>>                  "-", octave_config_info("api_version"));
>>>
>>> /usr/share/octave/packages/%name-%version/%arch
>>>
>>> Where should they be to meet the FHS? The only constraint I see on their
>>> placement is that it would be better to have each packages architecture
>>> dependent files in a separate directory. This for the PKG_ADD command
>>> issue below.
>>>
>> According to the FHS:
>>
>> /usr/share : Architecture-independent data
>>
>> Currently the Fedora octave packages put the .oct files into
>> LOCALAPIOCTFILEDIR, for example:
>>
>> /usr/libexec/octave/2.9.14/oct/i386-redhat-linux-gnu
>>
>> Possibly this should get changed to
>>
>> /usr/lib[64]/octave/%version/oct
>>
>> depending on how you feel about libexec.  libexec is generally for
>> programs and scripts that are only executed by other programs, not
>> libraries.
> 
> Well are oct-files libraries? From a certain way of looking at it yes,
> but you can't be guaranteed to be able to link to them.. Looking at the
> issue from within Octave it would be easies to make pkg (when run as
> root), install the packages files to
> 
> LOCALAPIFILEDIR/<package>
> 
> Another reason that there needs to be separate directories is that the
> package manager might have one package loaded and others not and having
> or the files in one path makes it harder (if not impossible) to allow
> only a portion of the oct-files to be used.
> 

There is another issue with using LOCALAPIFILEDIR or something like it..
 The default path of octave is set to contain these directories and all
sub-directories of these. A better choice might be

<libexec>/octave/packages/getarch()/<package>

where getarch is a pkg sub-function

function arch = getarch ()
  persistent _arch = strcat (octave_config_info("canonical_host_type"), ...
                             "-", octave_config_info("api_version"));
  arch = _arch;
endfunction

as this directory will not be automatically load by load_path.cc
(load_path::do_initialize)

The attached patch does this, but leaves the installations of oct-files
for non system users in the same location.. Does this meet your needs?

D.

*** ./scripts/pkg/pkg.m.orig2   2007-08-23 18:14:51.000000000 +0200
--- ./scripts/pkg/pkg.m 2007-09-21 11:31:00.406494714 +0200
***************
*** 178,188 ****
                                     "octave_packages");
    mlock ();
  
!   if (ispc () && ! isunix ())
!     global_install = 1;
!   else
!     global_install = (geteuid() == 0);
!   endif
  
    if (prefix == -1)
      if (global_install)
--- 178,184 ----
                                     "octave_packages");
    mlock ();
  
!   global_install = issuperuser ();
  
    if (prefix == -1)
      if (global_install)
***************
*** 668,673 ****
--- 664,670 ----
      endfor
      for i = 1:length (descriptions)
        rm_rf (descriptions{i}.dir);
+       rm_rf (getarchdir (descriptions{i}));
      endfor
      rethrow (lasterror ());
    end_try_catch
***************
*** 675,683 ****
    ## Check if the installed directory is empty. If it is remove it
    ## from the list
    for i = length (descriptions):-1:1
!     if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}))
        warning ("package %s is empty\n", descriptions{i}.name);
        rm_rf (descriptions{i}.dir);
        descriptions(i) = [];
      endif
    endfor
--- 672,682 ----
    ## Check if the installed directory is empty. If it is remove it
    ## from the list
    for i = length (descriptions):-1:1
!     if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) &&
!       dirempty (getarchdir (descriptions{i})))
        warning ("package %s is empty\n", descriptions{i}.name);
        rm_rf (descriptions{i}.dir);
+       rm_rf (getarchdir (descriptions{i}));
        descriptions(i) = [];
      endif
    endfor
***************
*** 826,833 ****
      ## Do the actual deletion
      if (desc.loaded)
        rmpath (desc.dir);
!       if (exist (fullfile (desc.dir, getarch()), "dir"))
!       rmpath (fullfile (desc.dir, getarch ()));
        endif
      endif
      if (exist (desc.dir, "dir"))
--- 825,832 ----
      ## Do the actual deletion
      if (desc.loaded)
        rmpath (desc.dir);
!       if (exist (getarchdir (desc)))
!       rmpath (getarchdir (desc));
        endif
      endif
      if (exist (desc.dir, "dir"))
***************
*** 835,840 ****
--- 834,843 ----
        if (status != 1)
        error ("couldn't delete directory %s: %s", desc.dir, msg);
        endif
+       [status, msg] = rm_rf (getarchdir (desc));
+       if (status != 1)
+       error ("couldn't delete directory %s: %s", getarchdir (desc), msg);
+       endif
      else
        warning ("directory %s previously lost", desc.dir);
      endif
***************
*** 1130,1137 ****
    ## architecture dependent directory so that the autoload/mfilename 
    ## commands work as expected. The only part that doesn't is the
    ## part in the main directory.
!   if (exist (fullfile (desc.dir, getarch ()), "dir"))
!     archpkg = fullfile (desc.dir, getarch (), nm);
      archfid = fopen (archpkg, "wt");
    else
      archpkg = instpkg;
--- 1133,1140 ----
    ## architecture dependent directory so that the autoload/mfilename 
    ## commands work as expected. The only part that doesn't is the
    ## part in the main directory.
!   if (exist (getarchdir (desc), "dir"))
!     archpkg = fullfile (getarchdir (desc), nm);
      archfid = fopen (archpkg, "wt");
    else
      archpkg = instpkg;
***************
*** 1196,1201 ****
--- 1199,1206 ----
      endif
    endif
  
+   octfiledir = getarchdir (desc);
+ 
    ## Copy the files from "inst" to installdir
    instdir = fullfile (packdir, "inst");
    if (! dirempty (instdir))
***************
*** 1204,1209 ****
--- 1209,1260 ----
        rm_rf (desc.dir);
        error ("couldn't copy files to the installation directory");
      endif
+     if (issuperuser () && exist (fullfile (desc.dir, getarch ()), "dir"))
+       if (! exist (octfiledir, "dir"))
+         ## Can be required to create upto three levels of dirs
+         octm1 = fileparts (octfiledir);
+         if (! exist (octm1, "dir"))
+           octm2 = fileparts (octm1);
+           if (! exist (octm2, "dir"))
+             octm3 = fileparts (octm2);
+             if (! exist (octm3, "dir"))
+               [status, output] = mkdir (octm3);
+               if (status != 1)
+                 rm_rf (desc.dir);
+                 error ("couldn't create installation directory %s : %s", 
+                        octm3, output);
+               endif
+             endif
+             [status, output] = mkdir (octm2);
+             if (status != 1)
+               rm_rf (desc.dir);
+               error ("couldn't create installation directory %s : %s", 
+                      octm2, output);
+             endif
+           endif
+           [status, output] = mkdir (octm1);
+           if (status != 1)
+             rm_rf (desc.dir);
+             error ("couldn't create installation directory %s : %s", 
+                    octm1, output);
+           endif
+         endif
+         [status, output] = mkdir (octfiledir);
+         if (status != 1)
+           rm_rf (desc.dir);
+           error ("couldn't create installation directory %s : %s", 
+           octfiledir, output);
+         endif
+       endif
+       [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), 
+                                  octfiledir);
+       if (status != 1)
+         rm_rf (desc.dir);
+         rm_rf (octfiledir);
+         error ("couldn't copy files to the installation directory");
+       endif
+     endif
+ 
    endif
  
    ## Create the "packinfo" directory
***************
*** 1211,1231 ****
    [status, msg] = mkdir (packinfo);
    if (status != 1)
      rm_rf (desc.dir);
      error ("couldn't create packinfo directory: %s", msg);
    endif
  
    ## Copy DESCRIPTION
    [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo);
    if (status != 1)
!    rm_rf (desc.dir);
!    error ("couldn't copy DESCRIPTION: %s", output);
    endif
  
    ## Copy COPYING
    [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo);
    if (status != 1)
!    rm_rf (desc.dir);
!    error ("couldn't copy COPYING: %s", output);
    endif
  
    ## If the file ChangeLog exists, copy it
--- 1262,1285 ----
    [status, msg] = mkdir (packinfo);
    if (status != 1)
      rm_rf (desc.dir);
+     rm_rf (octfiledir);
      error ("couldn't create packinfo directory: %s", msg);
    endif
  
    ## Copy DESCRIPTION
    [status, output] = copyfile (fullfile (packdir, "DESCRIPTION"), packinfo);
    if (status != 1)
!     rm_rf (desc.dir);
!     rm_rf (octfiledir);
!     error ("couldn't copy DESCRIPTION: %s", output);
    endif
  
    ## Copy COPYING
    [status, output] = copyfile (fullfile (packdir, "COPYING"), packinfo);
    if (status != 1)
!     rm_rf (desc.dir);
!     rm_rf (octfiledir);
!     error ("couldn't copy COPYING: %s", output);
    endif
  
    ## If the file ChangeLog exists, copy it
***************
*** 1234,1239 ****
--- 1288,1294 ----
      [status, output] = copyfile (fChangeLog, packinfo);
      if (status != 1)
        rm_rf (desc.dir);
+       rm_rf (octfiledir);
        error ("couldn't copy ChangeLog file: %s", output);
      endif
    endif
***************
*** 1244,1249 ****
--- 1299,1305 ----
      [status, output] = copyfile (fINDEX, packinfo);
      if (status != 1)
        rm_rf (desc.dir);
+       rm_rf (octfiledir);
        error ("couldn't copy INDEX file: %s", output);
      endif
    else
***************
*** 1252,1257 ****
--- 1308,1314 ----
                   fullfile (packinfo, "INDEX"));
      catch
        rm_rf (desc.dir);
+       rm_rf (octfiledir);
        rethrow (lasterror ());
      end_try_catch
    endif
***************
*** 1262,1267 ****
--- 1319,1325 ----
      [status, output] = copyfile (fon_uninstall, packinfo);
      if (status != 1)
        rm_rf (desc.dir);
+       rm_rf (octfiledir);
        error ("couldn't copy on_uninstall.m: %s", output);
      endif
    endif
***************
*** 1269,1281 ****
    ## Is there a doc/ directory that needs to be installed
    docdir = fullfile (packdir, "doc");
    if (exist (docdir, "dir") && ! dirempty (docdir))
!    [status, output] = copyfile (docdir, desc.dir);
    endif
  
    ## Is there a bin/ directory that needs to be installed
    bindir = fullfile (packdir, "bin");
    if (exist (bindir, "dir") && ! dirempty (bindir))
!    [status, output] = copyfile (bindir, desc.dir);
    endif
  endfunction
  
--- 1327,1339 ----
    ## Is there a doc/ directory that needs to be installed
    docdir = fullfile (packdir, "doc");
    if (exist (docdir, "dir") && ! dirempty (docdir))
!     [status, output] = copyfile (docdir, desc.dir);
    endif
  
    ## Is there a bin/ directory that needs to be installed
    bindir = fullfile (packdir, "bin");
    if (exist (bindir, "dir") && ! dirempty (bindir))
!     [status, output] = copyfile (bindir, desc.dir);
    endif
  endfunction
  
***************
*** 1290,1295 ****
--- 1348,1354 ----
      catch
        cd (wd);
        rm_rf (desc.dir);
+       rm_rf (getarchdir (desc));
        rethrow (lasterror ());
      end_try_catch
    endif
***************
*** 1478,1485 ****
    endif
  
    ## Check for architecture dependent files
!   arch = getarch();
!   tmpdir = fullfile (dir, arch);
    if (exist (tmpdir, "dir"))
      [files2, err, msg] = readdir (tmpdir);
      if (err)
--- 1537,1543 ----
    endif
  
    ## Check for architecture dependent files
!   tmpdir = getarchdir ();
    if (exist (tmpdir, "dir"))
      [files2, err, msg] = readdir (tmpdir);
      if (err)
***************
*** 1739,1773 ****
    ## unload all
    if (length (files) == 1 && strcmp (files{1}, "all"))
        dirs = pdirs;
    ## unload package_name1 ...
    else
      dirs = {};
      for i = 1:length (files)
!       idx = strcmp (pnames, files{i});
        if (! any (idx))
        error ("package %s is not installed", files{i});
        endif
!       dirs{end+1} = pdirs{idx};
        endfor
    endif
  
    ## Check for architecture dependent directories
-   arch = getarch();
    archdirs = {};
    for i = 1:length (dirs)
!     tmpdir = fullfile (dirs{i}, arch);
      if (exist (tmpdir, "dir"))
        archdirs{end + 1} = dirs{i};
        archdirs{end + 1} = tmpdir;
      endif
    endfor
-   if (length (archdirs) > 0)
-     dirs = archdirs;
-   endif
  
    ## Unload the packages
!   for i = 1:length (dirs)
!     d = dirs{i};
      idx = strcmp (p, d);
      if (any (idx))
        rmpath (d);
--- 1797,1832 ----
    ## unload all
    if (length (files) == 1 && strcmp (files{1}, "all"))
        dirs = pdirs;
+       desc = installed_pkgs_lst;
    ## unload package_name1 ...
    else
      dirs = {};
+     desc = {};
      for i = 1:length (files)
!       idx = strcmp (pnames, files {i});
        if (! any (idx))
        error ("package %s is not installed", files{i});
        endif
!       dirs {end + 1} = pdirs {idx};
!         desc {end + 1} = installed_pkgs_lst {idx};
        endfor
    endif
  
    ## Check for architecture dependent directories
    archdirs = {};
    for i = 1:length (dirs)
!     tmpdir = getarchdir (desc {i});
      if (exist (tmpdir, "dir"))
        archdirs{end + 1} = dirs{i};
        archdirs{end + 1} = tmpdir;
+     else
+       archdirs = dirs {i};
      endif
    endfor
  
    ## Unload the packages
!   for i = 1:length (archdirs)
!     d = archdirs{i};
      idx = strcmp (p, d);
      if (any (idx))
        rmpath (d);
***************
*** 1777,1789 ****
  endfunction
  
  function [status_out, msg_out] = rm_rf (dir)
!   crr = confirm_recursive_rmdir ();
!   unwind_protect
!     confirm_recursive_rmdir (false);
!     [status, msg] = rmdir (dir, "s");
!   unwind_protect_cleanup
!     confirm_recursive_rmdir (crr);
!   end_unwind_protect
    if (nargout > 0)
      status_out = status;
    endif
--- 1836,1853 ----
  endfunction
  
  function [status_out, msg_out] = rm_rf (dir)
!   if (exist (dir, "dir"))
!     crr = confirm_recursive_rmdir ();
!     unwind_protect
!       confirm_recursive_rmdir (false);
!       [status, msg] = rmdir (dir, "s");
!     unwind_protect_cleanup
!       confirm_recursive_rmdir (crr);
!     end_unwind_protect
!   else
!     status = 0;
!     msg = "";
!   endif
    if (nargout > 0)
      status_out = status;
    endif
***************
*** 1793,1818 ****
  endfunction
  
  function emp = dirempty (nm, ign)
!   if (nargin < 2)
!     ign = {".", ".."};
!   else
!     ign = [{".", ".."}, ign];
!   endif
!   l = dir (nm);
!   for i = 1:length (l)
!     found = false;
!     for j = 1:length (ign)
!       if (strcmp (l(i).name, ign{j}))
!         found = true;
!         break;
        endif
      endfor
!     if (! found)
!       emp = false;
!       return
!     endif
!   endfor
!   emp = true;
  endfunction
  
  function arch = getarch ()
--- 1857,1886 ----
  endfunction
  
  function emp = dirempty (nm, ign)
!   if (exist (nm, "dir"))
!     if (nargin < 2)
!       ign = {".", ".."};
!     else
!       ign = [{".", ".."}, ign];
!     endif
!     l = dir (nm);
!     for i = 1:length (l)
!       found = false;
!       for j = 1:length (ign)
!         if (strcmp (l(i).name, ign{j}))
!           found = true;
!           break;
!         endif
!       endfor
!       if (! found)
!         emp = false;
!         return
        endif
      endfor
!     emp = true;
!   else
!     emp = true;
!   endif
  endfunction
  
  function arch = getarch ()
***************
*** 1821,1826 ****
--- 1889,1911 ----
    arch = _arch;
  endfunction
  
+ function archdir = getarchdir (desc)
+   if (issuperuser ())
+     archdir = fullfile (octave_config_info ("libexecdir"), "octave", 
"packages", 
+                       getarch(), strcat(desc.name, "-", desc.version));
+   else
+     archdir = fullfile (desc.dir, getarch ());
+   endif
+ endfunction
+ 
+ function s = issuperuser ()
+   if ((ispc () && ! isunix ()) || (geteuid() == 0))
+     s = true;
+   else
+     s = false;
+   endif
+ endfunction
+ 
  function [status, output] = shell (cmd)
    persistent have_sh;
  
***************
*** 1881,1887 ****
  
  function load_packages_and_dependencies (idx, handle_deps, installed_pkgs_lst)
    idx = load_package_dirs (idx, [], handle_deps, installed_pkgs_lst);
-   arch = getarch ();
    dirs = {};
    execpath = EXEC_PATH ();
    for i = idx;
--- 1966,1971 ----
***************
*** 1890,1896 ****
      if (exist (fullfile (dirs{end}, "bin"), "dir"))
        execpath = strcat (fullfile(dirs{end}, "bin"), ":", execpath);
      endif
!     tmpdir = fullfile (ndir, arch);
      if (exist (tmpdir, "dir"))
        dirs{end + 1} = tmpdir;
      endif
--- 1974,1980 ----
      if (exist (fullfile (dirs{end}, "bin"), "dir"))
        execpath = strcat (fullfile(dirs{end}, "bin"), ":", execpath);
      endif
!     tmpdir = getarchdir (installed_pkgs_lst {i});
      if (exist (tmpdir, "dir"))
        dirs{end + 1} = tmpdir;
      endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]