From 603373be839a87cb0ee97a16f4a243d86bbae72e Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Wed, 28 Oct 2020 09:42:21 +0000 Subject: [PATCH] Improve Vala support (closes #13002) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is mostly work by Daniel Espinosa, but any bugs are Reuben Thomas’s, who finished it off! * NEWS: mention these changes. * bin/automake.in: generated C files go in builddir, not srcdir. Distribute the header files generated from VAPI files. * t/vala-libs-distcheck.sh: new test for “make distcheck” of a Vala library. * t/vala-libs-vpath.sh: new test for a VPATH build of a Vala library. * t/vala-libs.sh: add local VAPIs used as external --package to test * t/vala-{,non}-recursive-setup.sh: we need to make maintainer-clean at one point to remove stamp files to avoid confusing a VPATH build performed after a non-VPATH build. * t/vala-{parallel,per-target-flags,recursive-setup,vpath}.sh: some test paths need changing to take into account that generated C files now go in builddir. --- NEWS | 6 ++ bin/automake.in | 44 +++++--- t/list-of-tests.mk | 2 + t/vala-libs-distcheck.sh | 196 ++++++++++++++++++++++++++++++++++ t/vala-libs-vpath.sh | 108 +++++++++++++++++++ t/vala-libs.sh | 49 +++++---- t/vala-non-recursive-setup.sh | 3 +- t/vala-parallel.sh | 4 +- t/vala-per-target-flags.sh | 4 +- t/vala-recursive-setup.sh | 18 ++-- t/vala-vpath.sh | 33 +++--- 11 files changed, 405 insertions(+), 62 deletions(-) create mode 100644 t/vala-libs-distcheck.sh create mode 100644 t/vala-libs-vpath.sh diff --git a/NEWS b/NEWS index 9c69e48d1..010cd3756 100644 --- a/NEWS +++ b/NEWS @@ -81,6 +81,10 @@ New in ?.?.?: - valac argument matching more precise, to avoid garbage in DIST_COMMON. + - Support for Vala in VPATH builds fixed so that both freshly-generated and + distributed C files work, and operation is more reliable with or without + an installed valac. + * Distribution - new variable AM_DISTCHECK_DVI_TARGET, to allow overriding the @@ -91,6 +95,8 @@ New in ?.?.?: - Removed function up_to_date_p in lib/Automake/FileUtils.pm. We believe this function is completely unused. + - Support for in-tree Vala libraries improved. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ New in 1.16.2: diff --git a/bin/automake.in b/bin/automake.in index a88b835a5..31c72382a 100644 --- a/bin/automake.in +++ b/bin/automake.in @@ -5730,13 +5730,18 @@ sub lang_vala_finish_target my $c_file = $vala_file; if ($c_file =~ s/(.*)\.vala$/$1.c/) { - $c_file = "\$(srcdir)/$c_file"; - $output_rules .= "$c_file: \$(srcdir)/${derived}_vala.stamp\n" - . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n" + my $built_c_file = "\$(builddir)/$c_file"; + my $built_dir = dirname $built_c_file; + my $base_c_file = basename $c_file; + $output_rules .= "$built_c_file: \$(builddir)/${derived}_vala.stamp\n" + . "\t\@if test ! -f \$@ && test \$(srcdir) != \$(builddir) && test -n \"\$\$(find -L \$(srcdir)/$c_file -prune -newer \$(srcdir)/$vala_file)\"; then cp -p \$(srcdir)/$c_file $built_c_file; fi\n" + . "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n" . "\t\@if test -f \$@; then :; else \\\n" - . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n" + . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n" + . "\t if test $built_dir != .; then mv $base_c_file $built_dir/; fi \\\n" . "\tfi\n"; - $clean_files{$c_file} = MAINTAINER_CLEAN; + $clean_files{$built_c_file} = DIST_CLEAN; + $clean_files{"\$(srcdir)/$c_file"} = MAINTAINER_CLEAN; } } @@ -5750,11 +5755,11 @@ sub lang_vala_finish_target if (grep (/^$lastflag$/, ('-H', '-h', '--header', '--internal-header', '--vapi', '--internal-vapi', '--gir'))) { - my $headerfile = "\$(srcdir)/$flag"; - $output_rules .= "$headerfile: \$(srcdir)/${derived}_vala.stamp\n" - . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n" + my $headerfile = "\$(builddir)/$flag"; + $output_rules .= "$headerfile: \$(builddir)/${derived}_vala.stamp\n" + . "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n" . "\t\@if test -f \$@; then :; else \\\n" - . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n" + . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n" . "\tfi\n"; # valac is not used when building from dist tarballs @@ -5762,6 +5767,21 @@ sub lang_vala_finish_target push_dist_common ($headerfile); $clean_files{$headerfile} = MAINTAINER_CLEAN; } + if (grep (/$lastflag/, ('--library'))) + { + my $headerfile = "\$(builddir)/$flag"; + $output_rules .= "$headerfile.vapi: \$(builddir)/${derived}_vala.stamp\n" + . "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n" + . "\t\@if test -f \$@; then :; else \\\n" + . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n" + . "\tfi\n"; + + # valac is not used when building from dist tarballs + # distribute the generated files + my $vapi = "$headerfile.vapi"; + push_dist_common ($vapi); + $clean_files{$headerfile.'.vapi'} = MAINTAINER_CLEAN; + } $lastflag = $flag; } } @@ -5785,10 +5805,10 @@ sub lang_vala_finish_target my $verbose = verbose_flag ('VALAC'); my $silent = silent_flag (); - my $stampfile = "\$(srcdir)/${derived}_vala.stamp"; + my $stampfile = "\$(builddir)/${derived}_vala.stamp"; $output_rules .= - "\$(srcdir)/${derived}_vala.stamp: @vala_sources\n". + "\$(builddir)/${derived}_vala.stamp: @vala_sources\n". # Since the C files generated from the vala sources depend on the # ${derived}_vala.stamp file, we must ensure its timestamp is older than # those of the C files generated by the valac invocation below (this is @@ -5796,7 +5816,7 @@ sub lang_vala_finish_target # Thus we need to create the stamp file *before* invoking valac, and to # move it to its final location only after valac has been invoked. "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n". - "\t${verbose}\$(am__cd) \$(srcdir) && $compile @vala_sources\n". + "\t${verbose}$compile \$^\n". "\t${silent}mv -f \$\@-t \$\@\n"; push_dist_common ($stampfile); diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk index f44eed0e5..5359c2242 100644 --- a/t/list-of-tests.mk +++ b/t/list-of-tests.mk @@ -1252,6 +1252,8 @@ t/vala-configure.sh \ t/vala-grepping.sh \ t/vala-headers.sh \ t/vala-libs.sh \ +t/vala-libs-distcheck.sh \ +t/vala-libs-vpath.sh \ t/vala-mix.sh \ t/vala-mix2.sh \ t/vala-non-recursive-setup.sh \ diff --git a/t/vala-libs-distcheck.sh b/t/vala-libs-distcheck.sh new file mode 100644 index 000000000..99f1e902f --- /dev/null +++ b/t/vala-libs-distcheck.sh @@ -0,0 +1,196 @@ +#! /bin/sh +# Copyright (C) 2012-2016 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Building libraries (libtool and static) from Vala sources. +# And use of vapi files to call C code from Vala. + +required="valac cc pkg-config libtoolize GNUmake" +am_create_testdir=empty +. test-init.sh + +cat >> configure.ac << 'END' +AC_INIT([atest],[0.1]) +AC_CONFIG_SRCDIR([data/atest.pc.in]) + +AC_SUBST([API_VERSION],[0]) + +AM_INIT_AUTOMAKE +AM_MAINTAINER_MODE([enable]) + +AC_PROG_CC +AC_PROG_INSTALL +AM_PROG_AR +PKG_PROG_PKG_CONFIG([0.22]) +AM_PROG_VALAC([0.32]) + +PKG_CHECK_MODULES(ATEST, [gio-2.0]) + +LT_INIT +AC_CONFIG_FILES([ + Makefile + + src/Makefile + + src/atest-$API_VERSION.deps:src/atest.deps.in + + data/Makefile + data/atest-$API_VERSION.pc:data/atest.pc.in + +],[], +[API_VERSION='$API_VERSION']) +AC_OUTPUT +END + + +cat > Makefile.am << 'END' +SUBDIRS=data src +END + +mkdir data + +cat > data/atest.pc.in << 'END' +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +datarootdir=@datarootdir@ +datadir=@datadir@ +includedir=@includedir@ + +Name: atest-@API_VERSION@ +Description: atest library +Version: @VERSION@ +Requires: glib-2.0 gobject-2.0 +Libs: -L${libdir} -latest-@API_VERSION@ +Cflags: -I${includedir}/atest-@API_VERSION@ +END + + +cat > data/Makefile.am << 'END' +# pkg-config data +# Note that the template file is called atest.pc.in, but generates a +# versioned .pc file using some magic in AC_CONFIG_FILES. +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = atest-$(API_VERSION).pc + +DISTCLEANFILES = $(pkgconfig_DATA) +EXTRA_DIST = atest.pc.in +END + +mkdir src + +cat > src/atest.deps.in << 'END' +glib-2.0 +END + + +cat > src/atest.vala << 'END' +using GLib; + +namespace Atest { + public class A { + public bool foo() { return false; } + } +} +END + +cat > src/Makefile.am << 'END' +lib_LTLIBRARIES = libatest-@API_VERSION@.la + +libatest_@API_VERSION@_la_SOURCES = \ + atest.vala \ + cservice.c \ + cservice.h \ + $(NULL) + + +libatest_@API_VERSION@_la_CPPFLAGS = \ + -DOKOKIMDEFINED=1 \ + $(NULL) + +libatest_@API_VERSION@_la_CFLAGS = \ + $(ATEST_CFLAGS) \ + $(WARN_CFLAGS) \ + $(NULL) + +libatest_@API_VERSION@_la_LIBADD = \ + $(ATEST_LIBS) \ + $(NULL) + +libatest_@API_VERSION@_la_LDFLAGS = \ + $(WARN_LDFLAGS) \ + $(NULL) + +libatest_@API_VERSION@_la_VALAFLAGS = \ + --vapidir=$(VAPIDIR) \ + --vapidir=$(srcdir) \ + --pkg cservice \ + --thread \ + --target-glib=2.44 \ + --pkg glib-2.0 \ + -H atest.h \ + --library atest-@API_VERSION@ \ + $(NULL) + +header_DATA=atest.h +headerdir=$(includedir)/atest-@API_VERSION@/atest + +atest-@API_VERSION@.deps: + cp atest.deps atest-@API_VERSION@.deps + +vapi_DATA=atest-@API_VERSION@.vapi atest-@API_VERSION@.deps +vapidir=$(VAPIDIR) + +CLEANFILES = atest-@API_VERSION@.deps +END + + +cat > src/cservice.c << 'END' +#include "cservice.h" +int c_service_mu_call (void) +{ + return OKOKIMDEFINED; +} +END + +cat > src/cservice.h << 'END' +int c_service_mu (void); +END + +cat > src/cservice.vapi <<'END' +namespace CService { + public class Mu { + [CCode (cheader_filename = "cservice.h", cname = "c_service_mu_call")] + public int call (); + } +} +END + + +libtoolize +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure + +$MAKE +test -f src/libatest_0_la_vala.stamp +test -f src/libatest-0.la + +$MAKE distcheck + +: + diff --git a/t/vala-libs-vpath.sh b/t/vala-libs-vpath.sh new file mode 100644 index 000000000..330ce23f7 --- /dev/null +++ b/t/vala-libs-vpath.sh @@ -0,0 +1,108 @@ +#! /bin/sh +# Copyright (C) 2012-2016 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Building libraries (libtool and static) from Vala sources. +# And use of vapi files to call C code from Vala. + +required="valac cc pkg-config libtoolize GNUmake" +am_create_testdir=empty +. test-init.sh + +cat >> configure.ac << 'END' +AC_INIT([valalibs],[0.1]) + +AC_CONFIG_MACRO_DIR([m4]) + +AM_INIT_AUTOMAKE +AM_PROG_AR +LT_INIT + +AC_PROG_CC +AC_CONFIG_FILES([Makefile src/Makefile]) + +AM_PROG_VALAC([0.7.3]) +PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4]) + +AC_OUTPUT +END + + +cat > Makefile.am << 'END' +SUBDIRS=src +END + +mkdir src + +cat > src/Makefile.am << 'END' +AUTOMAKE_OPTIONS = subdir-objects +lib_LTLIBRARIES = libservice.la +libservice_la_SOURCES = service.vala cservice.c cservice.h +libservice_la_CPPFLAGS = -DOKOKIMDEFINED=1 +libservice_la_VALAFLAGS = --vapidir=$(srcdir) --pkg cservice --library service +AM_CFLAGS = $(GOBJECT_CFLAGS) +END + +libtoolize +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +cat > src/cservice.c << 'END' +#include "cservice.h" +int c_service_mu_call (void) +{ + return OKOKIMDEFINED; +} +END + +cat > src/cservice.h << 'END' +int c_service_mu (void); +END + +cat > src/cservice.vapi <<'END' +namespace CService { + public class Mu { + [CCode (cheader_filename = "cservice.h", cname = "c_service_mu_call")] + public int call (); + } +} +END + +cat > src/service.vala << 'END' +namespace CService { +public class Generator : Object { + public Generator () { + stdout.printf ("construct generator"); + } + public void init () { + stdout.printf ("init generator"); + } +} +} +END + +mkdir build +cd build +../configure + +$MAKE +pwd +test -f src/libservice_la_vala.stamp +test -f src/libservice.la + + +: + diff --git a/t/vala-libs.sh b/t/vala-libs.sh index 77d1971bc..9bd8a4a2c 100644 --- a/t/vala-libs.sh +++ b/t/vala-libs.sh @@ -32,11 +32,11 @@ END cat > Makefile.am << 'END' AUTOMAKE_OPTIONS = subdir-objects -lib_LIBRARIES = libmu.a +lib_LIBRARIES = libservice.a lib_LTLIBRARIES = src/libzardoz.la -libmu_a_SOURCES = mu.vala mu2.c mu.vapi mu2.h -libmu_a_CPPFLAGS = -DOKOKIMDEFINED=1 -libmu_a_VALAFLAGS = --vapidir=$(srcdir) +libservice_a_SOURCES = service.vala cservice.c cservice.h +libservice_a_CPPFLAGS = -DOKOKIMDEFINED=1 +libservice_a_VALAFLAGS = --vapidir=$(srcdir) --pkg cservice --library service AM_CFLAGS = $(GOBJECT_CFLAGS) src_libzardoz_la_LIBADD = $(GOBJECT_LIBS) src_libzardoz_la_SOURCES = src/zardoz-foo.vala src/zardoz-bar.vala @@ -51,28 +51,37 @@ $AUTOMAKE -a ./configure -cat > mu2.c << 'END' -#include "mu2.h" -int mu2 (void) +cat > cservice.c << 'END' +#include "cservice.h" +int c_service_mu_call (void) { return OKOKIMDEFINED; } END -cat > mu2.h << 'END' -int mu2 (void); +cat > cservice.h << 'END' +int c_service_mu (void); END -cat > mu.vapi <<'END' -[CCode (cheader_filename = "mu2.h", cname = "mu2")] -public int c_mu2 (); +cat > cservice.vapi <<'END' +namespace CService { + public class Mu { + [CCode (cheader_filename = "cservice.h", cname = "c_service_mu_call")] + public int call (); + } +} END -cat > mu.vala << 'END' -int main () -{ - stdout.printf ("mumumu\n"); - return c_mu2 (); +cat > service.vala << 'END' +namespace CService { +public class Generator : Object { + public Generator () { + stdout.printf ("construct generator"); + } + public void init () { + stdout.printf ("init generator"); + } +} } END @@ -87,12 +96,12 @@ public class Foo { END $MAKE -test -f libmu.a +test -f libservice.a test -f src/libzardoz.la -$FGREP "mumumu" mu.c +$FGREP "construct generator" service.c $FGREP "FooFooFoo" src/zardoz-foo.c $FGREP "BarBarBar" src/zardoz-bar.c -test -f libmu_a_vala.stamp +test -f libservice_a_vala.stamp test -f src_libzardoz_la_vala.stamp $MAKE distcheck diff --git a/t/vala-non-recursive-setup.sh b/t/vala-non-recursive-setup.sh index 5fa18d4f5..8113e471c 100644 --- a/t/vala-non-recursive-setup.sh +++ b/t/vala-non-recursive-setup.sh @@ -86,7 +86,8 @@ $AUTOMAKE -a ./configure || skip_ "configure failure" $MAKE $MAKE distcheck -$MAKE distclean +$MAKE maintainer-clean + mkdir build cd build ../configure diff --git a/t/vala-parallel.sh b/t/vala-parallel.sh index 4f93f8970..8c012552e 100644 --- a/t/vala-parallel.sh +++ b/t/vala-parallel.sh @@ -64,8 +64,8 @@ cd build ../configure $MAKE -j6 ls -l . .. # For debugging. -for x in main 1 2 3 4 5 6; do test -f ../$x.c; done -test -f ../zardoz_vala.stamp +for x in main 1 2 3 4 5 6; do test -f $x.c; done +test -f ./zardoz_vala.stamp $MAKE distcheck -j4 diff --git a/t/vala-per-target-flags.sh b/t/vala-per-target-flags.sh index 715ed7768..e37fe60d8 100644 --- a/t/vala-per-target-flags.sh +++ b/t/vala-per-target-flags.sh @@ -86,8 +86,8 @@ test -f src/xfoo.c test -f src/xbar.c $MAKE distclean -test -f src/xfoo.c -test -f src/xbar.c +test ! -e src/xfoo.c +test ! -e src/xbar.c # Re-create Makefile. mv config.sav config.status diff --git a/t/vala-recursive-setup.sh b/t/vala-recursive-setup.sh index 40b870119..808f5b98a 100644 --- a/t/vala-recursive-setup.sh +++ b/t/vala-recursive-setup.sh @@ -77,9 +77,9 @@ grep 'am--error' src/zardoz.[ch] && exit 1 # Check the distribution. $MAKE distcheck -$MAKE distclean +$MAKE maintainer-clean -# Tru a VPATH setup. +# Try a VPATH setup. mkdir build cd build @@ -89,19 +89,19 @@ $MAKE distcheck # Test rebuild rules from builddir. -rm -f ../src/zardoz.h -$MAKE -C src ../../src/zardoz.h -test -f ../src/zardoz.h +rm src/zardoz.h +$MAKE -C src zardoz.h +test -f src/zardoz.h -rm -f ../src/zardoz.c +rm -f src/zardoz.c $MAKE -grep 'Zardoz!' ../src/zardoz.c +grep 'Zardoz!' src/zardoz.c $sleep sed 's/Zardoz!/FooBar!/' ../src/zardoz.vala > t mv -f t ../src/zardoz.vala $MAKE -grep 'FooBar!' ../src/zardoz.c -grep 'Zardoz!' ../src/zardoz.c && exit 1 +grep 'FooBar!' src/zardoz.c +grep 'Zardoz!' src/zardoz.c && exit 1 : diff --git a/t/vala-vpath.sh b/t/vala-vpath.sh index bc10ab9ba..d3d0ff135 100644 --- a/t/vala-vpath.sh +++ b/t/vala-vpath.sh @@ -47,16 +47,16 @@ cp hello.vala goodbye.vala $ACLOCAL $AUTOCONF -$AUTOMAKE +$AUTOMAKE -a mkdir build cd build ../configure $MAKE -test -f ../foo_vala.stamp -test -f ../bar_vala.stamp -grep foofoofoo ../hello.c -test -f ../zardoz.h +test -f ./foo_vala.stamp +test -f ./bar_vala.stamp +grep foofoofoo ./hello.c +test -f ./zardoz.h $MAKE distcheck # Rebuild rules work also in VPATH builds. @@ -70,9 +70,10 @@ int main () END $MAKE -test -f ../foo_vala.stamp -test -f ../bar_vala.stamp -grep barbarbar ../hello.c +test -f ./foo_vala.stamp +test -f ./bar_vala.stamp +grep barbarbar ./hello.c +$MAKE distcheck # Rebuild rules are not uselessly triggered. $MAKE -q @@ -80,14 +81,14 @@ $MAKE -n | grep '\.stamp' && exit 1 # Cleanup rules work also in VPATH builds. $MAKE clean -test -f ../foo_vala.stamp -test -f ../bar_vala.stamp -test -f ../zardoz.h -test -f ../hello.c +test -f ./foo_vala.stamp +test -f ./bar_vala.stamp +test -f ./zardoz.h +test -f ./hello.c $MAKE maintainer-clean -test ! -e ../zardoz.h -test ! -e ../hello.c -test ! -e ../foo_vala.stamp -test ! -e ../bar_vala.stamp +test ! -e ./zardoz.h +test ! -e ./hello.c +test ! -e ./foo_vala.stamp +test ! -e ./bar_vala.stamp : -- 2.25.1