"Fossies" - the Fresh Open Source Software Archive

Member "snapcraft-3.6/snapcraft/plugins/autotools.py" (14 Jun 2019, 4793 Bytes) of package /linux/misc/snapcraft-3.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "autotools.py" see the Fossies "Dox" file reference documentation.

    1 # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
    2 #
    3 # Copyright (C) 2015-2016 Canonical Ltd
    4 # Copyright (C) 2016 Harald Sitter <sitter@kde.org>
    5 #
    6 # This program is free software: you can redistribute it and/or modify
    7 # it under the terms of the GNU General Public License version 3 as
    8 # published by the Free Software Foundation.
    9 #
   10 # This program is distributed in the hope that it will be useful,
   11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 # GNU General Public License for more details.
   14 #
   15 # You should have received a copy of the GNU General Public License
   16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17 
   18 """The autotools plugin is used for autotools based parts.
   19 
   20 Autotools based projects are the ones that have the usual
   21 `./configure && make && make install` instruction set.
   22 
   23 The plugin tries to build using ./configure first, if it is not there
   24 it will run ./autogen and if autogen is not there it will run autoreconf.
   25 
   26 This plugin uses the common plugin keywords as well as those for "sources".
   27 For more information check the 'plugins' topic for the former and the
   28 'sources' topic for the latter.
   29 
   30 In addition, this plugin uses the following plugin-specific keywords:
   31 
   32     - configflags:
   33       (list of strings)
   34       configure flags to pass to the build such as those shown by running
   35       './configure --help'
   36     - install-via:
   37       (enum, 'destdir' or 'prefix')
   38       Whether to install via DESTDIR or by using --prefix (default is
   39       'destdir')
   40 """
   41 
   42 import os
   43 import stat
   44 
   45 from snapcraft.plugins import make
   46 
   47 
   48 class AutotoolsPlugin(make.MakePlugin):
   49     @classmethod
   50     def schema(cls):
   51         schema = super().schema()
   52         schema["properties"]["configflags"] = {
   53             "type": "array",
   54             "minitems": 1,
   55             "items": {"type": "string"},
   56             "default": [],
   57         }
   58 
   59         schema["properties"]["install-via"] = {
   60             "enum": ["destdir", "prefix"],
   61             "default": "destdir",
   62         }
   63 
   64         schema["required"] = ["source"]
   65 
   66         return schema
   67 
   68     @classmethod
   69     def get_build_properties(cls):
   70         # Inform Snapcraft of the properties associated with building. If these
   71         # change in the YAML Snapcraft will consider the build step dirty.
   72         return super().get_build_properties() + ["configflags", "install-via"]
   73 
   74     def __init__(self, name, options, project):
   75         super().__init__(name, options, project)
   76         self.build_packages.extend(["autoconf", "automake", "autopoint", "libtool"])
   77 
   78         if options.install_via == "destdir":
   79             self.options.make_install_var = "DESTDIR"
   80         elif options.install_via == "prefix":
   81             self.options.make_install_var = ""
   82         else:
   83             raise RuntimeError(
   84                 'Unsupported installation method: "{}"'.format(options.install_via)
   85             )
   86 
   87     def enable_cross_compilation(self):
   88         pass
   89 
   90     def build(self):
   91         if not os.path.exists(os.path.join(self.builddir, "configure")):
   92             generated = False
   93             scripts = ["autogen.sh", "bootstrap"]
   94             for script in scripts:
   95                 path = os.path.join(self.builddir, script)
   96                 if not os.path.exists(path) or os.path.isdir(path):
   97                     continue
   98                 # Make sure it's executable
   99                 if not os.access(path, os.X_OK):
  100                     os.chmod(
  101                         path,
  102                         stat.S_IRUSR
  103                         | stat.S_IWUSR
  104                         | stat.S_IXUSR
  105                         | stat.S_IRGRP
  106                         | stat.S_IWGRP
  107                         | stat.S_IXGRP
  108                         | stat.S_IROTH
  109                         | stat.S_IWOTH
  110                         | stat.S_IXOTH,
  111                     )
  112                 self.run(["env", "NOCONFIGURE=1", "./{}".format(script)])
  113                 generated = True
  114                 break
  115             if not generated:
  116                 self.run(["autoreconf", "-i"])
  117 
  118         configure_command = ["./configure"]
  119 
  120         if self.options.make_install_var:
  121             # Use an empty prefix since we'll install via DESTDIR
  122             configure_command.append("--prefix=")
  123         else:
  124             configure_command.append("--prefix=" + self.installdir)
  125         if self.project.is_cross_compiling:
  126             configure_command.append("--host={}".format(self.project.arch_triplet))
  127 
  128         self.run(configure_command + self.options.configflags)
  129         self.make()
  130 
  131     def snap_fileset(self):
  132         fileset = super().snap_fileset()
  133         # Remove .la files which don't work when they are moved around
  134         fileset.append("-**/*.la")
  135         return fileset