diff mbox

[v2] checkpatch: kbuild: if_changed: check for multiple calls in targets

Message ID 20180720074804.4160-1-dirk@gouders.net (mailing list archive)
State New, archived
Headers show

Commit Message

Dirk Gouders July 20, 2018, 7:48 a.m. UTC
The kbuild function if_changed should not be called more than once for
a target.

Because that function writes the command line to a .cmd file for later
tests, multiple calls of it within a target would result in overwrites
of previous values and effectively render the command line test
meaningless, resulting in flip-flop behaviour.

Add a check for makefiles and kbuild files and produce an error for
targets with multiple calls to if_changed.

Three examples that now could be detected:

98f78525371b55ccd (x86/boot: Refuse to build with data relocations)
6a8dfe1cac5c591ae (microblaze: support U-BOOT image format)
684151a75bf25f5ae (sparc32: added U-Boot build target: uImage)

Reviewed-by: Joe Perches <joe@perches.com>
Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
v2: rework commit message and regular expression
---
 scripts/checkpatch.pl | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Joe Perches July 20, 2018, 10:06 a.m. UTC | #1
On Fri, 2018-07-20 at 09:48 +0200, Dirk Gouders wrote:
> The kbuild function if_changed should not be called more than once for
> a target.
> 
> Because that function writes the command line to a .cmd file for later
> tests, multiple calls of it within a target would result in overwrites
> of previous values and effectively render the command line test
> meaningless, resulting in flip-flop behaviour.
> 
> Add a check for makefiles and kbuild files and produce an error for
> targets with multiple calls to if_changed.
> 
> Three examples that now could be detected:
> 
> 98f78525371b55ccd (x86/boot: Refuse to build with data relocations)
> 6a8dfe1cac5c591ae (microblaze: support U-BOOT image format)
> 684151a75bf25f5ae (sparc32: added U-Boot build target: uImage)
> 
> Reviewed-by: Joe Perches <joe@perches.com>

I didn't review this.  I gave you feedback
but didn't add a signature.

For anything other than "Suggested-by:",
please don't add signatures to patches unless
the person gives directly gives you one.

> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Signed-off-by: Dirk Gouders <dirk@gouders.net>
> ---
> v2: rework commit message and regular expression
> ---
>  scripts/checkpatch.pl | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 447857ffaf6b..437e98414f74 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2911,6 +2911,14 @@ sub process {
>  			     "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
>  		}
>  
> +		# Check for multiple calls of if_changed within a target in Makefiles
> +		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&

The uses of .* here are superfluous.

> +		    ($prevline =~ /^[ +]\t\s*\$\(call\s+if_changed,/) &&
> +		    ($line =~ /^[ +]\t\s*\$\(call\s+if_changed,/)) {
> +				ERROR("MULTIPLE_IF_CHANGED",
> +				      "Multiple calls of if_changed within a target.\n" . $herecurr);
> +		}
> +
>  # check for DT compatible documentation
>  		if (defined $root &&
>  			(($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Segher Boessenkool July 20, 2018, 3:21 p.m. UTC | #2
On Fri, Jul 20, 2018 at 03:06:37AM -0700, Joe Perches wrote:
> On Fri, 2018-07-20 at 09:48 +0200, Dirk Gouders wrote:
> > +		# Check for multiple calls of if_changed within a target in Makefiles
> > +		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
> 
> The uses of .* here are superfluous.

And it looks like you wanted to match this only at the beginning of the
string, which would be /^Makefile/ etc.


Segher
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches July 20, 2018, 3:33 p.m. UTC | #3
On Fri, 2018-07-20 at 10:21 -0500, Segher Boessenkool wrote:
> On Fri, Jul 20, 2018 at 03:06:37AM -0700, Joe Perches wrote:
> > On Fri, 2018-07-20 at 09:48 +0200, Dirk Gouders wrote:
> > > +		# Check for multiple calls of if_changed within a target in Makefiles
> > > +		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
> > 
> > The uses of .* here are superfluous.
> 
> And it looks like you wanted to match this only at the beginning of the
> string, which would be /^Makefile/ etc.

Nope.

$realfile includes path and /^Makefile/ matches only the
top level Makefile and none of the ones in subdirectories.


--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Segher Boessenkool July 20, 2018, 3:44 p.m. UTC | #4
On Fri, Jul 20, 2018 at 08:33:56AM -0700, Joe Perches wrote:
> On Fri, 2018-07-20 at 10:21 -0500, Segher Boessenkool wrote:
> > On Fri, Jul 20, 2018 at 03:06:37AM -0700, Joe Perches wrote:
> > > On Fri, 2018-07-20 at 09:48 +0200, Dirk Gouders wrote:
> > > > +		# Check for multiple calls of if_changed within a target in Makefiles
> > > > +		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
> > > 
> > > The uses of .* here are superfluous.
> > 
> > And it looks like you wanted to match this only at the beginning of the
> > string, which would be /^Makefile/ etc.
> 
> Nope.
> 
> $realfile includes path and /^Makefile/ matches only the
> top level Makefile and none of the ones in subdirectories.

Then the .* is more mysterious :-)

(Maybe the script should use File::Basename).


Segher
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 447857ffaf6b..437e98414f74 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2911,6 +2911,14 @@  sub process {
 			     "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
 		}
 
+		# Check for multiple calls of if_changed within a target in Makefiles
+		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
+		    ($prevline =~ /^[ +]\t\s*\$\(call\s+if_changed,/) &&
+		    ($line =~ /^[ +]\t\s*\$\(call\s+if_changed,/)) {
+				ERROR("MULTIPLE_IF_CHANGED",
+				      "Multiple calls of if_changed within a target.\n" . $herecurr);
+		}
+
 # check for DT compatible documentation
 		if (defined $root &&
 			(($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||