diff options
author | Mathieu Lirzin <mthl@gnu.org> | 2017-07-08 20:18:45 +0200 |
---|---|---|
committer | Mathieu Lirzin <mthl@gnu.org> | 2017-08-31 11:55:02 +0200 |
commit | 574b20e518079db0f91720c0641e4222d9fda84f (patch) | |
tree | 68ea05618bf068d336d80aa85a0eed084347e35f /maintainer | |
parent | 99cf7ca5ed35afa9552a3a2429963130700a0fde (diff) | |
download | automake-574b20e518079db0f91720c0641e4222d9fda84f.tar.gz |
build: Inline perl prototypes in sources
Prototypes allows us to avoid using the '&foo' invocation form when
invoking a subroutine before its definition. Previously those
prototypes were generated to prevent them from falling out-of-sync
with actual definitions. Now we provide a 'check-perl-protos' lint
script to ensure that this is not the case. This has the same
benefits as generating prototypes while simplifying the
bootstrap/build process.
* bin/gen-perl-protos: Remove.
* bin/Makefile.inc: Adapt.
* bootstrap: Likewise.
* bin/aclocal.in: Inline prototypes.
* bin/automake.in: Likewise.
* maintainer/check-perl-protos: New lint script.
* maintainer/syntax-checks.mk (sc_perl_protos): New target.
(syntax_check_rules): Add it.
Diffstat (limited to 'maintainer')
-rwxr-xr-x | maintainer/check-perl-protos | 50 | ||||
-rw-r--r-- | maintainer/syntax-checks.mk | 8 |
2 files changed, 58 insertions, 0 deletions
diff --git a/maintainer/check-perl-protos b/maintainer/check-perl-protos new file mode 100755 index 000000000..b1d6a72b5 --- /dev/null +++ b/maintainer/check-perl-protos @@ -0,0 +1,50 @@ +#!/usr/bin/env perl +# +# Copyright (C) 2017 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 3, 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 <http://www.gnu.org/licenses/>. + +use warnings; +use strict; + +my @lines = <>; +my %forwards = map { /^sub (\w+)\s*\((.*)\);$/ ? ("$1" => "$2") : () } @lines; +my %subs = map { /^sub (\w+)\s*\((.*)\)$/ ? ("$1" => "$2") : () } @lines; +my $error_count = 0; + +# $subs{"foo"} = "$$"; +# $subs{"bar"} = "@"; +# $forwards{"bar"} = "\$"; + +# Check that every subroutine has a matching forward declaration with +# the same prototype. +foreach my $sub (keys (%subs)) + { + # XXX: The location of the subroutine is not reported. + if (grep { $sub eq $_ } keys (%forwards)) + { + if ($forwards{$sub} ne $subs{$sub}) + { + $error_count += 1; + warn ("prototype mismatch for \"$sub\" subroutine\n"); + } + } + else + { + $error_count += 1; + warn ("missing prototype for \"$sub\" subroutine\n"); + } + } + +exit (($error_count == 0) ? 0 : 1); diff --git a/maintainer/syntax-checks.mk b/maintainer/syntax-checks.mk index c8b074008..07a12ab6f 100644 --- a/maintainer/syntax-checks.mk +++ b/maintainer/syntax-checks.mk @@ -51,6 +51,7 @@ sc_mkinstalldirs \ sc_pre_normal_post_install_uninstall \ sc_perl_no_undef \ sc_perl_no_split_regex_space \ +sc_perl_protos \ sc_cd_in_backquotes \ sc_cd_relative_dir \ sc_perl_at_uscore_in_scalar_context \ @@ -102,6 +103,13 @@ sc_sanity_gnu_grep: .PHONY: sc_sanity_gnu_grep $(syntax_check_rules): sc_sanity_gnu_grep +# Check that every subroutine in perl scripts has a corresponding +# prototype +sc_perl_protos: + $(AM_V_GEN)$(srcdir)/maintainer/check-perl-protos \ + <$(srcdir)/bin/aclocal.in && \ + $(srcdir)/maintainer/check-perl-protos <$(srcdir)/bin/automake.in + # These check avoids accidental configure substitutions in the source. # There are exactly 8 lines that should be modified from automake.in to # automake, and 9 lines that should be modified from aclocal.in to |