From patchwork Fri Nov 30 09:15:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 152500 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3423617ljp; Fri, 30 Nov 2018 01:17:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wnvy9C+cl/bIqDYYxyx5Y7rVrgIb4zhItBpPKZrAb669m7yuHavAmbNkJBnam4FNmpCLeE X-Received: by 2002:a17:902:d905:: with SMTP id c5mr4778208plz.43.1543569442439; Fri, 30 Nov 2018 01:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543569442; cv=none; d=google.com; s=arc-20160816; b=Y6582x/PiyIMDfYX0GC2JtvWwd1ov79OE25Uabl/L5YYbFYjZHc8k3klPiS7VRsHuL mIm1cE00iC86rfruU4V22VRRJmXZJYE1jCY+6IpZO4K16lntdCL1vOYuUOcbn0HmE1cy i2A771cwsBaK02cc9L4cjI5sTPTNjyjO2XuBm9T4xH0cGmhWGPndwzpbAOIrChw0mKFN Ql9MBS+diQ9ioSy9lLBbF1Z9E95KWNmK4dn9PXlfwgmzUvodRbriX5Epr/hRLebU6V/t /a7eOn8q18pzGo5PRNGIIWnk3jUygYMCt06deuqe+e3pXpLbm0HEtezGm0gsNq/T/mWC aWzQ== 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; bh=HiMqj/ME+AaGau+DxV454Be5fNhnAhoE/t6iCz3z6jg=; b=R6v/FJMXvVpIUVZczXOMvoYbrpG6RcS9J/C84vrIADiTSxkvJatkxfqW6toD0p1CE2 ikYfVjhjYDDnku0PqGobvkxvEbqwiS//tWBZ+6dwbDc1f/k26gwPt0ynXuA6Co8Kp61B xknmcXYxWLHidsT6QxkDL10oaIWfn0AdkyXoe78D1i4MR8lUu9P/q2q8HbpuU4L7nH5e igWqtwMacE5Pxx6KecvdYApHWCxO4iXzjPJxvPPFbre3pRSeiADqNjVsgifX5ZIU6s/H lXniSYql+2wTxhLqdV7d4etiPPBgLprEo8LcxeOFDte8VyKMKtBAM4CEA5UZlm6IjS8y Rygw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=0lPI4l5Q; 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 m65si5030740pfg.282.2018.11.30.01.17.21; Fri, 30 Nov 2018 01:17:22 -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=0lPI4l5Q; 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 S1726789AbeK3UZ7 (ORCPT + 32 others); Fri, 30 Nov 2018 15:25:59 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:53048 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726644AbeK3UZx (ORCPT ); Fri, 30 Nov 2018 15:25:53 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id wAU9GEac028692; Fri, 30 Nov 2018 18:16:16 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com wAU9GEac028692 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1543569376; bh=HiMqj/ME+AaGau+DxV454Be5fNhnAhoE/t6iCz3z6jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0lPI4l5QGeZ4FmFhB/3a9h8BVW7oBdM/qSU9p6YwNGzHP9nRB0gfgHj4pYmH1yGWG LYkh7Cdo4wdnem8m11bWar/IW3pOibroI/ohq/5zaDRUdMNA1Yno7CTlHfcgpIJ8O6 KpBuc3YgtCTBHzujQm5/l2RK67n2I7l/afD+pig7sHvZ6iOYZ1f3rTNJfQb5qUfD2o HaivYoNgvbqvyMDdLJlyMizYgephTbiAdrP8Cia/Z9H2CZm9EhVcjoONNpyn0MCrjl D65NB86DUMrUMmuk8psBlyhvHN7XST8u+mdfsArGImSb1Fl3IrtjexDxmqeJHnPm+s OppF+2kH0PB7g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Ulf Magnusson , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] kconfig: split out code touching a file to conf_touch_dep() Date: Fri, 30 Nov 2018 18:15:50 +0900 Message-Id: <1543569352-4899-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543569352-4899-1-git-send-email-yamada.masahiro@socionext.com> References: <1543569352-4899-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 conf_touch_deps() iterates over symbols, touching corresponding include/config/*.h files as needed. Split the part that touches a single file into a new helper so it can be reused. The new helper, conf_touch_dep(), takes a symbol name as a parameter, and touches the corresponding include/config/*.h file. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 92 ++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 43 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 4c76d56..7263b83 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -74,6 +74,47 @@ static int make_parent_dir(const char *path) return 0; } +static char depfile_path[PATH_MAX]; +static size_t depfile_prefix_len; + +/* touch depfile for symbol 'name' */ +static int conf_touch_dep(const char *name) +{ + int fd, ret; + const char *s; + char *d, c; + + /* check overflow: prefix + name + ".h" + '\0' must fix in buffer. */ + if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path)) + return -1; + + d = depfile_path + depfile_prefix_len; + s = name; + + while ((c = *s++)) + *d++ = (c == '_') ? '/' : tolower(c); + strcpy(d, ".h"); + + /* Assume directory path already exists. */ + fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd == -1) { + if (errno != ENOENT) + return -1; + + ret = make_parent_dir(depfile_path); + if (ret) + return ret; + + /* Try it again. */ + fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd == -1) + return -1; + } + close(fd); + + return 0; +} + struct conf_printer { void (*print_symbol)(FILE *, struct symbol *, const char *, void *); void (*print_comment)(FILE *, const char *, void *); @@ -909,21 +950,16 @@ static int conf_write_dep(const char *name) static int conf_touch_deps(void) { const char *name; - char path[PATH_MAX+1]; - char *s, *d, c; struct symbol *sym; - int res, i, fd; + int res, i; + + strcpy(depfile_path, "include/config/"); + depfile_prefix_len = strlen(depfile_path); name = conf_get_autoconfig_name(); conf_read_simple(name, S_DEF_AUTO); sym_calc_value(modules_sym); - if (make_parent_dir("include/config/foo.h")) - return 1; - if (chdir("include/config")) - return 1; - - res = 0; for_all_symbols(i, sym) { sym_calc_value(sym); if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) @@ -975,42 +1011,12 @@ static int conf_touch_deps(void) * different from 'no'). */ - /* Replace all '_' and append ".h" */ - s = sym->name; - d = path; - while ((c = *s++)) { - c = tolower(c); - *d++ = (c == '_') ? '/' : c; - } - strcpy(d, ".h"); - - /* Assume directory path already exists. */ - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd == -1) { - if (errno != ENOENT) { - res = 1; - break; - } - - if (make_parent_dir(path)) { - res = 1; - goto out; - } - - /* Try it again. */ - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd == -1) { - res = 1; - break; - } - } - close(fd); + res = conf_touch_dep(sym->name); + if (res) + return res; } -out: - if (chdir("../..")) - return 1; - return res; + return 0; } int conf_write_autoconf(int overwrite)