From patchwork Thu Apr 20 15:39:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 97832 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp857608qgf; Thu, 20 Apr 2017 08:40:35 -0700 (PDT) X-Received: by 10.107.130.104 with SMTP id e101mr10861081iod.118.1492702835024; Thu, 20 Apr 2017 08:40:35 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si7478501ioe.107.2017.04.20.08.40.34; Thu, 20 Apr 2017 08:40:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S970823AbdDTPkc (ORCPT + 15 others); Thu, 20 Apr 2017 11:40:32 -0400 Received: from mail-wr0-f171.google.com ([209.85.128.171]:34303 "EHLO mail-wr0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970701AbdDTPk2 (ORCPT ); Thu, 20 Apr 2017 11:40:28 -0400 Received: by mail-wr0-f171.google.com with SMTP id z109so38341356wrb.1 for ; Thu, 20 Apr 2017 08:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=NipJXa+wQhzgmay3Xg8/MLX7Z9B6xl+Y7qS8naWFVqc=; b=CSCIssVNpCgIbzryD9Qkbbl7fvh84igNzWuMifmzdSXk7rHUZ18X0U++ruzD5WnTac iGCNnqI73dXu8DYK9hp3grUSyO0M8bRwhy3DV+VSBAOGorRb7Y2cw2kk5So54STc6dyj NF7UIwNif43/3T4QeAruLjbOwORWloEzImdjY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NipJXa+wQhzgmay3Xg8/MLX7Z9B6xl+Y7qS8naWFVqc=; b=i/IiBo3aRP94rHQ5hj9K38alLfIBrXOrJ7PYGbB9tqECNPHJX97skK6hfBPXBSLh1w SkRinRx12ln4yxVXNj5zpfwqm+5iThIJzpbqgwyI3Aelj3bHIRZKb7HR+0Wzrh/JYJKK C1cM3G5BFVm+FGNNvUiX6Mx+QHJhnt2J0DuCmKGL0aLPYAg1sKykV5us0CmrwUPw41Zo g1Otuthh8S5H3IS/GHcSKFlJGtlDLaLPUSmiqC5UBJdC+WgEmSUR1vldML6d6G9hloTv ZYTJ+qCcISvmS0axW9rstVmWv/Md72/1TnEfJx4ACQ22zoC9MrcDcYPS06pt8pBcKm2Z XPMw== X-Gm-Message-State: AN3rC/51fYH5PcCu1ZgjOJUh+J8dOIE8VFZZpB9RTAgIhttfhZuG37EB aggq1TL2kRfGqG8TJdppwg== X-Received: by 10.223.176.163 with SMTP id i32mr1434911wra.32.1492702827283; Thu, 20 Apr 2017 08:40:27 -0700 (PDT) Received: from jfw540.home (ANice-653-1-30-38.w90-8.abo.wanadoo.fr. [90.8.124.38]) by smtp.gmail.com with ESMTPSA id t100sm8073071wrc.24.2017.04.20.08.40.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Apr 2017 08:40:26 -0700 (PDT) From: Jerome Forissier To: Andy Whitcroft , Joe Perches , linux-kernel@vger.kernel.org Cc: Jerome Forissier Subject: [PATCH] checkpatch: add --typedefsfile Date: Thu, 20 Apr 2017 17:39:25 +0200 Message-Id: X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When using checkpatch on out-of-tree code, it may occur that some project-specific types are used, which will cause spurious warnings. Add the --typedefsfile option as a way to extend the known types and deal with this issue. Signed-off-by: Jerome Forissier --- scripts/checkpatch.pl | 56 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 19 deletions(-) -- 2.7.4 diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index baa3c7b..eb55f5f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -55,6 +55,7 @@ my $spelling_file = "$D/spelling.txt"; my $codespell = 0; my $codespellfile = "/usr/share/codespell/dictionary.txt"; my $conststructsfile = "$D/const_structs.checkpatch"; +my $typedefsfile = ""; my $color = 1; my $allow_c99_comments = 1; @@ -113,6 +114,7 @@ Options: --codespell Use the codespell dictionary for spelling/typos (default:/usr/share/codespell/dictionary.txt) --codespellfile Use this codespell dictionary + --typedefsfile Read additional types from this file --color Use colors when output is STDOUT (default: on) -h, --help, --version display this help and exit @@ -208,6 +210,7 @@ GetOptions( 'test-only=s' => \$tst_only, 'codespell!' => \$codespell, 'codespellfile=s' => \$codespellfile, + 'typedefsfile=s' => \$typedefsfile, 'color!' => \$color, 'h|help' => \$help, 'version' => \$help @@ -629,28 +632,43 @@ if ($codespell) { $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; +sub read_words { + my ($wordsRef, $file) = @_; + + if (open(my $words, '<', $file)) { + while (<$words>) { + my $line = $_; + + $line =~ s/\s*\n?$//g; + $line =~ s/^\s*//g; + + next if ($line =~ m/^\s*#/); + next if ($line =~ m/^\s*$/); + if ($line =~ /\s/) { + print("$file: '$line' invalid - ignored\n"); + next; + } + + $$wordsRef .= '|' if ($$wordsRef ne ""); + $$wordsRef .= $line; + } + close($file); + return 1; + } + + return 0; +} + my $const_structs = ""; -if (open(my $conststructs, '<', $conststructsfile)) { - while (<$conststructs>) { - my $line = $_; +read_words(\$const_structs, $conststructsfile) + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; - $line =~ s/\s*\n?$//g; - $line =~ s/^\s*//g; - - next if ($line =~ m/^\s*#/); - next if ($line =~ m/^\s*$/); - if ($line =~ /\s/) { - print("$conststructsfile: '$line' invalid - ignored\n"); - next; - } - - $const_structs .= '|' if ($const_structs ne ""); - $const_structs .= $line; - } - close($conststructsfile); -} else { - warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; +my $typeOtherTypedefs = ""; +if (length($typedefsfile)) { + read_words(\$typeOtherTypedefs, $typedefsfile) + or warn "No additional types will be considered - file '$typedefsfile': $!\n"; } +$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); sub build_types { my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";