From patchwork Thu Jan 11 13:05:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 124197 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp654555qgn; Thu, 11 Jan 2018 05:07:46 -0800 (PST) X-Google-Smtp-Source: ACJfBou/xru5tW1yPeKfKt4xum+KLLpVAZfEUviTj5PZEPC43daJ4RECd2D7fzHk/Uj2Zf6r2W6L X-Received: by 10.159.247.129 with SMTP id e1mr15025955pls.330.1515676066737; Thu, 11 Jan 2018 05:07:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515676066; cv=none; d=google.com; s=arc-20160816; b=GAZ4eNysnVUh07lhNOnhDuYZZPJKcvlRhIHUy/qN+S9duQyrhdra2TPVN27toxc8p/ rmEZe3uKBi/0uvR9uAgXhErS1Vfjh5A8HLSWWPuH6gUnevm1geU6EemYVuPM9T2pfvwf CoBH9CIIFISq/lAZyhf0hhRZzQnPdagvGh3DSRh33n2WwZ6uOQFQgtTU4HSTMgV8E5+9 VTc0O97/juGtwYS32KW2hpM9rfxmfBFUVOubYJzlAPKMWYn1eyTHXEiebgGJYHJSKA6l mcuWNMqkoejxqXp7tjmztSUKAr8W3/BVKBzrAyvIMRAfKf/9ALWIf0GrO3uYarNid8Iw uDbg== 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=MeF0KCtHw5TauBWNsBow2HMdNQMYrHzZXLyCfHzFnps=; b=jBt43tTK7U43cfie7y6FcpMS23xusZei2aFpMEwk4F457r4GlJuZMUlhH240UkMFTK Buzwp+JKKulV4kQtq2UjqxfvaYpClhnqyV5MvlVpiBYhJR0C2DnUF+EuV9diKdw17bem eHzr4p2IDsqM1BtoIAERX+uY8UPlOL6lHF1zT9LSfllrxi6rDqblt7KdDyM/Y6WTKbDF TYfq3mE8aF9I4eyPU22dZbOlK8+y8rHguS+5aMdx2YoTeCSQD5GT4SIq6pCHRr9V1Pt1 5/JQayB+fFsLt1BdsHawDIrwtrnU2RYM/mjCEUOC0uAKz0fR0kLfQlbg/wxCknDb1V9N PG+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ygdEH868; 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 v20si14302059plo.820.2018.01.11.05.07.46; Thu, 11 Jan 2018 05:07:46 -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=ygdEH868; 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 S934495AbeAKNHo (ORCPT + 28 others); Thu, 11 Jan 2018 08:07:44 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:60578 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934031AbeAKNG1 (ORCPT ); Thu, 11 Jan 2018 08:06:27 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w0BD5mX6031475; Thu, 11 Jan 2018 22:05:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w0BD5mX6031475 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515675952; bh=MeF0KCtHw5TauBWNsBow2HMdNQMYrHzZXLyCfHzFnps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ygdEH868QPJPvvWpRkWjccWx+ZhUaoRGV7MC2Aed8ueu38W3cvhMQmSadlzzvA7Ve dcF8V7pEuU/ekSmeiKqwUO/UwePrv1DxbMGVUsCcRqzOXc0XWw/qYWo9JhV/dEmXcb 0ZN5moN3N7T47Cvnc0ZcWQo3gicymuKp/C9QHJgltdT2lXpz8nZ+zeZ681ziPrB9HO SXuHPmoHct/FzmBrqjWnogtc6MGiwAjvW5XZ2+P0bjw6cLLP4tZ+pZssfgRdtwA5Pb ru7tIgk17VSkiUmQgH2gNa5vEptEZMm+yOa6fUQ88++iV6Bx1B/BrRGrt4/xI8gJP0 QtIcV69J0h45g== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Michal Marek , Sam Ravnborg , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] fixdep: refactor parse_dep_file() Date: Thu, 11 Jan 2018 22:05:45 +0900 Message-Id: <1515675946-7514-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515675946-7514-1-git-send-email-yamada.masahiro@socionext.com> References: <1515675946-7514-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 --- Changes in v2: None 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 d33b5a4..0abc15778 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -239,15 +239,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 *read_file(const char *filename) @@ -282,6 +281,16 @@ static void *read_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 @@ -314,47 +323,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 = read_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 = read_file(m); + parse_config_file(buf); + free(buf); } if (is_last)