From patchwork Thu May 19 06:51:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 68096 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3033027qge; Wed, 18 May 2016 23:53:55 -0700 (PDT) X-Received: by 10.28.129.22 with SMTP id c22mr35604239wmd.89.1463640834910; Wed, 18 May 2016 23:53:54 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id m8si15789770wjh.93.2016.05.18.23.53.54; Wed, 18 May 2016 23:53:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EADE4A769D; Thu, 19 May 2016 08:53:16 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mbmTwO7w2OeR; Thu, 19 May 2016 08:53:16 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6B564A769F; Thu, 19 May 2016 08:52:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BC96DA750E for ; Thu, 19 May 2016 08:51:31 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5sAhVP4Tu8iL for ; Thu, 19 May 2016 08:51:31 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-12.nifty.com (conuserg-12.nifty.com [210.131.2.79]) by theia.denx.de (Postfix) with ESMTPS id 70433A7531 for ; Thu, 19 May 2016 08:51:26 +0200 (CEST) Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id u4J6p2Zl001067; Thu, 19 May 2016 15:51:08 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com u4J6p2Zl001067 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1463640669; bh=rW5pB81Kp6bKLeSbO33C44d8U7f6lVX0DIKqLugHr4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Azx6R6hTNWW29HglPYY80B8H1UgVP9LrKnsLnBFHgyijUmCr32stIIPe027P3nTW7 NTQygwGXFq737YWqxrEKPhw9IhEIirsKf2KTI/OugsfH9aq83NzsANx/5eOQ9SMzoE jEMv1oX/m7Qsjpisft56tSCYVdq2j/Y+GzojFczwuf5Vko6OtXjaWq9brexn9AV/1p bFu9mxc+QumBf3ljNe09FzG51RD19AnvRjSW60lIp72IOjCuIOzJdJf4x5JbhpZNZX Ag0AD4kMXwROJwGDny+7wzBZS2A4VS8Hl6CkEUmnZoUq1e/wEwMLsMOC6D/ZQ41eJd +GVMKEGzlSLbQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Thu, 19 May 2016 15:51:56 +0900 Message-Id: <1463640729-25666-9-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463640729-25666-1-git-send-email-yamada.masahiro@socionext.com> References: <1463640729-25666-1-git-send-email-yamada.masahiro@socionext.com> Cc: Joe Hershberger Subject: [U-Boot] [PATCH 08/21] tools: moveconfig: do not rely on type and default value given by users X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Commit 96464badc794 ("moveconfig: Always run savedefconfig on the moved config") changed the work flow of this tool a lot from the original intention when this tool was designed first. Since then, before running this tool, users must edit the Kconfig to add the menu entries for the configs they are moving. It means users had already specified the type and the default value for each CONFIG via the Kconfig entries. Nevertheless, users are still required to dictate the same type and the default value in each line of the input file. So, my idea here is to deprecate the latter. Before moving forward with it, there is one thing worth mentioning; since the savedefconfig re-sync was introduced, there is a case this tool can not handle correctly. Let's say we are moving CONFIG_FOO from board headers to Kconfig, and we want to make it "default y" option. First, we are supposed to create an entry: config FOO bool "foo" default y CONFIG_FOO=y will appear in the .config for every processed defconfig. It will be duplicated to the include/autoconf.mk as well unless the board explicitly #undef's it. Therefore, the defconfig without "#define CONFIG_FOO" or "#undef CONFIG_FOO" that should be converted to "unset" would be misconverted to "=y". Anyway, this has been a problem for a while. Yet, I am not inclined to revert that commit because the "create a Kconfig entry beforehand, and sync with savedefconfig" approach has been successful in practical use cases. I will come back to this problem with a different solution in a few commits later. For other use cases, I see no reason to require redundant dictation in the input file of this tool. Instead, the tool can know the types and default values by parsing the .config file. This commit changes the tool to use the CONFIG names, but ignore the types and default values given by the input file. This commit also fixes one bug. Before this commit, the tool could not move a integer-typed CONFIG with value 1. For example, assume we are moving CONFIG_CONS_INDEX. Please note this is a integer type option. Many board headers define this CONFIG as 1. #define CONFIG_CONS_INDEX 1 It will be converted to CONFIG_CONS_INDEX=y and moved to include/autoconf.mk, by the tools/scripts/define2mk.sed. It will cause "make savedefconfig" to fail due to the type conflict. This commit takes care of it by detecting the type and converting the CONFIG value correctly. Signed-off-by: Masahiro Yamada --- tools/moveconfig.py | 88 ++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 45 deletions(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 5e78266..ee0afbd 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -70,13 +70,17 @@ It looks like one of the followings: - Move 'CONFIG_... ' This config option was moved to the defconfig - - Default value 'CONFIG_...'. Do nothing. - The value of this option is the same as default. - We do not have to add it to the defconfig. - - - 'CONFIG_...' already exists in Kconfig. Do nothing. - This config option is already defined in Kconfig. - We do not need/want to touch it. + - CONFIG_... is not defined in Kconfig. Do nothing. + The entry for this CONFIG was not found in Kconfig. + There are two common cases: + - You forgot to create an entry for the CONFIG before running + this tool, or made a typo in a CONFIG passed to this tool. + - The entry was hidden due to unmet 'depends on'. + This is correct behavior. + + - 'CONFIG_...' is the same as the define in Kconfig. Do nothing. + The define in the config header matched the one in Kconfig. + We do not need to touch it. - Undefined. Do nothing. This config option was not found in the config header. @@ -216,9 +220,8 @@ STATE_AUTOCONF = 2 STATE_SAVEDEFCONFIG = 3 ACTION_MOVE = 0 -ACTION_DEFAULT_VALUE = 1 -ACTION_ALREADY_EXIST = 2 -ACTION_UNDEFINED = 3 +ACTION_NO_ENTRY = 1 +ACTION_NO_CHANGE = 2 COLOR_BLACK = '0;30' COLOR_RED = '0;31' @@ -464,7 +467,7 @@ class KconfigParser: return CROSS_COMPILE.get(arch, None) - def parse_one_config(self, config_attr, defconfig_lines, autoconf_lines): + def parse_one_config(self, config_attr, dotconfig_lines, autoconf_lines): """Parse .config, defconfig, include/autoconf.mk for one config. This function looks for the config options in the lines from @@ -474,7 +477,7 @@ class KconfigParser: Arguments: config_attr: A dictionary including the name, the type, and the default value of the target config. - defconfig_lines: lines from the original defconfig file. + dotconfig_lines: lines from the .config file. autoconf_lines: lines from the include/autoconf.mk file. Returns: @@ -484,42 +487,40 @@ class KconfigParser: config = config_attr['config'] not_set = '# %s is not set' % config - if config_attr['type'] in ('bool', 'tristate') and \ - config_attr['default'] == 'n': - default = not_set - else: - default = config + '=' + config_attr['default'] - - for line in defconfig_lines: + for line in dotconfig_lines: line = line.rstrip() if line.startswith(config + '=') or line == not_set: - return (ACTION_ALREADY_EXIST, line) - - if config_attr['type'] in ('bool', 'tristate'): - value = not_set + old_val = line + break else: - value = '(undefined)' + return (ACTION_NO_ENTRY, config) for line in autoconf_lines: line = line.rstrip() if line.startswith(config + '='): - value = line + new_val = line break - - if value == default: - action = ACTION_DEFAULT_VALUE - elif value == '(undefined)': - action = ACTION_UNDEFINED else: - action = ACTION_MOVE + new_val = not_set + + if old_val == new_val: + return (ACTION_NO_CHANGE, new_val) + + # If this CONFIG is neither bool nor trisate + if old_val[-2:] != '=y' and old_val[-2:] != '=m' and old_val != not_set: + # tools/scripts/define2mk.sed changes '1' to 'y'. + # This is a problem if the CONFIG is int type. + # Check the type in Kconfig and handle it correctly. + if new_val[-2:] == '=y': + new_val = new_val[:-1] + '1' - return (action, value) + return (ACTION_MOVE, new_val) def update_dotconfig(self, defconfig): """Parse files for the config options and update the .config. - This function parses the given defconfig, the generated .config - and include/autoconf.mk searching the target options. + This function parses the generated .config and include/autoconf.mk + searching the target options. Move the config option(s) to the .config as needed. Also, display the log to show what happened to the .config. @@ -527,19 +528,18 @@ class KconfigParser: defconfig: defconfig name. """ - defconfig_path = os.path.join('configs', defconfig) dotconfig_path = os.path.join(self.build_dir, '.config') autoconf_path = os.path.join(self.build_dir, 'include', 'autoconf.mk') results = [] - with open(defconfig_path) as f: - defconfig_lines = f.readlines() + with open(dotconfig_path) as f: + dotconfig_lines = f.readlines() with open(autoconf_path) as f: autoconf_lines = f.readlines() for config_attr in self.config_attrs: - result = self.parse_one_config(config_attr, defconfig_lines, + result = self.parse_one_config(config_attr, dotconfig_lines, autoconf_lines) results.append(result) @@ -549,15 +549,13 @@ class KconfigParser: if action == ACTION_MOVE: actlog = "Move '%s'" % value log_color = COLOR_LIGHT_GREEN - elif action == ACTION_DEFAULT_VALUE: - actlog = "Default value '%s'. Do nothing." % value + elif action == ACTION_NO_ENTRY: + actlog = "%s is not defined in Kconfig. Do nothing." % value log_color = COLOR_LIGHT_BLUE - elif action == ACTION_ALREADY_EXIST: - actlog = "'%s' already defined in Kconfig. Do nothing." % value + elif action == ACTION_NO_CHANGE: + actlog = "'%s' is the same as the define in Kconfig. Do nothing." \ + % value log_color = COLOR_LIGHT_PURPLE - elif action == ACTION_UNDEFINED: - actlog = "Undefined. Do nothing." - log_color = COLOR_DARK_GRAY else: sys.exit("Internal Error. This should not happen.")