Merge lp:~zyga/snapcraft/hostapd-example into lp:~snappy-dev/snapcraft/core

Proposed by Zygmunt Krynicki
Status: Needs review
Proposed branch: lp:~zyga/snapcraft/hostapd-example
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 163 lines (+132/-0)
5 files modified
examples/hostapd/README.rst (+21/-0)
examples/hostapd/plugins/README.rst (+4/-0)
examples/hostapd/plugins/x-custom.yaml (+9/-0)
examples/hostapd/plugins/x_custom.py (+74/-0)
examples/hostapd/snapcraft.yaml (+24/-0)
To merge this branch: bzr merge lp:~zyga/snapcraft/hostapd-example
Reviewer Review Type Date Requested Status
Snappy Developers Pending
Review via email: mp+271336@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

hmm, this includes the plugin with custom commands, not so sure about it now as I don't think we want to promote this way of creating plugins officially at least.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

> hmm, this includes the plugin with custom commands, not so sure about it now
> as I don't think we want to promote this way of creating plugins officially at
> least.

Is there a way to build this with one of the stock part types?

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

> > hmm, this includes the plugin with custom commands, not so sure about it now
> > as I don't think we want to promote this way of creating plugins officially
> at
> > least.
>
> Is there a way to build this with one of the stock part types?

Can't you extend the makefile project to pass in a makefile and have that be the driver for those custom commands?

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

I'll try, I did something similar with trousers. I did find that I
need to have precise paths to other parts though (for -I/-L and
pkg-config). Perhaps it's better to just bake those into the makefile
part type in general.

On Thu, Sep 17, 2015 at 2:12 PM, Sergio Schvezov
<email address hidden> wrote:
>> > hmm, this includes the plugin with custom commands, not so sure about it now
>> > as I don't think we want to promote this way of creating plugins officially
>> at
>> > least.
>>
>> Is there a way to build this with one of the stock part types?
>
> Can't you extend the makefile project to pass in a makefile and have that be the driver for those custom commands?
> --
> https://code.launchpad.net/~zyga/snapcraft/hostapd-example/+merge/271336
> You are the owner of lp:~zyga/snapcraft/hostapd-example.

Unmerged revisions

168. By Zygmunt Krynicki

Add hostapd example

This example contains a custom build (from upstream sources, not a
repackaged Debian package) for hostapd. Hostapd is a part of a wifi
access point daemon. It can be used to construct a more complicated snap
which offers simple access point on compatible devices.

Signed-off-by: Zygmunt Krynicki <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'examples/hostapd'
2=== added file 'examples/hostapd/README.rst'
3--- examples/hostapd/README.rst 1970-01-01 00:00:00 +0000
4+++ examples/hostapd/README.rst 2015-09-16 15:45:47 +0000
5@@ -0,0 +1,21 @@
6+Example snapcraft file for hostapd
7+==================================
8+
9+This repository contains an example build of hostapd. It is neither supported
10+nor endorsed by Canonical. Please use it for anything you wish. If you have
11+made any improvements, please share them.
12+
13+Build Instructions
14+==================
15+
16+To build this project just use snapcraft::
17+
18+ $ snapcraft
19+
20+Note that you need snapcraft version at least r167 to build this example.
21+
22+Notable Missing Features
23+========================
24+
25+- Configuration with snappy config hooks
26+- Service with correct configuration
27
28=== added file 'examples/hostapd/icon.png'
29Binary files examples/hostapd/icon.png 1970-01-01 00:00:00 +0000 and examples/hostapd/icon.png 2015-09-16 15:45:47 +0000 differ
30=== added directory 'examples/hostapd/parts'
31=== added symlink 'examples/hostapd/parts/plugins'
32=== target is u'../plugins/'
33=== added directory 'examples/hostapd/plugins'
34=== added file 'examples/hostapd/plugins/README.rst'
35--- examples/hostapd/plugins/README.rst 1970-01-01 00:00:00 +0000
36+++ examples/hostapd/plugins/README.rst 2015-09-16 15:45:47 +0000
37@@ -0,0 +1,4 @@
38+This directory contains a local "custom" plugin that aids in building this
39+snap. It is symlinked from parts/plugins as that's what the current version of
40+snapcraft requires. This will change later so that the symlink is no longer
41+needed.
42
43=== added file 'examples/hostapd/plugins/x-custom.yaml'
44--- examples/hostapd/plugins/x-custom.yaml 1970-01-01 00:00:00 +0000
45+++ examples/hostapd/plugins/x-custom.yaml 2015-09-16 15:45:47 +0000
46@@ -0,0 +1,9 @@
47+module: x_custom
48+options:
49+ source:
50+ required: true
51+ source-type:
52+ source-tag:
53+ source-branch:
54+ custom-cmds:
55+ required: true
56
57=== added file 'examples/hostapd/plugins/x_custom.py'
58--- examples/hostapd/plugins/x_custom.py 1970-01-01 00:00:00 +0000
59+++ examples/hostapd/plugins/x_custom.py 2015-09-16 15:45:47 +0000
60@@ -0,0 +1,74 @@
61+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
62+#
63+# Copyright (C) 2015 Canonical Ltd
64+#
65+# This program is free software: you can redistribute it and/or modify
66+# it under the terms of the GNU General Public License version 3 as
67+# published by the Free Software Foundation.
68+#
69+# This program is distributed in the hope that it will be useful,
70+# but WITHOUT ANY WARRANTY; without even the implied warranty of
71+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72+# GNU General Public License for more details.
73+#
74+# You should have received a copy of the GNU General Public License
75+# along with this program. If not, see <http://www.gnu.org/licenses/>.
76+
77+
78+"""Implementation of the "custom" part type."""
79+
80+import shlex
81+
82+import snapcraft
83+
84+
85+class CustomPlugin(snapcraft.BasePlugin):
86+
87+ """
88+ Snapcraft plugin for custom builds.
89+
90+ This plugin is closer to Debian packaging than to "we know better" canned
91+ environments. It is most useful with parts that are close but not quite
92+ entirely supported by other part types.
93+
94+ This plugin/type exposes one mandatory command (or list of commands):
95+
96+ custom-cmds:
97+ This command must configure the source tree for building. The commands
98+ have access to quasi variables for the name of the part being built
99+ $SNAPCRAFT_PART_NAME, build directory $SNAPCRAFT_BUILD_DIR and the
100+ installation directory $SNAPCRAFT_PART_INSTALL_DIR. Those are not real
101+ shell variables, instead they are expanded before the command is
102+ executed. This is a limitation of the current version of snapcraft.
103+ """
104+
105+ def build(self):
106+ """Build a custom snap part."""
107+ def make_cmd_list(cmd):
108+ if isinstance(cmd, list):
109+ return [[
110+ cmd_split_part.replace(
111+ '$SNAPCRAFT_PART_INSTALL_DIR', self.installdir
112+ ).replace(
113+ '$SNAPCRAFT_PART_BUILD_DIR', self.builddir
114+ ).replace(
115+ '$SNAPCRAFT_PART_NAME', self.name
116+ )
117+ for cmd_split_part in shlex.split(cmd_part)
118+ ] for cmd_part in cmd]
119+ elif isinstance(cmd, str):
120+ return make_cmd_list([cmd])
121+ elif isinstance(cmd, None):
122+ return []
123+
124+ def dispatch_cmd_list(cmd_list):
125+ for cmd in cmd_list:
126+ if not self.run(cmd):
127+ return False
128+ return True
129+
130+ return dispatch_cmd_list(make_cmd_list(self.options.custom_cmds))
131+
132+ def pull(self):
133+ """Pull the source of a custom snap part."""
134+ return self.handle_source_options()
135
136=== added file 'examples/hostapd/snapcraft.yaml'
137--- examples/hostapd/snapcraft.yaml 1970-01-01 00:00:00 +0000
138+++ examples/hostapd/snapcraft.yaml 2015-09-16 15:45:47 +0000
139@@ -0,0 +1,24 @@
140+name: hostapd
141+summary: HostAP Daemon
142+icon: icon.png
143+description: >
144+ User space IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator
145+version: 2.4-1
146+vendor: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
147+parts:
148+ hostapd:
149+ type: x-custom
150+ source: https://w1.fi/releases/hostapd-2.4.tar.gz
151+ source-type: tar
152+ custom-cmds:
153+ - cp hostapd/defconfig hostapd/.config
154+ - sed -i -e 's/#CONFIG_LIBNL32=y/CONFIG_LIBNL32=y/g' hostapd/.config
155+ - make -C hostapd
156+ - make -C hostapd install BINDIR=/usr/bin DESTDIR=$SNAPCRAFT_PART_INSTALL_DIR
157+ - strip -v $SNAPCRAFT_PART_INSTALL_DIR/usr/bin/*
158+binaries:
159+ - name: hostapd
160+ security-template: unconfined
161+ - name: hostapd-cli
162+ exec: hostapd_cli
163+ security-template: unconfined

Subscribers

People subscribed via source and target branches