From patchwork Mon Nov 13 10:29:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 118722 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1625547qgn; Mon, 13 Nov 2017 02:31:46 -0800 (PST) X-Google-Smtp-Source: AGs4zMah6cTxck+KcwvxxYldL/gVaQQTE1r73u1hHRvfj6bWX2HiaPL8RM0xeZSL5rDmjOUEJJJV X-Received: by 10.101.82.130 with SMTP id y2mr8190303pgp.65.1510569106182; Mon, 13 Nov 2017 02:31:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510569106; cv=none; d=google.com; s=arc-20160816; b=IM5TIwIlYm7Nnat0cZussEkJ7cZtZTm4G8H1YXx4ntFZ93UHRg3SDYYeoNZp4ggGuJ MP7JigX8iTvdDXV4am+OC+qRdA9/I9GhAvi7sDv0w3ic64Vcoubr9hUEjmhchXuE2NSW XjsctKZZKRn1pba7BI+aBD9dp8SOpQPn7SMVOsh2++5UarjqyT7V4FaX5YagjeefvN5F IJECsrf28Y59w7WF1iqD3ccwnjEFnq1SmdNLHnIBElOo1L2ZfJDj+9oO6ml9rzNPYCjK uAXoJMbiE/V3Et+KpCseP6Mn5owykil//tZdkAdXSKBioqcz2hYO/5s6wHEtBkGPfBEq XQpw== 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=qaZXLHYoiB/ipFxL+tv9kxYX+kTaG7OkVcK45xoIg8Y=; b=AEeH1u+flQdH/GAqBM/+KqLi3tMIBlK1dcWqBHI0qbsHedFEZ3f8vb4kAApVaDMHRd BXNJEjq0VIPolT+8jpsrxcK+Cvaur8T96bW15TyIRUky0WtXy5+4xVaAOtEh0yNH7h3z 5btpW04P7itx+3nOl0IlRUuiXQFILilEhmJ3a0GXlHfvvBFF7rLzd+fHCIx48UbJfIBe unIM2znUuFfDQePCa3A0JfPoe/qMIt3swNMFuQdR6wwsG+bsrIVBmYvFEoHQdZvSqked BCFkke4VWKsQwuXodk5+eRGuXnAaiTGsjDEm1HpI9VY38q0NvC2omFm+5kUNMB91tTOE UhRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=K9sMH4ZH; 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 w23si14193381plk.389.2017.11.13.02.31.45; Mon, 13 Nov 2017 02:31: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=K9sMH4ZH; 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 S1752539AbdKMKbn (ORCPT + 27 others); Mon, 13 Nov 2017 05:31:43 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:40628 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbdKMKbf (ORCPT ); Mon, 13 Nov 2017 05:31:35 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id vADATvx2031253; Mon, 13 Nov 2017 19:29:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com vADATvx2031253 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1510568999; bh=qaZXLHYoiB/ipFxL+tv9kxYX+kTaG7OkVcK45xoIg8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K9sMH4ZHfOoWvgfXnsrHqvjYMBzSymo+KwM+QRdIJES7D1CzaVfPWH0R9bKFS+o2m EDXFtJZRHbe99gArqI9+PW7FTZtAb2EGxNMizj89p/ch3Z4rK0F/HChaGTa+CT/gw7 aHXN7b60euzKhq2dJOgmn+8DsTUWewY5jSI+HEoY5aVaDQo2RRuE6mkp7DRn4F82ba 50yNXlsGaAs6uvLE1q8C4dKB3uWVSh4RdL/z0q+45in6+JpoizmKYqkTBy1sjI/WE2 x/O6UEAQlgjnJRqAR5VV47WQwNbruP2InMNXIBoWDzkmmMR0XtZ1uoPVUxJ9J/MfSi SAs3dabNAraBg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Douglas Anderson , Sam Ravnborg , Michal Marek , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] kbuild: create directory for make cache only when necessary Date: Mon, 13 Nov 2017 19:29:34 +0900 Message-Id: <1510568979-24440-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510568979-24440-1-git-send-email-yamada.masahiro@socionext.com> References: <1510568979-24440-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 Currently, the existence of $(dir $(make-cache)) is always checked, and created if it is missing. We can avoid unnecessary system calls by some tricks. [1] If KBUILD_SRC is unset, we are building in the source tree. The output directory checks can be entirely skipped. [2] If at least one cache data is found, it means the cache file was included. Obviously its directory exists. Skip "mkdir -p". [3] If Makefile does not contain any call of __run-and-store, it will not create a cache file. No need to create its directory. [4] The "mkdir -p" should be only invoked by the first call of __run-and-store Signed-off-by: Masahiro Yamada Reviewed-by: Douglas Anderson --- Changes in v2: - Use boolean flag "create-cache-dir" for clarification - Fix a typo in git-log: Obiously -> Obviously scripts/Kbuild.include | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index be1c9d6..065324a 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -99,18 +99,19 @@ cc-cross-prefix = \ # Include values from last time make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk -ifeq ($(wildcard $(dir $(make-cache))),) -$(shell mkdir -p '$(dir $(make-cache))') -endif $(make-cache): ; -include $(make-cache) +cached-data := $(filter __cached_%, $(.VARIABLES)) + # If cache exceeds 1000 lines, shrink it down to 500. -ifneq ($(word 1000,$(filter __cached_%, $(.VARIABLES))),) +ifneq ($(word 1000,$(cached-data)),) $(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \ mv $(make-cache).tmp $(make-cache)) endif +create-cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,1)) + # Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios) # # Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_' @@ -136,6 +137,10 @@ __sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$ define __run-and-store ifeq ($(origin $(1)),undefined) $$(eval $(1) := $$(shell $$(2))) +ifeq ($(create-cache-dir),1) + $$(shell mkdir -p $(dir $(make-cache))) + $$(eval create-cache-dir :=) +endif $$(shell echo '$(1) := $$($(1))' >> $(make-cache)) endif endef