view scripts/pkg/private/copy_built_files.m @ 21518:2ee20a290d61

pkg build: complete rewrite of the logic behind binary packages. * pkg/private/build.m: this functions prepares a "binary" package. This rewrite is triggered to fix bug #45369 (do not move installed PKG_ADD and PKG_DEL files into root of the binary package) but changes the whole underlying logic of binary packages. Previously, "pkg build" would install a package into a specific directory and then created a package by making a tarball of it. This worked because the build files would go into a arch dependent directory inside inst/ which is just copied. Anyway, this is a complex process and sometimes almost impossible because all files besides the .m and .oct files need to be moved back to their original place. The main current problem is with PKG_ADD and PKG_DEL files (see bugs #45362, #45091, and #45369). In addition, it can also lead to duplication of PKG_ADD commands (because the process of installing a package parses .m files for PKG_ADD directives so they will appear on a PKG_ADD file. During installation of the binary package, the PKG_ADD directives would be readded to the file). Another issue is that it only works because the arch dependent directory is nested within the arch independent directory. Since that should not be, it will stop work once that gets fixed. Anyway, the whole reason for a "binary" package is to avoid a build which may require mkoctfile and C++ compilers (in theory it could also avoid generating doc-cache but in practice that is currently not done). So all we have to do is: do the build, remove the configure and Makefile, repackage everything with the oct and mex files. * pkg/private/repackage.m: remove unused function (it was used by build()) to create a binary package from an installed package. * pkg/private/configure_make.m: split into two parts. The first (which remains configure_make()) only really calls configure and make (and is used by build()). The rest is moved to the new function copy_built_files(). The split allows this function to be used by build. * pkg/private/copy_built_files.m: new function with the code moved from configure_make (it is used in install() only). * pkg/private/install.m: add call to copy_built_files which was previously part of configure_make. * pkg.m: adjust call to build(). * pkg/module.mk: remove repackage.m; add copy_built_files.m.
author Carnë Draug <carandraug@octave.org>
date Mon, 21 Mar 2016 00:02:43 +0000
parents
children
line wrap: on
line source

## Copyright (C) 2005-2015 Søren Hauberg
## Copyright (C) 2010 VZLU Prague, a.s.
##
## 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 {} {} copy_built_files (@var{desc}, @var{packdir}, @var{verbose})
## Undocumented internal function.
## @end deftypefn

function copy_built_files (desc, packdir, verbose)

  src = fullfile (packdir, "src");
  if (! exist (src, "dir"))
    return
  endif

  ## Copy files to "inst" and "inst/arch" (this is instead of 'make install').
  files = fullfile (src, "FILES");
  instdir = fullfile (packdir, "inst");
  archdir = fullfile (packdir, "inst", getarch ());

  ## Get filenames.
  if (exist (files, "file"))
    [fid, msg] = fopen (files, "r");
    if (fid < 0)
      error ("couldn't open %s: %s", files, msg);
    endif
    filenames = char (fread (fid))';
    fclose (fid);
    if (filenames(end) == "\n")
      filenames(end) = [];
    endif
    filenames = strtrim (ostrsplit (filenames, "\n"));
    delete_idx = [];
    for i = 1:length (filenames)
      if (! all (isspace (filenames{i})))
        filenames{i} = fullfile (src, filenames{i});
      else
        delete_idx(end+1) = i;
      endif
    endfor
    filenames(delete_idx) = [];
  else
    m = dir (fullfile (src, "*.m"));
    oct = dir (fullfile (src, "*.oct"));
    mex = dir (fullfile (src, "*.mex"));

    filenames = cellfun (@(x) fullfile (src, x),
                         {m.name, oct.name, mex.name},
                         "uniformoutput", false);
  endif

  ## Split into architecture dependent and independent files.
  if (isempty (filenames))
    idx = [];
  else
    idx = cellfun ("is_architecture_dependent", filenames);
  endif
  archdependent = filenames(idx);
  archindependent = filenames(! idx);

  ## Copy the files.
  if (! all (isspace ([filenames{:}])))
      if (! exist (instdir, "dir"))
        mkdir (instdir);
      endif
      if (! all (isspace ([archindependent{:}])))
        if (verbose)
          printf ("copyfile");
          printf (" %s", archindependent{:});
          printf ("%s\n", instdir);
        endif
        [status, output] = copyfile (archindependent, instdir);
        if (status != 1)
          rmdir (desc.dir, "s");
          error ("Couldn't copy files from 'src' to 'inst': %s", output);
        endif
      endif
      if (! all (isspace ([archdependent{:}])))
        if (verbose)
          printf ("copyfile");
          printf (" %s", archdependent{:});
          printf (" %s\n", archdir);
        endif
        if (! exist (archdir, "dir"))
          mkdir (archdir);
        endif
        [status, output] = copyfile (archdependent, archdir);
        if (status != 1)
          rmdir (desc.dir, "s");
          error ("Couldn't copy files from 'src' to 'inst': %s", output);
        endif
      endif
  endif
endfunction