From patchwork Tue Jan 9 08:30:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123811 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3750396qgn; Tue, 9 Jan 2018 00:32:57 -0800 (PST) X-Google-Smtp-Source: ACJfBotdzbyjZc4nnIjYIS93s+A4HLp9qD6i4+ZmkTC8o8H8kcwL66F1hYY7cILTZU/bYs2PJHFX X-Received: by 10.98.79.12 with SMTP id d12mr5841354pfb.186.1515486777897; Tue, 09 Jan 2018 00:32:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486777; cv=none; d=google.com; s=arc-20160816; b=ukUKmpkos4JOR+EymRk8G/KcOfmHe8k04gvtKpTabZ6NXc8a1XG64PenHFVtWX5KzK kTS/aaJszYp13CCOclvO/l2yBs6v4ryUAYl6leE2jTY6ZYtmC6zjrui+PiEhrKOSp4Ob cYFb2e8FrBZCX7QZBImaUB/EY3J1+ZO0e18nv01i8nER2XZLFgJ/PA40R/TCNNrKMG8f e9bCzufKKS4rUYnMKd3vwSnZoK+r+mhR+5cwAF1fTrwquV21SeUSY782g+mtpFg6For9 w3yP7PBg8IrCloVfupqpOgUj425Iceg5t7joBumc+hbunU7BoD4NOAuLgM6CLazxfgw9 Vz2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=p2IiKeUeeCM1PZk1FiBC3mNu2+yZuCe6Dxyrlt1dsLI=; b=EhHK0KrbnTks9336QUmDHIzf/G4JkJlKxdqC/dBjH79WoGnuwxMx/dbh4BVk2JwUpB PqGg7K39AVWeI1mt/B13PU3eXgdNCXE93wPODdktm57+PqAgo1LV/rVltfIYIQJ4HHf5 Xee7sHWFrF7kPxPZ3z/m0db+9c9MCHkXd7uYNpPLibEBkn8589oDKt2NyS2r58sE9E2O IkxIstHdRes7wkM5dXw03HRvfm/MoFGtEK0HA74DNTiK4yl9tQ1djW36KywOQBPl2Izy jEMxA1MTUwJGo6lI8hRdmP1GyiAtjAwKukUYmGB5jYjzy2BpH/yhAk/JkUC7FQGWzGTq 1pGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QxaMMGre; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si8703618pgc.748.2018.01.09.00.32.57; Tue, 09 Jan 2018 00:32:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QxaMMGre; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751388AbeAIIcB (ORCPT + 28 others); Tue, 9 Jan 2018 03:32:01 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27301 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750985AbeAIIb7 (ORCPT ); Tue, 9 Jan 2018 03:31:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugw024960; Tue, 9 Jan 2018 17:30:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugw024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486659; bh=p2IiKeUeeCM1PZk1FiBC3mNu2+yZuCe6Dxyrlt1dsLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QxaMMGrefYwC38qjfMpZy1emijJWar2O2XCXvW71tWio9AqJCCwBWnm/Wr3PHJcMX BZIBCk1/25DWjKSfKs2Kbl29Ss5d7kpSKDFWqRh1X+FIgM7Il6TYB8aUIhRk8oo0HG rY2pja2N0BPMMm+u6NLMSkE6p2ZBYDVK9q6vOQlOCrcjOTIuwekCXQOKsTvEVMNOp2 ruAWZT5llXLL71NVUIkCnebkBQhBHbasBoNtrjj+lUhsUJx9DaxkwKO7bzmdNiOFm3 rzG7DZNYPh6ZUGbdxcmzi56ajA4eSkiZ30gmnxW1d/KQikV5aJe6+iCkBELNeJdBUH 5NZcW+DvJc7cw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] fixdep: refactor parse_dep_file() Date: Tue, 9 Jan 2018 17:30:49 +0900 Message-Id: <1515486650-1141-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> References: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org parse_dep_file() has too much indentation, and puts the code far to the right. This commit refactors the code and reduces the one level of indentation. strrcmp() computes 'slen' by itself, but the caller already knows the length of the token, so 'slen' can be passed via function argument. With this, we can swap the order of strrcmp() and "*p = \0;" Also, strrcmp() is an ambiguous function name. Flip the logic and rename it to str_ends_with(). I added a new helper is_ignored_file() - this returns 1 if the token represents a file that should be ignored. Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 80 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index bb6d2da..3881bf1 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -250,15 +250,14 @@ static void parse_config_file(const char *p) } /* test if s ends in sub */ -static int strrcmp(const char *s, const char *sub) +static int str_ends_with(const char *s, int slen, const char *sub) { - int slen = strlen(s); int sublen = strlen(sub); if (sublen > slen) - return 1; + return 0; - return memcmp(s + slen - sublen, sub, sublen); + return !memcmp(s + slen - sublen, sub, sublen); } static void *load_file(const char *filename) @@ -293,6 +292,16 @@ static void *load_file(const char *filename) return buf; } +/* Ignore certain dependencies */ +static int is_ignored_file(const char *s, int len) +{ + return str_ends_with(s, len, "include/generated/autoconf.h") || + str_ends_with(s, len, "include/generated/autoksyms.h") || + str_ends_with(s, len, "arch/um/include/uml-config.h") || + str_ends_with(s, len, "include/linux/kconfig.h") || + str_ends_with(s, len, ".ver"); +} + /* * Important: The below generated source_foo.o and deps_foo.o variable * assignments are parsed not only by make, but also by the rather simple @@ -325,47 +334,38 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps) if (is_target) { /* The /next/ file is the first dependency */ is_first_dep = 1; - } else { + } else if (!is_ignored_file(m, p - m)) { *p = '\0'; - /* Ignore certain dependencies */ - if (strrcmp(m, "include/generated/autoconf.h") && - strrcmp(m, "include/generated/autoksyms.h") && - strrcmp(m, "arch/um/include/uml-config.h") && - strrcmp(m, "include/linux/kconfig.h") && - strrcmp(m, ".ver")) { + /* + * Do not list the source file as dependency, so that + * kbuild is not confused if a .c file is rewritten + * into .S or vice versa. Storing it in source_* is + * needed for modpost to compute srcversions. + */ + if (is_first_dep) { /* - * Do not list the source file as dependency, - * so that kbuild is not confused if a .c file - * is rewritten into .S or vice versa. Storing - * it in source_* is needed for modpost to - * compute srcversions. + * If processing the concatenation of multiple + * dependency files, only process the first + * target name, which will be the original + * source name, and ignore any other target + * names, which will be intermediate temporary + * files. */ - if (is_first_dep) { - /* - * If processing the concatenation of - * multiple dependency files, only - * process the first target name, which - * will be the original source name, - * and ignore any other target names, - * which will be intermediate temporary - * files. - */ - if (!saw_any_target) { - saw_any_target = 1; - printf("source_%s := %s\n\n", - target, m); - printf("deps_%s := \\\n", - target); - } - is_first_dep = 0; - } else - printf(" %s \\\n", m); - - buf = load_file(m); - parse_config_file(buf); - free(buf); + if (!saw_any_target) { + saw_any_target = 1; + printf("source_%s := %s\n\n", + target, m); + printf("deps_%s := \\\n", target); + } + is_first_dep = 0; + } else { + printf(" %s \\\n", m); } + + buf = load_file(m); + parse_config_file(buf); + free(buf); } if (is_last)