Skip to content

Commit

Permalink
pluginhandler: build scriptlet support (canonical#988)
Browse files Browse the repository at this point in the history
LP: #1642371

Signed-off-by: Sergio Schvezov <[email protected]>
  • Loading branch information
sergiusens authored Dec 16, 2016
1 parent 5671b91 commit cc123ca
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 9 deletions.
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config.python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Unit Test",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config.python.pythonPath}",
"program": "${workspaceRoot}/units.py",
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
]
}
7 changes: 7 additions & 0 deletions integration_tests/snaps/scriptlet-build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- Mode: Makefile; indent-tabs-mode:t; tab-width: 4 -*-

build:
touch build-build

move-to-dest:
touch $(DESTDIR)/build-install
17 changes: 17 additions & 0 deletions integration_tests/snaps/scriptlet-build/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: build-scriptlet-test
version: '0.1'
summary: Runs the build scriptlet for a part
description: |
Runs the shell script defined in `build` overriding the plugins
build directives.
grade: devel
confinement: devmode

parts:
build-scriptlet-test:
source: .
plugin: make
build: |
make build
make move-to-dest DESTDIR=$SNAPCRAFT_PART_INSTALL
21 changes: 13 additions & 8 deletions integration_tests/test_scriptlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ def test_prepare_scriptlet(self):

installdir = os.path.join(
project_dir, 'parts', 'prepare-scriptlet-test', 'install')
prepared_file_path = os.path.join(installdir, 'prepared')
touch_file_path = os.path.join(installdir, 'prepared')
self.assertThat(touch_file_path, FileExists())

installdir = os.path.join(
project_dir, 'parts', 'prepare-and-install', 'install')
built_file_path = os.path.join(installdir, 'built')
installed_file_path = os.path.join(installdir, 'installed')
def test_build_scriptlet(self):
project_dir = 'scriptlet-build'
self.run_snapcraft('build', project_dir)

self.assertThat(prepared_file_path, FileExists())
self.assertThat(built_file_path, FileExists())
self.assertThat(installed_file_path, FileExists())
partdir = os.path.join(project_dir, 'parts', 'build-scriptlet-test')
builddir = os.path.join(partdir, 'build')
installdir = os.path.join(partdir, 'install')

touch_file_path = os.path.join(builddir, 'build-build')
self.assertThat(touch_file_path, FileExists())
touch_file_path = os.path.join(installdir, 'build-install')
self.assertThat(touch_file_path, FileExists())

def test_install_scriptlet(self):
project_dir = 'scriptlet-install'
Expand Down
3 changes: 3 additions & 0 deletions schema/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ properties:
install:
type: string
default: ''
build:
type: string
default: ''
prepare:
type: string
default: ''
Expand Down
14 changes: 14 additions & 0 deletions snapcraft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@
cd scripts
./bootstrap.sh
- build: shell script
If present, the shell script defined here is run instead of the `build`
step of the plugin. The working directory is the base build directory
for the given part. The defined script is run with `/bin/sh`.
For example:
plugin: make
build: |
make project
make test
make special-install
- install: shell script
If present, the shell script defined here is run after the `build` step
Expand Down
6 changes: 5 additions & 1 deletion snapcraft/internal/pluginhandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ def ignore(directory, files):
script_runner = ScriptRunner(builddir=self.code.build_basedir)

script_runner.run(scriptlet=self._part_properties.get('prepare'))
self.code.build()
build_scriptlet = self._part_properties.get('build')
if build_scriptlet:
script_runner.run(scriptlet=build_scriptlet)
else:
self.code.build()
script_runner.run(scriptlet=self._part_properties.get('install'))

self.mark_build_done()
Expand Down
4 changes: 4 additions & 0 deletions units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import unittest

unittest.main('snapcraft.tests.pluginhandler.test_scriptlets',
argv=['ScriptletsTestCase']) # noqa

0 comments on commit cc123ca

Please sign in to comment.