Message ID | 20231214140305.531963-1-masahiroy@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8565380dys; Thu, 14 Dec 2023 06:03:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSu2XsDPPEzalLboI6PYz7O/zMj+/V8ifd8VRyTUdPvvi0b/rC+786KNgmMnGfuZ4Umf1O X-Received: by 2002:a17:90a:5d93:b0:286:9ff9:ab9a with SMTP id t19-20020a17090a5d9300b002869ff9ab9amr4318419pji.66.1702562606956; Thu, 14 Dec 2023 06:03:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702562606; cv=none; d=google.com; s=arc-20160816; b=HugzicuieBzBBzFL3ZTnup4/C1bJKtkruS4epaIN2q2I1CQTvG6gawF+ue2E4wM5pk 64ehKI3oZb7mUwGR+HMBpXAQXukdLC4o2iYPnWmN3pi0yHp+Xs2pveCTvOd8jd4CHAp3 V0ye5oK0/uowDYpCBHt5/jLOFNWiRZPVl61DVASKpfIuAPCHX6Yc5IlWwG9DdGD2YdE+ 9SIjsRaxTSPRzo7/e2339/R0zv153GqSdKry+RT4yRlh5N0AutSVSq8Yk8m7SyqWTTqO vOxqhzOjela7zMpaaMWznJGOGPJRDt3Tn2J0nd1EfL8FLawwE54XmU21cBf0J/ldWxl+ RasQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oFd79qEd0UAO1BLVZ2cMNnnm9cm7ED+CNa1rqbDmPg0=; fh=PFwXawrH1uMeasvl/p3z1jdQgSTgo4FZ0xmHmWTcQfM=; b=hbEMp9/J3kRzjQ1XCaZImwaXmNXvuAaHxjjcPfkFzIa6ijIXUjeCKJYz1I9+sAb/p7 C0jDGJEgbWtPgHngL++NQFgr5pH/Ys2uR8i2HisyI60eigmp5YpYTP8CkKD15dAAXHGk 48I9+ekSzT5/6tnJjsrcaF6vezfAqOpJcnPa3f2Bx4mn3Gaw6Mrj8UYqcbxenLpgZ16u 6ECF8W2Ktj9LvwmJNXo4AhoEiHrih+T+LmlbThFBQ6TOiGCW5I5lOomEg+Mon92NWXk7 Sk942yggt4LceyLlaChUfHKVmHo3GHsaVQAjs9aCOJQAcAui4kVyTt+5ipjycLKXovuB H1YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FSGR75HF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id nv7-20020a17090b1b4700b0028aedf48a6fsi2317303pjb.174.2023.12.14.06.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 06:03:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FSGR75HF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id ACC0A80A5F8E; Thu, 14 Dec 2023 06:03:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573363AbjLNODM (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Thu, 14 Dec 2023 09:03:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573115AbjLNODL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 14 Dec 2023 09:03:11 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBBDA9C for <linux-kernel@vger.kernel.org>; Thu, 14 Dec 2023 06:03:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48648C433C8; Thu, 14 Dec 2023 14:03:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702562597; bh=TmBlvdhMtwd+CkVq89ydLq0CdC3DZHSb/94YMt+8cx8=; h=From:To:Cc:Subject:Date:From; b=FSGR75HF8Uib5Aw6ixmy6n88N7GAR4E0yWRjocRCwxIpVzJaSaIQUU24OgU7gXugw DYdvOUH8LXwIfLoBZTvuj8yTMzr1M3jaLmRBDv3L79Znt910VQSZKYxMOaFvde9ztA MFRAUbzY2VQNgIOjQqe/jAoSuu9JR+Ls4tNhQihAUcZDxFjgp50X7bAjObi+HpbpF+ PHDPksngqGzcZj/Qkd7Zd0+9NKqSqvsXuyLA0Pwmr5Ch9zHdRt8PAcPhh+F4um32eZ wq1TNJHTpfOOpCpQsSWDH2bWg+l7x4Hl7O6Ws6kjjC0E4zCRRraKkWYNlDMl95r3g4 DwAjT8rMNmKJg== From: Masahiro Yamada <masahiroy@kernel.org> To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada <masahiroy@kernel.org>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Nicolas Schier <nicolas@fjasle.eu>, linux-kernel@vger.kernel.org Subject: [PATCH] kbuild: resolve symlinks for O= properly Date: Thu, 14 Dec 2023 23:03:05 +0900 Message-Id: <20231214140305.531963-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Dec 2023 06:03:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785266288269934061 X-GMAIL-MSGID: 1785266288269934061 |
Series |
kbuild: resolve symlinks for O= properly
|
|
Commit Message
Masahiro Yamada
Dec. 14, 2023, 2:03 p.m. UTC
Currently, Kbuild follows the logical chain of directories for the O=
option, just like 'cd' (or 'realpath --logical') does.
Example:
$ mkdir -p /tmp/a /tmp/x/y
$ ln -s /tmp/x/y /tmp/a/b
$ realpath /tmp/a/b/..
/tmp/x
$ realpath --logical /tmp/a/b/..
/tmp/a
$ make O=/tmp/a/b/.. defconfig
make[1]: Entering directory '/tmp/a'
[snip]
make[1]: Leaving directory '/tmp/a'
'make O=/tmp/a/b/.. defconfig' creates the kernel configuration in
/tmp/a instead of /tmp/x despite the directory path /tmp/a/b/..
resolves to the physical directory path /tmp/x.
This is because Kbuild internally uses the 'cd ... && pwd' for the
path resolution, but this behavior is not predictable for users.
Additionally, it is not consistent with how the Kbuild handles the
M= option or GNU Make works with 'make -C /tmp/a/b/..'.
Using the physical directory structure for the O= option seems more
reasonable.
The comment says "expand a shell special character '~'", but it has
already been expanded to the home directory in the command line.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
Makefile | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
Comments
On Thu, Dec 14, 2023 at 11:03:05PM +0900, Masahiro Yamada wrote: > Currently, Kbuild follows the logical chain of directories for the O= > option, just like 'cd' (or 'realpath --logical') does. > > Example: > > $ mkdir -p /tmp/a /tmp/x/y > $ ln -s /tmp/x/y /tmp/a/b > $ realpath /tmp/a/b/.. > /tmp/x > $ realpath --logical /tmp/a/b/.. > /tmp/a > $ make O=/tmp/a/b/.. defconfig > make[1]: Entering directory '/tmp/a' > [snip] > make[1]: Leaving directory '/tmp/a' > > 'make O=/tmp/a/b/.. defconfig' creates the kernel configuration in > /tmp/a instead of /tmp/x despite the directory path /tmp/a/b/.. > resolves to the physical directory path /tmp/x. > > This is because Kbuild internally uses the 'cd ... && pwd' for the > path resolution, but this behavior is not predictable for users. > Additionally, it is not consistent with how the Kbuild handles the > M= option or GNU Make works with 'make -C /tmp/a/b/..'. > > Using the physical directory structure for the O= option seems more > reasonable. > > The comment says "expand a shell special character '~'", but it has > already been expanded to the home directory in the command line. I minor change in behaviour is that 'make O="~/..."' (=quoted '~) will not work any more. But I think this actually the way it should be. Thanks! Reviewed-by: Nicolas Schier <n.schier@avm.de> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > --- > > Makefile | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/Makefile b/Makefile > index 24fac1889997..a05f0f7c99e0 100644 > --- a/Makefile > +++ b/Makefile > @@ -190,14 +190,11 @@ ifeq ("$(origin O)", "command line") > endif > > ifneq ($(KBUILD_OUTPUT),) > -# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot > -# expand a shell special character '~'. We use a somewhat tedious way here. > -abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) > -$(if $(abs_objtree),, \ > - $(error failed to create output directory "$(KBUILD_OUTPUT)")) > - > +# $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. > +$(shell mkdir -p $(KBUILD_OUTPUT)) > # $(realpath ...) resolves symlinks > -abs_objtree := $(realpath $(abs_objtree)) > +abs_objtree := $(realpath $(KBUILD_OUTPUT)) > +$(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) > endif # ifneq ($(KBUILD_OUTPUT),) > > ifneq ($(words $(subst :, ,$(abs_srctree))), 1) > -- > 2.40.1 >
On Fri, Dec 15, 2023 at 6:29 PM Nicolas Schier <n.schier@avm.de> wrote: > > On Thu, Dec 14, 2023 at 11:03:05PM +0900, Masahiro Yamada wrote: > > Currently, Kbuild follows the logical chain of directories for the O= > > option, just like 'cd' (or 'realpath --logical') does. > > > > Example: > > > > $ mkdir -p /tmp/a /tmp/x/y > > $ ln -s /tmp/x/y /tmp/a/b > > $ realpath /tmp/a/b/.. > > /tmp/x > > $ realpath --logical /tmp/a/b/.. > > /tmp/a > > $ make O=/tmp/a/b/.. defconfig > > make[1]: Entering directory '/tmp/a' > > [snip] > > make[1]: Leaving directory '/tmp/a' > > > > 'make O=/tmp/a/b/.. defconfig' creates the kernel configuration in > > /tmp/a instead of /tmp/x despite the directory path /tmp/a/b/.. > > resolves to the physical directory path /tmp/x. > > > > This is because Kbuild internally uses the 'cd ... && pwd' for the > > path resolution, but this behavior is not predictable for users. > > Additionally, it is not consistent with how the Kbuild handles the > > M= option or GNU Make works with 'make -C /tmp/a/b/..'. > > > > Using the physical directory structure for the O= option seems more > > reasonable. > > > > The comment says "expand a shell special character '~'", but it has > > already been expanded to the home directory in the command line. > > I minor change in behaviour is that 'make O="~/..."' (=quoted '~) will > not work any more. But I think this actually the way it should be. > Thanks! A good catch. This bug should be fixed by quoting $(KBUILD_OUTPUT). -$(shell mkdir -p $(KBUILD_OUTPUT)) +$(shell mkdir -p "$(KBUILD_OUTPUT)") When ~ is quoted, it loses a special meaning. masahiro@zoe:~$ echo ~ /home/masahiro masahiro@zoe:~$ echo "~" ~ So, the right behaviour of 'make O="~/foo"' is to create "~/foo" under the current directory. If you try to test it, please be careful to not delete your home directory. (I did "rm -r ./~" just in case) > Reviewed-by: Nicolas Schier <n.schier@avm.de> > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > --- > > > > Makefile | 11 ++++------- > > 1 file changed, 4 insertions(+), 7 deletions(-) > > > > diff --git a/Makefile b/Makefile > > index 24fac1889997..a05f0f7c99e0 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -190,14 +190,11 @@ ifeq ("$(origin O)", "command line") > > endif > > > > ifneq ($(KBUILD_OUTPUT),) > > -# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot > > -# expand a shell special character '~'. We use a somewhat tedious way here. > > -abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) > > -$(if $(abs_objtree),, \ > > - $(error failed to create output directory "$(KBUILD_OUTPUT)")) > > - > > +# $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. > > +$(shell mkdir -p $(KBUILD_OUTPUT)) > > # $(realpath ...) resolves symlinks > > -abs_objtree := $(realpath $(abs_objtree)) > > +abs_objtree := $(realpath $(KBUILD_OUTPUT)) > > +$(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) > > endif # ifneq ($(KBUILD_OUTPUT),) > > > > ifneq ($(words $(subst :, ,$(abs_srctree))), 1) > > -- > > 2.40.1 > >
diff --git a/Makefile b/Makefile index 24fac1889997..a05f0f7c99e0 100644 --- a/Makefile +++ b/Makefile @@ -190,14 +190,11 @@ ifeq ("$(origin O)", "command line") endif ifneq ($(KBUILD_OUTPUT),) -# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot -# expand a shell special character '~'. We use a somewhat tedious way here. -abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) -$(if $(abs_objtree),, \ - $(error failed to create output directory "$(KBUILD_OUTPUT)")) - +# $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. +$(shell mkdir -p $(KBUILD_OUTPUT)) # $(realpath ...) resolves symlinks -abs_objtree := $(realpath $(abs_objtree)) +abs_objtree := $(realpath $(KBUILD_OUTPUT)) +$(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) endif # ifneq ($(KBUILD_OUTPUT),) ifneq ($(words $(subst :, ,$(abs_srctree))), 1)