# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2015, 2016 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
"""The make plugin is useful for building make based parts.
Make based projects are projects that have a Makefile that drives the
build.
This plugin uses the common plugin keywords as well as those for "sources".
For more information check the 'plugins' topic for the former and the
'sources' topic for the latter.
Additionally, this plugin uses the following plugin-specific keyword:
- script:
(string)
Run the given script name.
- bash-arguments:
(list of strings)
Pass the given parameters to the bash script.
"""
import snapcraft
import snapcraft.common
class BashPlugin(snapcraft.BasePlugin):
@classmethod
def schema(cls):
schema = super().schema()
schema['properties']['script'] = {
'type': 'string',
}
schema['properties']['bash-arguments'] = {
'type': 'array',
'minitems': 1,
'uniqueItems': True,
'items': {
'type': 'string',
},
'default': [],
}
# Inform Snapcraft of the properties associated with building. If these
# change in the YAML Snapcraft will consider the build step dirty.
schema['required'].extend(['script'])
schema['build-properties'].extend(['bash-arguments'])
return schema
def __init__(self, name, options, project):
super().__init__(name, options, project)
self.build_packages.append('bash')
def build(self):
super().build()
if self.sourcedir == '.':
command = ['./' + self.options.script]
else:
command = ['./' + self.sourcedir + self.options.script]
if self.options.bash-arguments:
command.extend(self.options.bash-arguments)
self.run(command)
self.run(command + ['install', self.installdir])