From patchwork Sun Sep 3 16:35:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Martincoski X-Patchwork-Id: 1829214 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=buildroot.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rdy8h138mz1ynJ for ; Mon, 4 Sep 2023 02:36:52 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id DD0E081440; Sun, 3 Sep 2023 16:36:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org DD0E081440 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TJnByMjYSfXV; Sun, 3 Sep 2023 16:36:49 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id 045A98141B; Sun, 3 Sep 2023 16:36:48 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 045A98141B X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 332DD1BF381 for ; Sun, 3 Sep 2023 16:36:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0C40060A4F for ; Sun, 3 Sep 2023 16:36:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 0C40060A4F X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8mo4g5tT_Fjg for ; Sun, 3 Sep 2023 16:36:36 +0000 (UTC) Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by smtp3.osuosl.org (Postfix) with ESMTPS id CE253608B7 for ; Sun, 3 Sep 2023 16:36:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org CE253608B7 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1a1fa977667so682657fac.1 for ; Sun, 03 Sep 2023 09:36:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693758994; x=1694363794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RSw/n/CMV4IGlg5a/UMbjYIqC6N9AK7dZrc0ksrZpas=; b=W4qBvyXBlFON8o34lP8P4WOZghlWNit+4VrzZqoBdABazVZJqZHSTXNoqOIEouNNIw AmES8IRJJOKdaE4Rv9QbRCup0fY0wQfqK02iPC3D7ed5IF+0f9LtTg9oKaTClHl7BdXD 5eY5/ijZPrOMUXIqDr0znOJF72NaKdC2mCWTm441aGLa3oxOtgsZiNQnTMJwn/TO2EC0 1AUdbE0gSU+Wp22q3Nc3f9JmErVoL+n4GOJp7rPM/PYGfJBI4pe0Wym9Sp5BXUp3Q0Aq EkyeACYC5F7EX/DSzmI8OC6TxuyeECZSuau8G1MRJ4HOWbUGdrNZ843qTcSBAmbhzP6r kgMg== X-Gm-Message-State: AOJu0YyFZFAHbcTrJeyA/2ZRWV1xEN1yPCuS4tyIwGRnXYAk6DtkBmzO kVKQIsKJfWZbt+glBd4udRmwbW4ghB0= X-Google-Smtp-Source: AGHT+IFyrZxTuLMz2tlWETyZliJSzbE9mEy+5zSnGaTRUeG4PSJiyzMVRB3VXHN8UUMR0OePcslknw== X-Received: by 2002:a05:6870:55a5:b0:1d0:f064:acbb with SMTP id n37-20020a05687055a500b001d0f064acbbmr10478742oao.19.1693758994550; Sun, 03 Sep 2023 09:36:34 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:7980:8b6b:3897:d6c:e635:bd4e]) by smtp.gmail.com with ESMTPSA id l8-20020a9d7348000000b006b753685cc5sm3789487otk.79.2023.09.03.09.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 09:36:33 -0700 (PDT) From: Ricardo Martincoski To: buildroot@buildroot.org Date: Sun, 3 Sep 2023 13:35:07 -0300 Message-Id: <20230903163509.614740-2-ricardo.martincoski@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230903163509.614740-1-ricardo.martincoski@gmail.com> References: <20230903163509.614740-1-ricardo.martincoski@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693758994; x=1694363794; darn=buildroot.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RSw/n/CMV4IGlg5a/UMbjYIqC6N9AK7dZrc0ksrZpas=; b=Z41ZPEdvpbsmU6ay/7/EGV8m2xN3UcXlQH2Fm5rh1J+8dSsvag6BrUE2HDietCRbKu ZDbAyLgBFD5UtXIpHNHYybZ1wcsaArXUiW7fsE+LloAb9CI98WHeTo7g63cEMNJxsQbd zEXTprGMSVQxA8ia/naow/8BrvNYkvnF/eeAj/IRyZp07O0nRhUKxbeMajcZ3i0FuFyR 8CPcECBoMrbK4vNMxtyVm87So00q8mZteU8jW3EFpx6utO7YXhrjsqoASo18YWRpFVZD tgHugSyVjlysq8KkxiLS+GhHAHJzda1QXNt1RLF/HGkym3LE2Zn+BzQ/evmxsiY54e8I fD1Q== X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Z41ZPEdv Subject: [Buildroot] [next v3 1/3] utils/check-package: factor-out check_disabled() X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: James Knight , Thomas Petazzoni , Ricardo Martincoski Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" Currently source files analysed by check-package can use a special comment to hint the script to completely ignore a CheckFunction for the next line of the source file: # check-package Indent Currently the logic that implements this is at the main check-package script. But the main package script is not covered by unit tests. In preparation to support not only 'ignore this CheckFunction for the next source line' but also 'use special rules for this CheckFunction when testing this file' move the logic that parses such special comments into the base class _CheckFunction. At same time, create unit tests that exercise such code. Cc: James Knight Cc: Thomas Petazzoni Signed-off-by: Ricardo Martincoski --- Changes v1 -> v3: - new patch, implementing a code improvement detected while reviewing v1 of this series https://gitlab.com/RicardoMartincoski/buildroot/-/pipelines/990306862 --- utils/check-package | 2 +- utils/checkpackagelib/base.py | 5 +++ utils/checkpackagelib/test_base.py | 49 ++++++++++++++++++++++++++++++ utils/checkpackagelib/test_util.py | 5 ++- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 utils/checkpackagelib/test_base.py diff --git a/utils/check-package b/utils/check-package index 105902303e..23d250d4a1 100755 --- a/utils/check-package +++ b/utils/check-package @@ -237,7 +237,7 @@ def check_file_using_lib(fname): for lineno, text in enumerate(f): nlines += 1 for name, cf in objects: - if cf.disable.search(lastline): + if cf.check_disabled(lastline): continue line_sts = cf.check_line(lineno + 1, text) warn, fail = print_warnings(line_sts, name in xfail) diff --git a/utils/checkpackagelib/base.py b/utils/checkpackagelib/base.py index f666e4110b..15a304acf3 100644 --- a/utils/checkpackagelib/base.py +++ b/utils/checkpackagelib/base.py @@ -8,6 +8,11 @@ class _CheckFunction(object): self.url_to_manual = url_to_manual self.disable = re.compile(r"^\s*# check-package .*\b{}\b".format(self.__class__.__name__)) + def check_disabled(self, line_before): + if self.disable.search(line_before): + return True + return False + def before(self): pass diff --git a/utils/checkpackagelib/test_base.py b/utils/checkpackagelib/test_base.py new file mode 100644 index 0000000000..ef266d542c --- /dev/null +++ b/utils/checkpackagelib/test_base.py @@ -0,0 +1,49 @@ +import pytest +import checkpackagelib.test_util as util +import checkpackagelib.base as m + + +IgnoreNextLine = [ + ('without comment to ignore a given CheckFunction', + 'any', + 'content to test\n' + '# commented content to test\n' + 'content to test\n' + 'content to test\n' + 'content to test\n', + [1, 2, 3, 4, 5]), # set of line numbers for all lines not ignored while testing + ('ignore next line', + 'any', + 'content to test\n' + '# check-package CheckFunctionUnderTest\n' + 'content to ignore\n' + 'content to test\n' + 'content to test\n', + [1, 2, 4, 5]), + ('comment to ignore one CheckFunction does not affect another one', + 'any', + 'content to test\n' + '# check-package AnotherCheckFunction\n' + 'content to test\n' + 'content to test\n' + 'content to test\n', + [1, 2, 3, 4, 5]), + ('ignore 2 CheckFunctions for next line', + 'any', + '# check-package CheckFunctionUnderTest, AnotherCheckFunction\n' + 'content to ignore\n' + '# check-package AnotherCheckFunction, CheckFunctionUnderTest\n' + 'content to ignore\n' + 'content to test\n', + [1, 3, 5]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', IgnoreNextLine) +def test_IgnoreNextLine(testname, filename, string, expected): + class CheckFunctionUnderTest(m._CheckFunction): + def check_line(self, lineno, text): + return lineno + + warnings = util.check_file(CheckFunctionUnderTest, filename, string) + assert warnings == expected diff --git a/utils/checkpackagelib/test_util.py b/utils/checkpackagelib/test_util.py index 23f2995e27..b06e218498 100644 --- a/utils/checkpackagelib/test_util.py +++ b/utils/checkpackagelib/test_util.py @@ -2,7 +2,10 @@ def check_file(check_function, filename, string): obj = check_function(filename, 'url') result = [] result.append(obj.before()) + lastline = "" for i, line in enumerate(string.splitlines(True)): - result.append(obj.check_line(i + 1, line)) + if not obj.check_disabled(lastline): + result.append(obj.check_line(i + 1, line)) + lastline = line result.append(obj.after()) return [r for r in result if r is not None] From patchwork Sun Sep 3 16:35:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Martincoski X-Patchwork-Id: 1829215 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=buildroot.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rdy8w15xbz1ynJ for ; Mon, 4 Sep 2023 02:37:04 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 77199819B4; Sun, 3 Sep 2023 16:37:02 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 77199819B4 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4-9QxEzEmLcO; Sun, 3 Sep 2023 16:37:01 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id 69DEE81447; Sun, 3 Sep 2023 16:37:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 69DEE81447 X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 4B1D31BF381 for ; Sun, 3 Sep 2023 16:36:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2526A40159 for ; Sun, 3 Sep 2023 16:36:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 2526A40159 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yChsR_cgyXzV for ; Sun, 3 Sep 2023 16:36:38 +0000 (UTC) Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by smtp2.osuosl.org (Postfix) with ESMTPS id 07F98400E4 for ; Sun, 3 Sep 2023 16:36:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 07F98400E4 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6bf01bcb1aeso639593a34.3 for ; Sun, 03 Sep 2023 09:36:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693758997; x=1694363797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nEi36f/fQSGaHZmRogaydl6+Y3uVyLxNkwyMBTitbB8=; b=K1o/ZOos3+sYx1ECSlRc2w5PM8/HZeutJf8Wp5kPB8qVDwmnjjzeSyTw8y5S9TO6Bv yTSMXVgiX7a7c7+to5g+Yl4hw/GnTryWnGgFAB3QcWx0DBZnVdJYTg17BePjxnUVS3Wj Do1Wof4rX2H5AUUg+hPbKXLUXPSKnGpEYq3ffVR+zK1Zs5swibviCbYC7eHd8JdL3Ibs Uls2UWYiCPzPkv6NUetMelzIDw0FyvphqJsSXgnMovH7I16+Hd+ktVlEcxgNFK5v2Y36 UlnANAUlxY61Apj/wFd2riLL3N8tsPeuE9Xw2owzwtZPSJCrDY4oRXyrxd0VSi7SoIM3 QP+Q== X-Gm-Message-State: AOJu0YxSCOCmfgIu9dXMWGiXe1FTPRNyPhu68Kui2S37OUP6+1deH0Q9 bnY4fiumKh2XdM3UyY92oZSP8ihd43A= X-Google-Smtp-Source: AGHT+IHl1+SbcDf39jbL95D6v4cZq1LEsSddavXSxQwSKZStCQobDCf7uflFEg86JZN+nutXz5PnRA== X-Received: by 2002:a05:6830:11c2:b0:6be:fd1c:c228 with SMTP id v2-20020a05683011c200b006befd1cc228mr8702665otq.1.1693758997037; Sun, 03 Sep 2023 09:36:37 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:7980:8b6b:3897:d6c:e635:bd4e]) by smtp.gmail.com with ESMTPSA id l8-20020a9d7348000000b006b753685cc5sm3789487otk.79.2023.09.03.09.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 09:36:36 -0700 (PDT) From: Ricardo Martincoski To: buildroot@buildroot.org Date: Sun, 3 Sep 2023 13:35:08 -0300 Message-Id: <20230903163509.614740-3-ricardo.martincoski@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230903163509.614740-1-ricardo.martincoski@gmail.com> References: <20230903163509.614740-1-ricardo.martincoski@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693758997; x=1694363797; darn=buildroot.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nEi36f/fQSGaHZmRogaydl6+Y3uVyLxNkwyMBTitbB8=; b=lxxBPKDHYXQt0sFH77IVF30EdtjznNunac3IdiMfktJ6TjwselPb+dkOg0aF/IrLjs CGJMHI901iFazlIUiDuHTtu/5q/hbFaS/DsnENhkRUswUKnEQs5kzXc2SRC0eULSUOW5 7LsQ7sSPBXGDjDrwZtVbP5OIhGzi2qAR1AYiKSGEgM0cUlLIOTWiqp2LWhKgUjEBf6uw mYVcQy4b/E805hGPbIdnSo0ekprSh4zn5BIViwMYIm9uvQlwQvKlKyOvTCLEZiQCVn9J GuSvLJxnU1/z5PZ4UpvX8SpCGHQUzA4tmlS8Ho4Pa9gxQ20vywFMPEryiP0XWLxoSEXO vseg== X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=lxxBPKDH Subject: [Buildroot] [next v3 2/3] utils/check-package: support inline flags X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: James Knight , Thomas Petazzoni , Ricardo Martincoski Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" Currently source files analysed by check-package can use a special comment to hint the script to completely ignore a CheckFunction for the next line of the source file: # check-package Indent Extend that functionality to also support flags that will trigger special behaviour. For instance, by adding the line to a Config.in file: # check-package Indent_ignore-menu-indent-below makes the CheckFunction named Indent to set a flag named ignore-menu-indent-below and use it until the end of the source file under test. One example of use for this new special comment is Indent() from lib_config.py, that currently keeps a list of 4 intree Config.in files that have a special but legitimate indentation rule. Instead of keeping the list inside the code, now a special comment can be used in each of these 4 Config.in files. A great side effect of this new type of special comment is that it can also be used in source files from br2-external trees. Concept reused from James Knight's work in [1] and [2]. [1] http://patchwork.ozlabs.org/project/buildroot/patch/SN4P221MB0682AE13FB1ACA5A755024F1A0689@SN4P221MB0682.NAMP221.PROD.OUTLOOK.COM/ [2] http://patchwork.ozlabs.org/project/buildroot/patch/SN4P221MB06823B0F7326D27ECD5E0FAEA0689@SN4P221MB0682.NAMP221.PROD.OUTLOOK.COM/ Cc: James Knight Cc: Thomas Petazzoni Signed-off-by: Ricardo Martincoski --- Changes v1 -> v3: - rewrite the code from scratch for patches 2/4 and 3/4, moving it to the base class - add unit tests https://gitlab.com/RicardoMartincoski/buildroot/-/pipelines/990309342 --- utils/checkpackagelib/base.py | 20 ++++++-- utils/checkpackagelib/test_base.py | 82 ++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/utils/checkpackagelib/base.py b/utils/checkpackagelib/base.py index 15a304acf3..d17b9d899f 100644 --- a/utils/checkpackagelib/base.py +++ b/utils/checkpackagelib/base.py @@ -3,14 +3,28 @@ import re class _CheckFunction(object): + flags = [] + def __init__(self, filename, url_to_manual): self.filename = filename self.url_to_manual = url_to_manual - self.disable = re.compile(r"^\s*# check-package .*\b{}\b".format(self.__class__.__name__)) + if self.flags: + flags_pattern = '|_' + '|_'.join(self.flags) + else: + flags_pattern = '' + self.disable = re.compile(r"^\s*# check-package .*\b{}({})\b".format(self.__class__.__name__, flags_pattern)) + self.enabled_flags = {f: False for f in self.flags} def check_disabled(self, line_before): - if self.disable.search(line_before): - return True + found = self.disable.findall(line_before) + if found: + # catch flags to be used by CheckFunction for a source file, for all lines below + flags_found = [f[1:] for f in found if (f != '' and f[0] == '_')] + for f in flags_found: + self.enabled_flags[f] = True + + ignore_this_line = '' in found + return ignore_this_line return False def before(self): diff --git a/utils/checkpackagelib/test_base.py b/utils/checkpackagelib/test_base.py index ef266d542c..bbe9285466 100644 --- a/utils/checkpackagelib/test_base.py +++ b/utils/checkpackagelib/test_base.py @@ -47,3 +47,85 @@ def test_IgnoreNextLine(testname, filename, string, expected): warnings = util.check_file(CheckFunctionUnderTest, filename, string) assert warnings == expected + + +SpecialCheckForThisFile = [ + ('without special comment', + 'any', + 'content to test\n' + '# commented content to test\n' + 'content to test\n' + 'content to test\n' + 'content to test\n', + [1, 2, 3, 4, 5]), # set of line numbers for all lines not ignored while testing + ('ignore next line (CheckFunction with flags)', + 'any', + 'content to test\n' + '# check-package CheckFunctionUnderTest\n' + 'content to ignore\n' + 'content to test\n' + 'content to test\n', + [1, 2, 4, 5]), + ('comment to ignore one CheckFunction does not affect another one (CheckFunction with flags)', + 'any', + 'content to test\n' + '# check-package AnotherCheckFunction\n' + 'content to test\n' + 'content to test\n' + 'content to test\n', + [1, 2, 3, 4, 5]), + ('ignore 2 CheckFunctions for next line (CheckFunction with flags)', + 'any', + '# check-package CheckFunctionUnderTest, AnotherCheckFunction\n' + 'content to ignore\n' + '# check-package AnotherCheckFunction, CheckFunctionUnderTest\n' + 'content to ignore\n' + 'content to test\n', + [1, 3, 5]), + ('one flag', + 'any', + 'content to test using default code\n' + '# check-package CheckFunctionUnderTest_flag-2\n' + 'content to test using flag-2\n' + 'content to test using flag-2\n', + [1, 2, [3, [-2]], [4, [-2]]]), + ('flag and ignore next line in the same file', + 'any', + 'content to test using default code\n' + '# check-package CheckFunctionUnderTest\n' + 'content to ignore\n' + '# check-package CheckFunctionUnderTest_flag-2\n' + 'content to test using flag-2\n' + '# check-package CheckFunctionUnderTest\n' + 'content to ignore\n' + 'content to test using flag-2\n', + [1, 2, 4, [5, [-2]], [6, [-2]], [8, [-2]]]), + ('2 flags', + 'any', + 'content to test using default code\n' + '# check-package CheckFunctionUnderTest_flag-2\n' + 'content to test using flag-2\n' + '# check-package CheckFunctionUnderTest_flag-1\n' + 'content to test using flag-1 and flag-2\n' + 'content to test using flag-1 and flag-2\n', + [1, 2, [3, [-2]], [4, [-2]], [5, [-1, -2]], [6, [-1, -2]]]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', SpecialCheckForThisFile) +def test_SpecialCheckForThisFile(testname, filename, string, expected): + class CheckFunctionUnderTest(m._CheckFunction): + flags = ['flag-1', 'flag-2'] + + def check_line(self, lineno, text): + flags = [] + if self.enabled_flags['flag-1']: + flags.append(-1) + if self.enabled_flags['flag-2']: + flags.append(-2) + if flags: + return [lineno, flags] + return lineno + + warnings = util.check_file(CheckFunctionUnderTest, filename, string) + assert warnings == expected From patchwork Sun Sep 3 16:35:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Martincoski X-Patchwork-Id: 1829216 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=buildroot.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rdy983nFtz1ynJ for ; Mon, 4 Sep 2023 02:37:16 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C487081447; Sun, 3 Sep 2023 16:37:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org C487081447 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PcOYqPCrTpqq; Sun, 3 Sep 2023 16:37:13 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id BF96881A15; Sun, 3 Sep 2023 16:37:12 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org BF96881A15 X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id BDD761BF381 for ; Sun, 3 Sep 2023 16:36:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A233D4090F for ; Sun, 3 Sep 2023 16:36:42 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A233D4090F X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vHZ97p4W2PCT for ; Sun, 3 Sep 2023 16:36:40 +0000 (UTC) Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by smtp4.osuosl.org (Postfix) with ESMTPS id 86C8B40900 for ; Sun, 3 Sep 2023 16:36:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 86C8B40900 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-1ccc0d2e697so585787fac.0 for ; Sun, 03 Sep 2023 09:36:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693758999; x=1694363799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vFHAWaNnssXSsy4qGgtInPo/uoPO/12PgMPCJMHkjrQ=; b=gHlYbIVuELqvXIa6iUfH8vm1PIpTCGyro3Roq2lzDcOwdWj4mDyCPdTBrNAqFLJbRg BW+5oZUcHSzfPpvDoPxQq1KVBpz54oAlMouIcghdIB21Yo8oMgO9oieDbtIa9E4ChcW6 nHHuVc3o++m9JEt2xx8RzGdKSP0DhJ1bNRe/bnr9R8nsjzy32FRcXocth/jdS+bmK21o 63gqADofJuLIx9KJRBL+u0SiXcJY3gT0Bwh1Ud7sDOTnzHNb9E69L31MW41UQZwaa456 iQ02cw2HXSBvVh4Dcx6HLox8Mqb+poO4UJ/ZbZm+HlS0JuXB+KiGwGdZbt2qrS1IR87N T3MA== X-Gm-Message-State: AOJu0Yxc+8IEAWh5Ru6vC/OMUVtODUbfMcOSwbA137n3bjBJhS0/Q3Ze 19Jrr2kCWFGmuVYA6ug9oeENbWVGW7o= X-Google-Smtp-Source: AGHT+IF+AQOYTK1QYwM7m+PVmLv+4hA+r1ZceuqEgnBzMJwQ5B0kAhnDBKy3mjbg4AXb/rUohpbJKg== X-Received: by 2002:a05:6870:e38b:b0:1bb:83ae:1512 with SMTP id x11-20020a056870e38b00b001bb83ae1512mr11118754oad.24.1693758999569; Sun, 03 Sep 2023 09:36:39 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:7980:8b6b:3897:d6c:e635:bd4e]) by smtp.gmail.com with ESMTPSA id l8-20020a9d7348000000b006b753685cc5sm3789487otk.79.2023.09.03.09.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 09:36:38 -0700 (PDT) From: Ricardo Martincoski To: buildroot@buildroot.org Date: Sun, 3 Sep 2023 13:35:09 -0300 Message-Id: <20230903163509.614740-4-ricardo.martincoski@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230903163509.614740-1-ricardo.martincoski@gmail.com> References: <20230903163509.614740-1-ricardo.martincoski@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693758999; x=1694363799; darn=buildroot.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vFHAWaNnssXSsy4qGgtInPo/uoPO/12PgMPCJMHkjrQ=; b=XJhcq0JrnMdNj6I3XH85h5vgjyQU4pNgtNzqwffxbdspDzwMIQDZ6Ler+2DQ6XSslV Tj33uf/QbGsHWCfvh8vq2EjLWexfMXicRGc99vOMcXy7V+zDUWA0+6XGU5P5serE/q/Y fdpONAV7At/nUsS/WAEA4k11XhX0d/S9Ey2H1Bmgy0RGIT1TkYhVJkWsftKtwTuF0lDq cx0VOvwF2i3Pnn+fHdDA5GBYUhmEo1exPesCg/imlSBYnVeOq1aSDuTCcy9W1dAzCEZu rZRbOufZESGv/7grNNv397KTZLFVUstgeE9aM5PBn6xcZ4PgNrIZDfoJ3z0Dkf+2IrEW /8dw== X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=XJhcq0Jr Subject: [Buildroot] [next v3 3/3] utils/check-package: remove hard-coded list from lib_config:Indent X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: James Knight , Ricardo Martincoski , Thomas Petazzoni Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" From: James Knight Apply a special comment enabling the flag Indent_ignore-menu-indent-below to all configuration files intree that allow indentation, allowing these special files to removed from an internal list hard-coded inside `checkpackagelib/lib_config.py`. A great side effect of this new type of special comment is that it can also be used in source files from br2-external trees. Signed-off-by: James Knight [Ricardo: update commit message after rebase] Cc: Thomas Petazzoni Signed-off-by: Ricardo Martincoski --- Changes v1 -> v3: - rebase patch 4/4, update commit message - rename the flag https://gitlab.com/RicardoMartincoski/buildroot/-/pipelines/990316889 --- package/Config.in | 2 ++ package/Config.in.host | 2 ++ package/kodi/Config.in | 2 ++ package/x11r7/Config.in | 2 ++ utils/checkpackagelib/lib_config.py | 8 +++----- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package/Config.in b/package/Config.in index b21a2f8c65..231e8101c9 100644 --- a/package/Config.in +++ b/package/Config.in @@ -1,3 +1,5 @@ +# check-package Indent_ignore-menu-indent-below + menu "Target packages" source "package/busybox/Config.in" diff --git a/package/Config.in.host b/package/Config.in.host index 22e0dc64d4..2a96456db6 100644 --- a/package/Config.in.host +++ b/package/Config.in.host @@ -1,3 +1,5 @@ +# check-package Indent_ignore-menu-indent-below + menu "Host utilities" source "package/abootimg/Config.in.host" diff --git a/package/kodi/Config.in b/package/kodi/Config.in index 6b68e6d504..f6d5dbe4d8 100644 --- a/package/kodi/Config.in +++ b/package/kodi/Config.in @@ -1,3 +1,5 @@ +# check-package Indent_ignore-menu-indent-below + config BR2_PACKAGE_KODI_ARCH_SUPPORTS bool default y if BR2_PACKAGE_FFMPEG_ARCH_SUPPORTS diff --git a/package/x11r7/Config.in b/package/x11r7/Config.in index b91f97bb34..9cb3596b24 100644 --- a/package/x11r7/Config.in +++ b/package/x11r7/Config.in @@ -1,3 +1,5 @@ +# check-package Indent_ignore-menu-indent-below + menuconfig BR2_PACKAGE_XORG7 bool "X.org X Window System" depends on BR2_USE_WCHAR diff --git a/utils/checkpackagelib/lib_config.py b/utils/checkpackagelib/lib_config.py index f26ca0d898..e2f7302485 100644 --- a/utils/checkpackagelib/lib_config.py +++ b/utils/checkpackagelib/lib_config.py @@ -187,6 +187,7 @@ class HelpText(_CheckFunction): class Indent(_CheckFunction): + flags = ["ignore-menu-indent-below"] ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$") entries_that_should_be_indented = [ "bool", "default", "depends", "help", "prompt", "select", "string"] @@ -224,11 +225,8 @@ class Indent(_CheckFunction): text] elif entry in entries_that_should_not_be_indented: if not text.startswith(entry): - # four Config.in files have a special but legitimate indentation rule - if self.filename in ["package/Config.in", - "package/Config.in.host", - "package/kodi/Config.in", - "package/x11r7/Config.in"]: + # some Config.in files have a special but legitimate indentation rule + if self.enabled_flags["ignore-menu-indent-below"]: return return ["{}:{}: should not be indented" .format(self.filename, lineno),