From nobody Fri Jun 28 05:51:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548229085369933.2073390846566; Tue, 22 Jan 2019 23:38:05 -0800 (PST) Received: from localhost ([127.0.0.1]:57319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gmD6q-0007ea-Cu for importer@patchew.org; Wed, 23 Jan 2019 02:38:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gmCWv-0005W7-Qx for qemu-devel@nongnu.org; Wed, 23 Jan 2019 02:00:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gmCWu-00048E-LP for qemu-devel@nongnu.org; Wed, 23 Jan 2019 02:00:57 -0500 Received: from mga18.intel.com ([134.134.136.126]:36921) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gmCWu-0002NF-D0 for qemu-devel@nongnu.org; Wed, 23 Jan 2019 02:00:56 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2019 22:59:55 -0800 Received: from he.bj.intel.com ([10.238.157.85]) by orsmga001.jf.intel.com with ESMTP; 22 Jan 2019 22:59:53 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,510,1539673200"; d="scan'208";a="129981129" From: Yang Zhong To: qemu-devel@nongnu.org Date: Wed, 23 Jan 2019 14:56:17 +0800 Message-Id: <20190123065618.3520-44-yang.zhong@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190123065618.3520-1-yang.zhong@intel.com> References: <20190123065618.3520-1-yang.zhong@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 Subject: [Qemu-devel] [RFC PATCH v4 43/44] minikconf: implement allyesconfig, allnoconfig, randconfig, defconfig X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, peter.maydell@linaro.org, thuth@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com, sameo@linux.intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Apart from defconfig (which is a no-op), the others are implemented implemented simply by ignoring the RHS of assignments and "default" statements. The RHS is replaced respectively by "true", "false" or a random value. Signed-off-by: Paolo Bonzini --- Makefile | 5 +++++ scripts/minikconf.py | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index c4b5c35ff5..97c6453415 100644 --- a/Makefile +++ b/Makefile @@ -336,6 +336,11 @@ MINIKCONF_ARGS =3D \ =20 MINIKCONF =3D $(SHELL) $(SRC_PATH)/scripts/minikconf.sh =20 +.PHONY: allyesconfig allnoconfig defconfig randconfig +allyesconfig allnoconfig defconfig randconfig: + rm */config-devices.mak config-all-devices.mak + $(MAKE) MINIKCONF=3D"$(MINIKCONF) --$<" config-all-devices.mak + %/config-devices.mak: default-configs/%-softmmu.mak Kconfig.host hw/Kconfig $(call quiet-command, \ $(MINIKCONF) $@ $*-config-devices.mak.d $^ $(MINIKCONF_ARGS) >= $@.tmp, " GEN $@.tmp") diff --git a/scripts/minikconf.py b/scripts/minikconf.py index b0b4f76733..a6c2f0c759 100644 --- a/scripts/minikconf.py +++ b/scripts/minikconf.py @@ -13,8 +13,10 @@ import os import sys import re +import random =20 -__all__ =3D [ 'KconfigParserError', 'KconfigData', 'KconfigParser' ] +__all__ =3D [ 'KconfigParserError', 'KconfigData', 'KconfigParser', + 'defconfig', 'allyesconfig', 'allnoconfig', 'randconfig' ] =20 def debug_print(*args): #print ' '.join(str(x) for x in args) @@ -30,6 +32,11 @@ def debug_print(*args): # just its name). # ------------------------------------------- =20 +allyesconfig =3D lambda x: True +allnoconfig =3D lambda x: False +defconfig =3D lambda x: x +randconfig =3D lambda x: random.randint(0, 1) =3D=3D 1 + class KconfigData: class Expr: def __and__(self, rhs): @@ -178,7 +185,8 @@ class KconfigData: if self.cond.evaluate(): self.dest.set_value(True) =20 - def __init__(self): + def __init__(self, value_mangler=3Ddefconfig): + self.value_mangler =3D value_mangler self.previously_included =3D [] self.incl_info =3D None self.defined_vars =3D set() @@ -256,10 +264,12 @@ class KconfigData: return var_obj =20 def do_assignment(self, var, val): - self.clauses.append(KconfigData.AssignmentClause(var, val)) + f =3D self.value_mangler + self.clauses.append(KconfigData.AssignmentClause(var, f(val))) =20 def do_default(self, var, val, cond=3DNone): - self.clauses.append(KconfigData.DefaultClause(var, val, cond)) + f =3D self.value_mangler + self.clauses.append(KconfigData.DefaultClause(var, f(val), cond)) =20 def do_depends_on(self, var, expr): self.clauses.append(KconfigData.DependsOnClause(var, expr)) @@ -307,9 +317,10 @@ class KconfigParserError(Exception): return "%s: %s" % (self.loc, self.msg) =20 class KconfigParser: + @classmethod - def parse(self, fp): - data =3D KconfigData() + def parse(self, fp, mode=3DNone): + data =3D KconfigData(mode or KconfigParser.defconfig) parser =3D KconfigParser(data) parser.parse_file(fp) return data @@ -625,11 +636,29 @@ class KconfigParser: =20 if __name__ =3D=3D '__main__': argv =3D sys.argv + mode =3D defconfig + if len(sys.argv) > 1: + if argv[1] =3D=3D '--defconfig': + del argv[1] + elif argv[1] =3D=3D '--randconfig': + mode =3D randconfig + del argv[1] + elif argv[1] =3D=3D '--allyesconfig': + mode =3D allyesconfig + del argv[1] + elif argv[1] =3D=3D '--allnoconfig': + mode =3D allnoconfig + del argv[1] + if len(argv) =3D=3D 1: print >>sys.stderr, "%s: at least one argument is required" % argv= [0] os.exit(1) =20 - data =3D KconfigData() + if argv[1].startswith('-'): + print >>sys.stderr, "%s: invalid option %s" % (argv[0], argv[1]) + os.exit(1) + + data =3D KconfigData(mode) parser =3D KconfigParser(data) for arg in argv[3:]: m =3D re.match(r'^(CONFIG_[A-Z0-9_]+)=3D([yn]?)$', arg) --=20 2.17.1