aboutsummaryrefslogtreecommitdiffstats
path: root/main/abuild/abuild-check.patch
blob: 2df7f5809e844d1580c1e72f0a1ab15d04294e75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
From ea1db36f1f62889ddcf4dbf8ca85409619d4424c Mon Sep 17 00:00:00 2001
From: William Pitcock <nenolod@dereferenced.org>
Date: Sun, 29 Jan 2017 09:47:25 +0000
Subject: [PATCH 1/3] abuild: implement check and $checkdepends support.

The check() function is an APKBUILD overridable function which runs a testsuite.  The packages listed in
$checkdepends are packages which will be installed at build time only if check() will be run.
---
 abuild.in | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/abuild.in b/abuild.in
index 2b2d23b..aa1fe09 100644
--- a/abuild.in
+++ b/abuild.in
@@ -66,6 +66,12 @@ cross_compiling() {
 	test "$CBUILD" != "$CHOST" -a -n "$CBUILDROOT"
 }
 
+want_check() {
+	cross_compiling && return 1
+	options_has "!check" && return 1
+	return 0
+}
+
 cleanup() {
 	local i=
 	[ -z "$subpkgdir" ] && set_xterm_title ""
@@ -199,6 +205,7 @@ default_sanitycheck() {
 	[ -n "$pkguser" ] && spell_error pkguser pkgusers
 	[ -n "$pkggroup" ] && spell_error pkggroup pkggroups
 	[ -n "$subpackage" ] && spell_error subpackage subpackages
+	[ -n "$checkdepend" ] && spell_error checkdepend checkdepends
 
 	check_maintainer || die "Provide a valid RFC822 maintainer address"
 
@@ -1365,18 +1372,21 @@ create_apks() {
 }
 
 build_abuildrepo() {
-	local d apk _build=build
+	local d apk _build=build _check=check
 	if ! is_function package; then
 		# if package() is missing then build is called from rootpkg
 		_build=true
 	fi
+	if ! want_check; then
+		_check=true
+	fi
 	if ! apk_up2date || [ -n "$force" ]; then
 		# check early if we have abuild key
 		abuild-sign --installed || return 1
 		logcmd "building $repo/$pkgname-$pkgver-r$pkgrel"
 		sanitycheck && builddeps && clean && fetch && unpack \
-			&& prepare && mkusers && $_build && rootpkg \
-			&& cleanup $CLEANUP \
+			&& prepare && mkusers && $_build && $_check \
+			&& rootpkg && cleanup $CLEANUP \
 			|| return 1
 	fi
 	update_abuildrepo_index
@@ -1417,6 +1427,15 @@ update_abuildrepo_index() {
 	done
 }
 
+# predefined function check
+default_check() {
+	warning "APKBUILD does not run any tests - define a check() function!"
+}
+
+check() {
+	default_check
+}
+
 # predefined splitfunc doc
 default_doc() {
 	depends="$depends_doc"
@@ -1715,11 +1734,14 @@ parse_aports_makedepends() {
 		subpackages=
 		depends=
 		makedepends=
+		checkdepends=
 		. $i
 		dir=${i%/APKBUILD}
 		deps=
 		# filter out conflicts from deps and version info
-		for j in $depends $makedepends; do
+		wantdepends="$depends $makedepends"
+		want_check && wantdepends="$wantdepends $checkdepends"
+		for j in $wantdepends; do
 			case "$j" in
 				!*) continue;;
 			esac
@@ -1792,6 +1814,7 @@ calcdeps() {
 		done
 	else
 		[ -z "$makedepends" ] && makedepends="$makedepends_build $makedepends_host"
+		want_check && makedepends="$makedepends $checkdepends"
 		for i in $1 $depends $makedepends; do
 			[ "$pkgname" = "${i%%[<>=]*}" ] && continue
 			list_has $i $builddeps && continue
@@ -2147,6 +2170,7 @@ usage() {
 
 		Commands:
 		  build       Compile and install package into \$pkgdir
+		  check       Run any defined tests concerning the package
 		  checksum    Generate checksum to be included in APKBUILD
 		  clean       Remove temp build and install dirs
 		  cleancache  Remove downloaded files from \$SRCDEST
-- 
2.11.1

From 7c1609b1bb4b6b7219b21b0d2750fcfaf02d63bc Mon Sep 17 00:00:00 2001
From: William Pitcock <nenolod@dereferenced.org>
Date: Sun, 29 Jan 2017 09:50:29 +0000
Subject: [PATCH 2/3] sample apkbuild: document check() function usage

---
 sample.APKBUILD | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sample.APKBUILD b/sample.APKBUILD
index a95fec2..30184c5 100644
--- a/sample.APKBUILD
+++ b/sample.APKBUILD
@@ -43,4 +43,11 @@ package() {
 	# install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
 }
 
+check() {
+	# uncomment the 2 lines below if there is a testsuite.  we assume the testsuite
+	# is run using "make check", which is the default for autotools-based build systems.
+	# cd "$builddir"
+	# make check || return 1
+}
+
 md5sums="" #generate with 'abuild checksum'
-- 
2.11.1

From 14f8fcfb372f9f9ab877c33f309431aa2043c097 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Tue, 31 Jan 2017 10:20:14 +0200
Subject: [PATCH 3/3] apkbuild-cpan: fix warnings, improve recreate, add check
 support

---
 apkbuild-cpan.in | 62 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 47 insertions(+), 15 deletions(-)

diff --git a/apkbuild-cpan.in b/apkbuild-cpan.in
index 5566f8e..688df6e 100644
--- a/apkbuild-cpan.in
+++ b/apkbuild-cpan.in
@@ -3,7 +3,10 @@
 
 use strict;
 use warnings;
-use feature qw(:5.10);
+use 5.016;
+use feature "switch";
+no if $] >= 5.018, warnings => "experimental::smartmatch";
+
 use LWP::UserAgent;
 use LWP::ConnCache;
 use CPAN::Meta;
@@ -21,9 +24,8 @@ my $package_mappings = {
 };
 our $packager = "";
 my $template = <<'EOF';
-# Automatically generated by apkbuild-cpan, template 1
-# Contributor: [% packager %]
-# Maintainer: [% packager %]
+# Automatically generated by apkbuild-cpan, template 2
+[% authors %]
 pkgname=[% pkgname %]
 _pkgreal=[% pkgreal %]
 pkgver=[% pkgver %]
@@ -34,8 +36,10 @@ arch="noarch"
 license="GPL PerlArtistic"
 cpandepends=""
 cpanmakedepends=""
+cpancheckdepends=""
 depends="$cpandepends"
 makedepends="perl-dev $cpanmakedepends"
+checkdepends="$cpancheckdepends"
 subpackages="$pkgname-doc"
 source="[% source %]"
 builddir="$srcdir/$_pkgreal-$pkgver"
@@ -59,6 +63,10 @@ package() {
 	:
 }
 
+check() {
+	:
+}
+
 EOF
 
 our $ua = LWP::UserAgent->new();
@@ -66,8 +74,7 @@ our $json = JSON->new;
 $ua->env_proxy;
 $ua->conn_cache(LWP::ConnCache->new());
 
-sub read_file
-{
+sub read_file {
 	my ($filename) = @_;
 	local $/;
 	open my $fh, "<", $filename or die "could not open $filename: $!";
@@ -76,10 +83,15 @@ sub read_file
 
 sub read_assignments_from_file {
 	my ($filename) = @_;
+	return () if ( ! -e $filename );
 	my $text = read_file($filename);
 	my %sline = $text =~ /^(\w+)\s*=\s*([^\"\n]*)$/mg;
 	my %mline = $text =~ /^(\w+)\s*=\s*\"([^\"]*)\"$/mg;
 	my %hash = ( %sline, %mline );
+
+	my $authors = join("\n", $text =~ /^# Contributor: .*$/mg, $text =~ /^# Maintainer: .*$/mg);
+	$hash{'authors'} = $authors if length($authors) > 1;
+
 	return \%hash;
 }
 
@@ -96,12 +108,13 @@ sub read_apkbuild {
 }
 
 sub write_apkbuild {
-	my ($distdata) = @_;
+	my ($distdata, $authors) = @_;
 
 	my $cpanid = $distdata->{releases}[0]->{cpanid};
 	$cpanid = substr($cpanid, 0, 1) . "/" . substr($cpanid, 0, 2) . "/$cpanid";
+
 	my %repl = (
-		packager => $packager,
+		authors  => ($authors or "# Contributor: $packager\n# Maintainer: $packager"),
 		pkgname  => map_cpan_to_apk($distdata->{name}),
 		pkgreal  => $distdata->{name},
 		pkgver   => $distdata->{releases}[0]->{version},
@@ -147,7 +160,8 @@ sub parse_deps {
 		my $pkgname = map_cpan_to_apk($distdata->{name});
 		$deps .= "$pkgname ";
 	}
-	$deps =~ s/\s+$//;
+	$deps =~ s/\h+/ /g;
+	$deps =~ s/ $//;
 	return $deps;
 
 }
@@ -162,6 +176,7 @@ sub update_functions {
 	my $metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
 	my $prepare_func;
 	my $build_func;
+	my $check_func;
 	my $package_func;
 
 	my $text = read_file "APKBUILD";
@@ -203,7 +218,7 @@ EOF
 build() {
 	cd "$builddir"
 	export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
-	make && make test
+	make
 }
 EOF
 		$package_func = <<'EOF';
@@ -213,6 +228,13 @@ package() {
 	find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete
 }
 EOF
+		$check_func = <<'EOF';
+check() {
+	cd "$builddir"
+	export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
+	make test
+}
+EOF
 	}
 
 	$text =~ s/^prepare\(\) \{.*?^\}\n/$prepare_func/smg or
@@ -221,6 +243,8 @@ EOF
 		die "Can't replace build function APKBUILD";
 	$text =~ s/^package\(\) \{.*?^\}\n/$package_func/smg or
 		die "Can't replace package function APKBUILD";
+	$text =~ s/^check\(\) \{.*?^\}\n/$check_func/smg or
+		die "Can't replace check function APKBUILD";
 
 	open my $fh, '>', "APKBUILD" or die;
 	print $fh $text;
@@ -251,11 +275,13 @@ sub do_depends {
 	say "CPAN deps: $deps";
 	say "Recommend: " . parse_deps $meta->effective_prereqs->requirements_for('runtime', 'recommends');
 
-	my $makedeps = parse_deps $meta->effective_prereqs->requirements_for('build', 'requires');
-	$makedeps   .= ' ' . parse_deps $meta->effective_prereqs->requirements_for('build', 'recommends');
-	$makedeps   .= ' ' . parse_deps $meta->effective_prereqs->requirements_for('test', 'requires');
-	$makedeps   .= ' ' . parse_deps $meta->effective_prereqs->requirements_for('test', 'recommends');
+	my $makedeps = parse_deps($meta->effective_prereqs->requirements_for('build', 'requires'), $meta->effective_prereqs->requirements_for('build', 'recommends'));
 	say "CPAN build deps: $makedeps";
+	say "CPAN requires: " . parse_deps($meta->effective_prereqs->requirements_for('build', 'requires'));
+	say "CPAN recommds: " . parse_deps($meta->effective_prereqs->requirements_for('build', 'recommends'));
+
+	my $checkdeps = parse_deps($meta->effective_prereqs->requirements_for('test', 'requires'), $meta->effective_prereqs->requirements_for('test', 'recommends'));
+	say "CPAN check deps: $makedeps";
 
 	my $text = read_file "APKBUILD";
 	if ($abstract) {
@@ -274,6 +300,8 @@ sub do_depends {
 		die "Can't find cpandepends line in APKBUILD";
 	$text =~ s/^cpanmakedepends=\"([^\"]*)\"$/cpanmakedepends=\"$makedeps\"/mg or
 		die "Can't find cpanmakedepends line in APKBUILD";
+	$text =~ s/^cpancheckdepends=\"([^\"]*)\"$/cpancheckdepends=\"$checkdeps\"/mg or
+		die "Can't find cpancheckdepends line in APKBUILD";
 
 	open my $fh, '>', "APKBUILD" or die;
 	print $fh $text;
@@ -282,6 +310,7 @@ sub do_depends {
 
 sub get_data {
 	my $apkbuild = read_apkbuild;
+	$apkbuild->{_pkgreal} or die "Not apkbuild-cpan generated APKBUILD";
 	my $response = $ua->get("http://search.cpan.org/api/dist/$apkbuild->{_pkgreal}");
 	$response->is_success or die $response->status_line;
 	my $distdata = $json->decode($response->decoded_content);
@@ -293,6 +322,9 @@ sub get_data {
 my $abuild_conf = read_assignments_from_file("/etc/abuild.conf");
 $packager = $abuild_conf->{PACKAGER} if $abuild_conf->{PACKAGER};
 
+my $user_abuild_conf = read_assignments_from_file($ENV{"HOME"} . "/.abuild/abuild.conf");
+$packager = $user_abuild_conf->{PACKAGER} if $user_abuild_conf->{PACKAGER};
+
 given ( $ARGV[0] ) {
 	when ("create") {
 		my $module = $ARGV[1];
@@ -319,7 +351,7 @@ given ( $ARGV[0] ) {
 	}
 	when ("recreate") {
 		my ($apkbuild, $distdata) = get_data;
-		write_apkbuild($distdata);
+		write_apkbuild($distdata, $apkbuild->{authors});
 		prepare_tree;
 		update_functions;
 		do_depends;
-- 
2.11.1

From c909c82ac22563b1235082a73ee1d35fdf1c4b86 Mon Sep 17 00:00:00 2001
From: William Pitcock <nenolod@dereferenced.org>
Date: Tue, 28 Feb 2017 08:22:36 +0000
Subject: [PATCH] abuild: expand on APKBUILD check() warning message

---
 abuild.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/abuild.in b/abuild.in
index b9ab5d6..22bd454 100644
--- a/abuild.in
+++ b/abuild.in
@@ -1456,7 +1456,9 @@ update_abuildrepo_index() {
 
 # predefined function check
 default_check() {
-	warning "APKBUILD does not run any tests - define a check() function!"
+	warning "APKBUILD does not run any tests!"
+	msg2 "Alpine policy will soon require that packages have any relevant testsuites run during the build process."
+	msg2 "To fix, either define a check() function, or declare !check in \$options to indicate the package does not have a testsuite."
 }
 
 check() {
-- 
2.11.1