From patchwork Fri Feb 1 18:03:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1035045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43rlMl4GZvz9s4Z; Sat, 2 Feb 2019 05:03:31 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gpd9v-000140-EF; Fri, 01 Feb 2019 18:03:23 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1gpd9u-00013g-Hk for kernel-team@lists.ubuntu.com; Fri, 01 Feb 2019 18:03:22 +0000 Received: from mail-qk1-f197.google.com ([209.85.222.197]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gpd9u-0004XG-8E for kernel-team@lists.ubuntu.com; Fri, 01 Feb 2019 18:03:22 +0000 Received: by mail-qk1-f197.google.com with SMTP id v64so8015157qka.5 for ; Fri, 01 Feb 2019 10:03:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=pwatpcMBo8Smm+JWzrBiQEUG2Y6ENGcLaAERzZOBj8I=; b=a4chUmlX+1Znt0ShdqFRqro54ZuB/QOc6ue0j1yb4oyMwEEKvq48qSIGJM0X/TMyWd pWbi5YBsOgaSURkA7ZuOv27iOihshjKgfqvsoJmRcCQtWqHF7tE7QmZiX/4yEdGTPXO1 Oq1JeFkefqJRkLcBhkCgsQxvXstARE0Cv4n9PU5IeeaKL2EbUtehnz0kZwQEem7RnbGh wzPcJEtVjbcEu18T2unZyPffL4UNZzOz+ZC/fkmUREqu35AbYcMG7iFV6Cn78xdWGeFY bi/C9xRhuHd7EMtMHuM2t3tSbS5bOwlqoAOLS4PWPhEav1dEs/prdbYNN1N1ihC9khGv +IvQ== X-Gm-Message-State: AJcUukfWlPM1LcCzuY3zNnZWPiLWRMBkVuLA0JO3qjUkPgreHHZqyXg/ avKSAG3jCOnpIF/7QaZIxq2IfdqkMRoUmmIhxXQh0q5EFLQoFXJHxLiR97e3Ok4lNl29lQJ9XGQ 6xPaAv6F9IB7snpw2ET79P0WuIGAlbFwday9MH7xH X-Received: by 2002:a37:9bc3:: with SMTP id d186mr36196572qke.22.1549044200521; Fri, 01 Feb 2019 10:03:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN5tTmuOTTuVrdrhczjhRZuLSbomDI9z5sW6fq7SD/Q306IFNGm6gV1UHuu7+cQ9lramP2jyxQ== X-Received: by 2002:a37:9bc3:: with SMTP id d186mr36196540qke.22.1549044200116; Fri, 01 Feb 2019 10:03:20 -0800 (PST) Received: from gallifrey.lan ([189.61.208.219]) by smtp.gmail.com with ESMTPSA id k62sm6147636qte.86.2019.02.01.10.03.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 10:03:19 -0800 (PST) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [X, B, C, D, unstable][PATCH] UBUNTU: [Packaging] config-check: Add an include directive Date: Fri, 1 Feb 2019 16:03:15 -0200 Message-Id: <20190201180315.28270-1-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: http://bugs.launchpad.net/bugs/1752072 Update the config-check script to support a new include directive, that can be used to override annotations from another file. For instance, with this change a custom kernel can include the annotation file from "debian.master/" and override some of it policies. The directive is only available when using the file format 3, that extends format 2. The new directive follows the systax: include FILEPATH Quotes are also accepted: include "FILEPATH" `FILENAME` is always relative to the current annotations file location. So, assuming a custom kernel, the following directive will include the annotations file from the generic kernel: include "../../debian.master/config/annotations" To avoid mistakes, any reference to a config in the base annotations file AFTER the include directive will completely override the references from the included file. For instance, the following: # FORMAT: 3 include "../../debian.master/config/annotations" CONFIG_X note Will cause any line related to CONFIG_X in the included annotations file to be ignored. The patch also includes smalls changes to avoid warning due to duplicate variable declarations. Signed-off-by: Marcelo Henrique Cerri Acked-by: Kamal Mostafa Acked-by: Seth Forshee --- That's a patch to replace the patch "config-check: allow overlay annotations files". --- debian/scripts/config-check | 80 +++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/debian/scripts/config-check b/debian/scripts/config-check index 224be080514a..843f5999006b 100755 --- a/debian/scripts/config-check +++ b/debian/scripts/config-check @@ -3,6 +3,8 @@ # check-config -- check the current config for issues # use strict; +use File::Basename; +use File::Spec; my $P = 'check-config'; @@ -13,7 +15,7 @@ if ($ARGV[0] eq '--test') { die "Usage: $P \n"; } -my ($config, $arch, $flavour, $commonconfig, $warn_only) = @ARGV; +my ($configfile, $arch, $flavour, $commonconfig, $warn_only) = @ARGV; my %values = (); @@ -25,8 +27,8 @@ $fail_exit = 0 if ($warn_only eq 'true' || $warn_only eq '1'); my $exit_val = 0; # Load up the current configuration values -- FATAL if this fails -print "$P: $config: loading config\n"; -open(CONFIG, "<$config") || die "$P: $config: open failed -- $! -- aborting\n"; +print "$P: $configfile: loading config\n"; +open(CONFIG, "<$configfile") || die "$P: $configfile: open failed -- $! -- aborting\n"; while () { # Pull out values. /^#*\s*(CONFIG_\w+)[\s=](.*)$/ or next; @@ -38,38 +40,74 @@ while () { } close(CONFIG); -# ANNOTATIONS: check any annotations marked for enforcement -my $pass = 0; -my $total = 0; -my $annotations = "$commonconfig/annotations"; -my ($config, $value, $options, $option, $value, $check, $policy); -print "$P: $annotations loading annotations\n"; -my %annot; -my $form = 1; -open(ANNOTATIONS, "<$annotations") || die "$P: $annotations: open failed -- $! -- aborting\n"; -while () { +sub read_annotations { + my ($filename) = @_; + my %annot; + my $form = 1; + my ($config, $value, $options); + + # Keep track of the configs that shouldn't be appended because + # they were include_annot from another annotations file. + # That's a hash of undefs, aka a set. + my %noappend; + + print "$P: $filename loading annotations\n"; + open(my $fd, "<$filename") || + die "$P: $filename: open failed -- $! -- aborting\n"; + while (<$fd>) { if (/^# FORMAT: (\S+)/) { - die "$P: $1: unknown annotations format\n" if ($1 != 2); - $form = $1; + die "$P: $1: unknown annotations format\n" if ($1 != 2 && $1 != 3); + $form = $1; + } + + # Format #3 adds the include directive on top of format #2: + if ($form == 3 && /^\s*include(\s|$)/) { + # Include quoted or unquoted files: + if (/^\s*include\s+"(.*)"\s*$/ || /^\s*include\s+(.*)$/) { + # The include is relative to the current file + my $include_filename = File::Spec->join(dirname($filename), $1); + # Append the include files + my %include_annot = read_annotations($include_filename); + %annot = ( %annot, %include_annot ); + # And marked them to not be appended: + my %included_noappend; + # Discard the values and keep only the keys + @included_noappend{keys %include_annot} = (); + %noappend = ( %noappend, %included_noappend ); + next; + } else { + die "$P: Invalid include: $_"; + } } /^#/ && next; chomp; /^$/ && next; - /^CONFIG_/ || next; if ($form == 1) { - ($config, $value, $options) = split(' ', $_, 3); - } elsif ($form == 2) { - ($config, $options) = split(' ', $_, 2); + ($config, $value, $options) = split(' ', $_, 3); + } elsif ($form >= 2) { + ($config, $options) = split(' ', $_, 2); } + if (exists $noappend{$config}) { + delete $annot{$config}; + delete $noappend{$config}; + } $annot{$config} = $annot{$config} . ' ' . $options; + } + close($fd); + return %annot; } -close(ANNOTATIONS); -my $config; +# ANNOTATIONS: check any annotations marked for enforcement +my $annotations = "$commonconfig/annotations"; +my %annot = read_annotations($annotations); + +my $pass = 0; +my $total = 0; +my ($config, $value, $options, $option, $check, $policy); for $config (keys %annot) { $check = 0; $options = $annot{$config};