From patchwork Sun Apr 1 05:08:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Martincoski X-Patchwork-Id: 893907 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CIW8tg5W"; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40DNhb6zNJz9s1w for ; Sun, 1 Apr 2018 15:10:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 556EC86DE2; Sun, 1 Apr 2018 05:10:04 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qq5zWaVnXdRc; Sun, 1 Apr 2018 05:10:01 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id D692286DC8; Sun, 1 Apr 2018 05:10:01 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id AD00C1C1E66 for ; Sun, 1 Apr 2018 05:10:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id A9A9E88B52 for ; Sun, 1 Apr 2018 05:10:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j36vESo5fMRO for ; Sun, 1 Apr 2018 05:10:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by hemlock.osuosl.org (Postfix) with ESMTPS id DD5A388AA6 for ; Sun, 1 Apr 2018 05:09:59 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id v2so12447228qkh.10 for ; Sat, 31 Mar 2018 22:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=wT+OH+NA0gZEmnqIZFwTrIRYwfUN47pBAgkjQZBnqSI=; b=CIW8tg5WQEy9jWLLHmwDqkKM6ZfL/EqrZDkxNLRs2szV+eQ8is8RY4xAArJmnV13Sm ekYsoSVyR8A4KydrKcFi8S6B4iSDXVLsjZ/ozweiL9TAxa+ShoNfs2BUzQeJPqtZlI9R 5xol6H/mVImRfhW7DoSmfzcgNF/5j2aVVhA2EbbYQh6h4XKhpxyeQPJTkYgOGlOXZIPr PBTaOrF7nj1CHVGqBUFxM/7Z9Ee3CVQGh1PENX5ufOWYbkN2rkU1bC1JmVwh5J5pV/lB rSLr1DWBQ9paRkSX5CT98wIfCOy1QGYIIalDa63SL/FzcBsdbmZdDd4i2zLteyu9RDNU sPtg== 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:in-reply-to :references:in-reply-to:references; bh=wT+OH+NA0gZEmnqIZFwTrIRYwfUN47pBAgkjQZBnqSI=; b=kksnVKIZFbF90YjvNnYwp4a/HIZP6xpkhsjJj08mqtbAG5q9GjSbOzExYzOty4egmd vCpKYZJSpc73m4sma1RCwsr1jaqI7zSl2awEFCYM/vNEDkZbwiR4fz0Fn9/E4DoTrn5H eKTFS85e4wwdd2oOQuwAIdBI/DMbC7Ytyx92CUBEnYWsnihHa6Klwg/BhiY6NPV+pw2D ep85MZNU8JfKgEBfibdxsWYsLxw2Sa8Xb9QZ5jy4VbCuJAbrM8sdet8iDCs55iCTB/UT dfERGuLLWtIVrsfOyXSr8+kDeWa/BZEfD6o3Q1Q8JIMsTFY06BJ/yI/wXEc4wY7wYqRv 3Z9A== X-Gm-Message-State: ALQs6tBflQeEf/rVbCCAgV6flTZCvNzSihFFJ7q9WLJ8o4V/hnses2lA bPxV8MKMUpKMnP7mC/sTkh8TZg== X-Google-Smtp-Source: AIpwx49fvFMLCXH73iatbDlQIlYa8mb6hWRRbx9/WKYRpdVdE3w/SzuGc5Cq1Y+As82eh9+D7QBQ6w== X-Received: by 10.55.3.209 with SMTP id 200mr6578025qkd.283.1522559398833; Sat, 31 Mar 2018 22:09:58 -0700 (PDT) Received: from ultri4.home ([177.156.145.193]) by smtp.gmail.com with ESMTPSA id a44sm3173974qtb.9.2018.03.31.22.09.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Mar 2018 22:09:58 -0700 (PDT) From: Ricardo Martincoski To: buildroot@buildroot.org Date: Sun, 1 Apr 2018 02:08:14 -0300 Message-Id: <20180401050850.5701-2-ricardo.martincoski@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180401050850.5701-1-ricardo.martincoski@gmail.com> References: <20180401050850.5701-1-ricardo.martincoski@gmail.com> In-Reply-To: <20180331022301.27501-1-ricardo.martincoski@gmail.com> References: <20180331022301.27501-1-ricardo.martincoski@gmail.com> Subject: [Buildroot] [PATCH v2 01/37] check-package: prepare to extend to other directories X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ricardo Martincoski , Thomas Petazzoni MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Currently the script only checks files inside the package/ directory. Upcoming patches will enable it for other directories. In order to reliably test for file names, i.e. the Config.in in the base directory, normalize the path of files to check to a relative path to the base directory. Rename the variable that holds the compiled regexp to better represent its content and rearrange how it is declared to make easy to later add new directories to check. As a consequence the files that declare package infra types would not be ignored anymore, so create a new variable to list the files intree to be ignored during the check. The same variable will be used by upcoming patches to ignore other files. Ignore pkg-*.mk and doc-asciidoc.mk since they are package infra files. In order to not produce weird results when used for files outside the tree (i.e. in a private br2-external) add an explicit command line option (-b) that bypasses any checks that would make a file be ignored by the path that contains it. When in this out-of-tree mode, the user is responsible for providing a list of files to check that do not contain files the script does not understand, e.g. package infra files. As a result of this patch, besides the known use: $ ./utils/check-package package/new-package/* someone with the utils/ directory in the path can now also run: $ cd package/new-package/ $ check-package * or $ check-package -b /path/to/br2-ext-tree/package/staging-package/* Signed-off-by: Ricardo Martincoski --- Changes v1 -> v2: - no changes --- utils/check-package | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/utils/check-package b/utils/check-package index a87a74decc..d2457c706c 100755 --- a/utils/check-package +++ b/utils/check-package @@ -4,6 +4,7 @@ from __future__ import print_function import argparse import inspect +import os import re import sys @@ -24,6 +25,9 @@ def parse_args(): parser.add_argument("files", metavar="F", type=str, nargs="*", help="list of files") + parser.add_argument("--br2-external", "-b", dest='intree_only', action="store_false", + help="do not apply the pathname filters used for intree files") + parser.add_argument("--manual-url", action="store", default="http://nightly.buildroot.org/", help="default: %(default)s") @@ -41,12 +45,21 @@ def parse_args(): CONFIG_IN_FILENAME = re.compile("/Config\.\S*$") -FILE_IS_FROM_A_PACKAGE = re.compile("package/[^/]*/") +DO_CHECK_INTREE = re.compile("|".join([ + "package/", + ])) +DO_NOT_CHECK_INTREE = re.compile("|".join([ + "package/doc-asciidoc\.mk$", + "package/pkg-\S*\.mk$", + ])) def get_lib_from_filename(fname): - if FILE_IS_FROM_A_PACKAGE.search(fname) is None: - return None + if flags.intree_only: + if DO_CHECK_INTREE.match(fname) is None: + return None + if DO_NOT_CHECK_INTREE.match(fname): + return None if CONFIG_IN_FILENAME.search(fname): return checkpackagelib.lib_config if fname.endswith(".hash"): @@ -117,7 +130,16 @@ def __main__(): global flags flags = parse_args() - if len(flags.files) == 0: + if flags.intree_only: + # change all paths received to be relative to the base dir + base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + files_to_check = [os.path.relpath(os.path.abspath(f), base_dir) for f in flags.files] + # move current dir so the script find the files + os.chdir(base_dir) + else: + files_to_check = flags.files + + if len(files_to_check) == 0: print("No files to check style") sys.exit(1) @@ -125,7 +147,7 @@ def __main__(): total_warnings = 0 total_lines = 0 - for fname in flags.files: + for fname in files_to_check: nwarnings, nlines = check_file_using_lib(fname) total_warnings += nwarnings total_lines += nlines