From ea1db36f1f62889ddcf4dbf8ca85409619d4424c Mon Sep 17 00:00:00 2001 From: William Pitcock 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 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?= 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 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