Merge lp:~mterry/pkgme/autoconf-helpers into lp:pkgme

Proposed by Michael Terry
Status: Merged
Merged at revision: 50
Proposed branch: lp:~mterry/pkgme/autoconf-helpers
Merge into: lp:pkgme
Diff against target: 418 lines (+214/-85)
11 files modified
pkgme/backend.py (+4/-1)
pkgme/backends/vala/homepage (+2/-31)
pkgme/backends/vala/package_name (+2/-43)
pkgme/backends/vala/want (+5/-8)
pkgme/helpers/pkgme_autoconf_config (+31/-0)
pkgme/helpers/pkgme_autoconf_description (+29/-0)
pkgme/helpers/pkgme_autoconf_homepage (+23/-0)
pkgme/helpers/pkgme_autoconf_initfield (+39/-0)
pkgme/helpers/pkgme_autoconf_maintainer (+29/-0)
pkgme/helpers/pkgme_autoconf_package_name (+42/-0)
pkgme/project_info.py (+8/-2)
To merge this branch: bzr merge lp:~mterry/pkgme/autoconf-helpers
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+49697@code.launchpad.net

Description of the change

We've talked about allowing a series of helper functions or programs for dealing with autotools projects (and maybe similar helper utilities for other build systems too).

I've taken the liberty of refactoring the vala backend autoconf code into several autoconf helper programs.

This should ease the burden of creating future autoconf-based backends.

To post a comment you must log in.
lp:~mterry/pkgme/autoconf-helpers updated
51. By Michael Terry

whoops, remove some debugging code

Revision history for this message
James Westby (james-w) wrote :

Hi,

That's a nice simple change, thanks.

I wonder if we want a set of helpers, or we want these to be part of an autoconf
backend?

We could make it possible for the vala backend to query the autoconf backend for
these values.

Thanks,

James

review: Needs Information
Revision history for this message
Michael Terry (mterry) wrote :

I'm not sure if an autoconf backend would be useful on its own? Plus, helper scripts have the possibility of doing more than just the set of backend functions (e.g. the pkgme_autoconf_initfield helper script).

I could maybe imagine a need for non-build-system-related helper scripts in future...? In which case, where to put them?

If you were thinking it might eventually be useful for inheritance, I would disagree, as a backend like vala may eventually want to support other build systems (e.g. cmake) too and that would be difficult with inheritance.

Revision history for this message
James Westby (james-w) wrote :

Hi,

Sorry for the delay. You make good points, so I refactored some of the code
to reduce some duplication (that was already there), and merged.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/backend.py'
2--- pkgme/backend.py 2011-02-05 21:06:45 +0000
3+++ pkgme/backend.py 2011-02-14 20:14:26 +0000
4@@ -118,11 +118,14 @@
5 script_path = os.path.join(
6 os.path.abspath(self.basepath), self.WANT_SCRIPT_NAME)
7 if os.path.exists(script_path):
8+ helperpath = os.path.join(os.path.dirname(os.path.dirname(self.basepath)), 'helpers')
9+ env = os.environ.copy()
10+ env['PATH'] = env['PATH'] + ':' + helperpath if 'PATH' in env else helperpath
11 try:
12 proc = subprocess.Popen(
13 [script_path], stdout=subprocess.PIPE,
14 stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
15- cwd=path)
16+ cwd=path, env=env)
17 except OSError as e:
18 if e.errno == errno.ENOENT:
19 raise ExternalHelperFailed(
20
21=== modified file 'pkgme/backends/vala/homepage'
22--- pkgme/backends/vala/homepage 2010-11-12 17:57:49 +0000
23+++ pkgme/backends/vala/homepage 2011-02-14 20:14:26 +0000
24@@ -1,7 +1,7 @@
25 #!/bin/sh
26 # -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
27 #
28-# © 2010 Canonical Ltd
29+# © 2010,2011 Canonical Ltd
30 #
31 # This program is free software; you can redistribute it and/or modify
32 # it under the terms of the GNU General Public License as published by
33@@ -18,33 +18,4 @@
34 # Authors: Michael Terry <michael.terry@canonical.com>
35 # =====================================================================
36
37-# The homepage may be in AC_INIT, in the 5th field
38-# AC_INIT([Example Project],[1.0],[http://bugs.example.com/],[example-project],[http://example.com/])
39-
40-CONFIG_NAME=configure.ac
41-if [ ! -e "$CONFIG_NAME" ]; then
42- CONFIG_NAME=configure.in
43- if [ ! -e "$CONFIG_NAME" ]; then
44- # not an autotools project
45- exit 0
46- fi
47-fi
48-
49-acinit=$(grep --max-count=1 AC_INIT "$CONFIG_NAME" 2>/dev/null)
50-
51-initfield() {
52- rv=$(echo $1 | sed 's/AC_INIT//')
53- rv=$(echo $rv | cut -d, -f"$2")
54- # Find end (either , or ending ')')
55- rv=$(echo $rv | sed 's/[[( ]*\([^,)]*\).*/\1/')
56- # chop off ending odd characters
57- rv=$(echo $rv | sed 's/[] ]*$//')
58- echo $rv
59-}
60-
61-tarname=$(initfield "$acinit" 5)
62-if [ -n "$tarname" ]; then
63- echo "$tarname"
64-fi
65-
66-exit 0
67+pkgme_autoconf_homepage
68
69=== modified file 'pkgme/backends/vala/package_name'
70--- pkgme/backends/vala/package_name 2010-11-12 17:57:49 +0000
71+++ pkgme/backends/vala/package_name 2011-02-14 20:14:26 +0000
72@@ -1,7 +1,7 @@
73 #!/bin/sh
74 # -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
75 #
76-# © 2010 Canonical Ltd
77+# © 2010,2011 Canonical Ltd
78 #
79 # This program is free software; you can redistribute it and/or modify
80 # it under the terms of the GNU General Public License as published by
81@@ -18,45 +18,4 @@
82 # Authors: Michael Terry <michael.terry@canonical.com>
83 # =====================================================================
84
85-CONFIG_NAME=configure.ac
86-if [ ! -e "$CONFIG_NAME" ]; then
87- CONFIG_NAME=configure.in
88- if [ ! -e "$CONFIG_NAME"]; then
89- # not an autotools project. Don't know how to grab name
90- exit 0
91- fi
92-fi
93-
94-# So this could be set up multiple ways.
95-# AC_INIT([Example Project],[1.0],[http://bugs.example.com/],[example-project],[http://example.com/])
96-# AC_INIT([Example Project],[1.0])
97-# First is easy, we just grab the 4th field. Second is harder, and requires us
98-# to simplify the string as autoconf would.
99-
100-acinit=$(grep --max-count=1 AC_INIT "$CONFIG_NAME" 2>/dev/null)
101-
102-initfield() {
103- rv=$(echo $1 | sed 's/AC_INIT//')
104- rv=$(echo $rv | cut -d, -f"$2")
105- # Find end (either , or ending ')')
106- rv=$(echo $rv | sed 's/[[( ]*\([^,)]*\).*/\1/')
107- # chop off ending odd characters
108- rv=$(echo $rv | sed 's/[] ]*$//')
109- echo $rv
110-}
111-
112-tarname=$(initfield "$acinit" 4)
113-if [ -n "$tarname" ]; then
114- echo "$tarname"
115- exit 0
116-fi
117-
118-# Now we mangle the project name into a tarball name. From the autoconf manual:
119-# "... with `GNU ' stripped, lower-cased, and all characters
120-# other than alphanumerics and underscores are changed to `-'."
121-
122-pkgname=$(initfield "$acinit" 1)
123-pkgname=$(echo $pkgname | sed 's/^GNU //')
124-pkgname=$(echo $pkgname | tr [:upper:] [:lower:])
125-pkgname=$(echo -n $pkgname | tr -c [:alnum:]_ -)
126-echo $pkgname
127+pkgme_autoconf_package_name
128
129=== modified file 'pkgme/backends/vala/want'
130--- pkgme/backends/vala/want 2010-11-12 17:57:49 +0000
131+++ pkgme/backends/vala/want 2011-02-14 20:14:26 +0000
132@@ -1,7 +1,7 @@
133 #!/bin/sh
134 # -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
135 #
136-# © 2010 Canonical Ltd
137+# © 2010,2011 Canonical Ltd
138 #
139 # This program is free software; you can redistribute it and/or modify
140 # it under the terms of the GNU General Public License as published by
141@@ -27,13 +27,10 @@
142 exit 0
143 }
144
145-CONFIG_NAME=configure.ac
146-if [ ! -e "$CONFIG_NAME" ]; then
147- CONFIG_NAME=configure.in
148- if [ ! -e "$CONFIG_NAME" ]; then
149- # not an autotools project
150- end 0
151- fi
152+# Require autoconf for now
153+CONFIG_NAME=$(pkgme_autoconf_config)
154+if [ -z "$CONFIG_NAME" ]; then
155+ end 0
156 fi
157
158 # Scan toplevel and immediate subdirectories for Vala files
159
160=== added directory 'pkgme/helpers'
161=== added file 'pkgme/helpers/pkgme_autoconf_config'
162--- pkgme/helpers/pkgme_autoconf_config 1970-01-01 00:00:00 +0000
163+++ pkgme/helpers/pkgme_autoconf_config 2011-02-14 20:14:26 +0000
164@@ -0,0 +1,31 @@
165+#!/bin/sh
166+# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
167+#
168+# © 2010,2011 Canonical Ltd
169+#
170+# This program is free software; you can redistribute it and/or modify
171+# it under the terms of the GNU General Public License as published by
172+# the Free Software Foundation; version 3 of the License.
173+#
174+# This program is distributed in the hope that it will be useful, but
175+# WITHOUT ANY WARRANTY; without even the implied warranty of
176+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
177+# General Public License for more details.
178+#
179+# You should have received a copy of the GNU General Public License
180+# along with this program. If not, see <http://www.gnu.org/licenses/>.
181+#
182+# Authors: Michael Terry <michael.terry@canonical.com>
183+# =====================================================================
184+
185+CONFIG_NAME=configure.ac
186+if [ ! -e "$CONFIG_NAME" ]; then
187+ CONFIG_NAME=configure.in
188+ if [ ! -e "$CONFIG_NAME" ]; then
189+ # not an autotools project
190+ exit 0
191+ fi
192+fi
193+
194+echo "$CONFIG_NAME"
195+exit 0
196
197=== added file 'pkgme/helpers/pkgme_autoconf_description'
198--- pkgme/helpers/pkgme_autoconf_description 1970-01-01 00:00:00 +0000
199+++ pkgme/helpers/pkgme_autoconf_description 2011-02-14 20:14:26 +0000
200@@ -0,0 +1,29 @@
201+#!/bin/sh
202+# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
203+#
204+# © 2010,2011 Canonical Ltd
205+#
206+# This program is free software; you can redistribute it and/or modify
207+# it under the terms of the GNU General Public License as published by
208+# the Free Software Foundation; version 3 of the License.
209+#
210+# This program is distributed in the hope that it will be useful, but
211+# WITHOUT ANY WARRANTY; without even the implied warranty of
212+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
213+# General Public License for more details.
214+#
215+# You should have received a copy of the GNU General Public License
216+# along with this program. If not, see <http://www.gnu.org/licenses/>.
217+#
218+# Authors: Michael Terry <michael.terry@canonical.com>
219+# =====================================================================
220+
221+# There isn't a well-defined location for a description in autoconf packages.
222+# So just look in several common places.
223+
224+if [ -e "README" ]; then
225+ cat README
226+elif [ -e "README.txt" ]; then
227+ cat README.txt
228+fi
229+exit 0
230
231=== added file 'pkgme/helpers/pkgme_autoconf_homepage'
232--- pkgme/helpers/pkgme_autoconf_homepage 1970-01-01 00:00:00 +0000
233+++ pkgme/helpers/pkgme_autoconf_homepage 2011-02-14 20:14:26 +0000
234@@ -0,0 +1,23 @@
235+#!/bin/sh
236+# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
237+#
238+# © 2010,2011 Canonical Ltd
239+#
240+# This program is free software; you can redistribute it and/or modify
241+# it under the terms of the GNU General Public License as published by
242+# the Free Software Foundation; version 3 of the License.
243+#
244+# This program is distributed in the hope that it will be useful, but
245+# WITHOUT ANY WARRANTY; without even the implied warranty of
246+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
247+# General Public License for more details.
248+#
249+# You should have received a copy of the GNU General Public License
250+# along with this program. If not, see <http://www.gnu.org/licenses/>.
251+#
252+# Authors: Michael Terry <michael.terry@canonical.com>
253+# =====================================================================
254+
255+# The homepage is the 5th field of AC_INIT
256+pkgme_autoconf_initfield 5
257+exit 0
258
259=== added file 'pkgme/helpers/pkgme_autoconf_initfield'
260--- pkgme/helpers/pkgme_autoconf_initfield 1970-01-01 00:00:00 +0000
261+++ pkgme/helpers/pkgme_autoconf_initfield 2011-02-14 20:14:26 +0000
262@@ -0,0 +1,39 @@
263+#!/bin/sh
264+# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
265+#
266+# © 2010,2011 Canonical Ltd
267+#
268+# This program is free software; you can redistribute it and/or modify
269+# it under the terms of the GNU General Public License as published by
270+# the Free Software Foundation; version 3 of the License.
271+#
272+# This program is distributed in the hope that it will be useful, but
273+# WITHOUT ANY WARRANTY; without even the implied warranty of
274+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
275+# General Public License for more details.
276+#
277+# You should have received a copy of the GNU General Public License
278+# along with this program. If not, see <http://www.gnu.org/licenses/>.
279+#
280+# Authors: Michael Terry <michael.terry@canonical.com>
281+# =====================================================================
282+
283+# Usage: pkgme_autoconf_initfield FIELD
284+
285+# Example AC_INIT line:
286+# AC_INIT([Example Project],[1.0],[http://bugs.example.com/],[example-project],[http://example.com/])
287+
288+CONFIG_NAME=$(pkgme_autoconf_config)
289+if [ -z "$CONFIG_NAME" ]; then
290+ exit 0
291+fi
292+
293+acinit=$(grep --max-count=1 AC_INIT "$CONFIG_NAME" 2>/dev/null)
294+rv=$(echo $acinit | sed 's/AC_INIT//')
295+rv=$(echo $rv | cut -d, -f"$1")
296+# Find end (either , or ending ')')
297+rv=$(echo $rv | sed 's/[[( ]*\([^,)]*\).*/\1/')
298+# chop off ending odd characters
299+rv=$(echo $rv | sed 's/[] ]*$//')
300+echo $rv
301+exit 0
302
303=== added file 'pkgme/helpers/pkgme_autoconf_maintainer'
304--- pkgme/helpers/pkgme_autoconf_maintainer 1970-01-01 00:00:00 +0000
305+++ pkgme/helpers/pkgme_autoconf_maintainer 2011-02-14 20:14:26 +0000
306@@ -0,0 +1,29 @@
307+#!/bin/sh
308+# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
309+#
310+# © 2010,2011 Canonical Ltd
311+#
312+# This program is free software; you can redistribute it and/or modify
313+# it under the terms of the GNU General Public License as published by
314+# the Free Software Foundation; version 3 of the License.
315+#
316+# This program is distributed in the hope that it will be useful, but
317+# WITHOUT ANY WARRANTY; without even the implied warranty of
318+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
319+# General Public License for more details.
320+#
321+# You should have received a copy of the GNU General Public License
322+# along with this program. If not, see <http://www.gnu.org/licenses/>.
323+#
324+# Authors: Michael Terry <michael.terry@canonical.com>
325+# =====================================================================
326+
327+# There isn't a well-defined location for maintainer info in autoconf packages.
328+# So just look in several common places.
329+
330+if [ -e "MAINTAINERS" ]; then
331+ cat MAINTAINERS
332+elif [ -e "AUTHORS" ]; then
333+ cat AUTHORS
334+fi
335+exit 0
336
337=== added file 'pkgme/helpers/pkgme_autoconf_package_name'
338--- pkgme/helpers/pkgme_autoconf_package_name 1970-01-01 00:00:00 +0000
339+++ pkgme/helpers/pkgme_autoconf_package_name 2011-02-14 20:14:26 +0000
340@@ -0,0 +1,42 @@
341+#!/bin/sh
342+# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
343+#
344+# © 2010,2011 Canonical Ltd
345+#
346+# This program is free software; you can redistribute it and/or modify
347+# it under the terms of the GNU General Public License as published by
348+# the Free Software Foundation; version 3 of the License.
349+#
350+# This program is distributed in the hope that it will be useful, but
351+# WITHOUT ANY WARRANTY; without even the implied warranty of
352+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
353+# General Public License for more details.
354+#
355+# You should have received a copy of the GNU General Public License
356+# along with this program. If not, see <http://www.gnu.org/licenses/>.
357+#
358+# Authors: Michael Terry <michael.terry@canonical.com>
359+# =====================================================================
360+
361+# The package name could be set up multiple ways.
362+# AC_INIT([Example Project],[1.0],[http://bugs.example.com/],[example-project],[http://example.com/])
363+# AC_INIT([Example Project],[1.0])
364+# First is easy; we just grab the 4th field. Second is harder and requires us
365+# to simplify the string as autoconf would.
366+
367+tarname=$(pkgme_autoconf_initfield 4)
368+if [ -n "$tarname" ]; then
369+ echo "$tarname"
370+ exit 0
371+fi
372+
373+# Now we mangle the project name into a tarball name. From the autoconf manual:
374+# "... with `GNU ' stripped, lower-cased, and all characters
375+# other than alphanumerics and underscores are changed to `-'."
376+
377+pkgname=$(pkgme_autoconf_initfield 1)
378+pkgname=$(echo "$pkgname" | sed 's/^GNU //')
379+pkgname=$(echo "$pkgname" | tr [:upper:] [:lower:])
380+pkgname=$(echo -n "$pkgname" | tr -c [:alnum:]_ -)
381+echo "$pkgname"
382+exit 0
383
384=== modified file 'pkgme/project_info.py'
385--- pkgme/project_info.py 2011-02-05 21:06:45 +0000
386+++ pkgme/project_info.py 2011-02-14 20:14:26 +0000
387@@ -41,11 +41,14 @@
388 def get_all(self, keys):
389 script_path = os.path.join(self.basepath, self.INFO_SCRIPT_NAME)
390 if os.path.exists(script_path):
391+ helperpath = os.path.join(os.path.dirname(os.path.dirname(self.basepath)), 'helpers')
392+ env = os.environ.copy()
393+ env['PATH'] = env['PATH'] + ':' + helperpath if 'PATH' in env else helperpath
394 try:
395 proc = subprocess.Popen(
396 [script_path], stdout=subprocess.PIPE,
397 stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
398- cwd=self.cwd)
399+ cwd=self.cwd, env=env)
400 except OSError as e:
401 if e.errno == errno.ENOENT:
402 raise ExternalHelperFailed(
403@@ -65,11 +68,14 @@
404 def _get(self, key):
405 script_path = os.path.join(self.basepath, key)
406 if os.path.exists(script_path):
407+ helperpath = os.path.join(os.path.dirname(os.path.dirname(self.basepath)), 'helpers')
408+ env = os.environ.copy()
409+ env['PATH'] = env['PATH'] + ':' + helperpath if 'PATH' in env else helperpath
410 try:
411 proc = subprocess.Popen(
412 [script_path], stdout=subprocess.PIPE,
413 stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
414- cwd=self.cwd)
415+ cwd=self.cwd, env=env)
416 except OSError as e:
417 if e.errno == errno.ENOENT:
418 raise ExternalHelperFailed(

Subscribers

People subscribed via source and target branches