linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kbuild: revert $(realpath ...) to $(shell cd ... && /bin/pwd)
@ 2017-10-02  8:07 Masahiro Yamada
  2017-10-02 11:27 ` Julien Grall
  0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2017-10-02  8:07 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Julien Grall, Masahiro Yamada, linux-pm, Michal Marek,
	David Carrillo-Cisneros, linux-kernel, Thomas Renninger,
	Josh Poimboeuf, Jiri Olsa, Arnaldo Carvalho de Melo

I thought commit 8e9b46679923 ("kbuild: use $(abspath ...) instead of
$(shell cd ... && /bin/pwd)") was a safe conversion, but it changed
the behavior.

$(abspath ...) / $(realpath ...) does not expand shell special
characters, such as '~'.

Here is a simple Makefile example:

  ---------------->8----------------
  $(info /bin/pwd: $(shell cd ~/; /bin/pwd))
  $(info abspath: $(abspath ~/))
  $(info realpath: $(realpath ~/))
  all:
          @:
  ---------------->8----------------

  $ make
  /bin/pwd: /home/masahiro
  abspath: /home/masahiro/workspace/~
  realpath:

This can be a real problem if 'make O=~/foo' is invoked from another
Makefile or primitive shell like dash.

This commit partially reverts 8e9b46679923.

Fixes: 8e9b46679923 ("kbuild: use $(abspath ...) instead of $(shell cd ... && /bin/pwd)")
Reported-by: Julien Grall <julien.grall@arm.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 Makefile                       | 4 ++--
 tools/power/cpupower/Makefile  | 2 +-
 tools/scripts/Makefile.include | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index cf007a3..1b48717 100644
--- a/Makefile
+++ b/Makefile
@@ -130,8 +130,8 @@ endif
 ifneq ($(KBUILD_OUTPUT),)
 # check that the output directory actually exists
 saved-output := $(KBUILD_OUTPUT)
-$(shell [ -d $(KBUILD_OUTPUT) ] || mkdir -p $(KBUILD_OUTPUT))
-KBUILD_OUTPUT := $(realpath $(KBUILD_OUTPUT))
+KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
+								&& /bin/pwd)
 $(if $(KBUILD_OUTPUT),, \
      $(error failed to create output directory "$(saved-output)"))
 
diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile
index 4c5a481..d6e1c02 100644
--- a/tools/power/cpupower/Makefile
+++ b/tools/power/cpupower/Makefile
@@ -26,7 +26,7 @@ endif
 
 ifneq ($(OUTPUT),)
 # check that the output directory actually exists
-OUTDIR := $(realpath $(OUTPUT))
+OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
 $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
 endif
 
diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
index 9dc8f07..1e8b611 100644
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -1,7 +1,7 @@
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-	ABSOLUTE_O := $(realpath $(O))
-	dummy := $(if $(ABSOLUTE_O),,$(error O=$(O) does not exist))
+	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+	ABSOLUTE_O := $(shell cd $(O) ; pwd)
 	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
@@ -12,7 +12,7 @@ endif
 
 # check that the output directory actually exists
 ifneq ($(OUTPUT),)
-OUTDIR := $(realpath $(OUTPUT))
+OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
 $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
 endif
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kbuild: revert $(realpath ...) to $(shell cd ... && /bin/pwd)
  2017-10-02  8:07 [PATCH] kbuild: revert $(realpath ...) to $(shell cd ... && /bin/pwd) Masahiro Yamada
@ 2017-10-02 11:27 ` Julien Grall
  2017-10-05 20:17   ` Masahiro Yamada
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Grall @ 2017-10-02 11:27 UTC (permalink / raw)
  To: Masahiro Yamada, linux-kbuild
  Cc: linux-pm, Michal Marek, David Carrillo-Cisneros, linux-kernel,
	Thomas Renninger, Josh Poimboeuf, Jiri Olsa,
	Arnaldo Carvalho de Melo

Hello,

On 02/10/17 09:07, Masahiro Yamada wrote:
> I thought commit 8e9b46679923 ("kbuild: use $(abspath ...) instead of
> $(shell cd ... && /bin/pwd)") was a safe conversion, but it changed
> the behavior.
> 
> $(abspath ...) / $(realpath ...) does not expand shell special
> characters, such as '~'.
> 
> Here is a simple Makefile example:
> 
>    ---------------->8----------------
>    $(info /bin/pwd: $(shell cd ~/; /bin/pwd))
>    $(info abspath: $(abspath ~/))
>    $(info realpath: $(realpath ~/))
>    all:
>            @:
>    ---------------->8----------------
> 
>    $ make
>    /bin/pwd: /home/masahiro
>    abspath: /home/masahiro/workspace/~
>    realpath:
> 
> This can be a real problem if 'make O=~/foo' is invoked from another
> Makefile or primitive shell like dash.
> 
> This commit partially reverts 8e9b46679923.
> 
> Fixes: 8e9b46679923 ("kbuild: use $(abspath ...) instead of $(shell cd ... && /bin/pwd)")
> Reported-by: Julien Grall <julien.grall@arm.com>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Tested-by: Julien Grall <julien.grall@arm.com>

Regards,

> ---
> 
>   Makefile                       | 4 ++--
>   tools/power/cpupower/Makefile  | 2 +-
>   tools/scripts/Makefile.include | 6 +++---
>   3 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index cf007a3..1b48717 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -130,8 +130,8 @@ endif
>   ifneq ($(KBUILD_OUTPUT),)
>   # check that the output directory actually exists
>   saved-output := $(KBUILD_OUTPUT)
> -$(shell [ -d $(KBUILD_OUTPUT) ] || mkdir -p $(KBUILD_OUTPUT))
> -KBUILD_OUTPUT := $(realpath $(KBUILD_OUTPUT))
> +KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
> +								&& /bin/pwd)
>   $(if $(KBUILD_OUTPUT),, \
>        $(error failed to create output directory "$(saved-output)"))
>   
> diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile
> index 4c5a481..d6e1c02 100644
> --- a/tools/power/cpupower/Makefile
> +++ b/tools/power/cpupower/Makefile
> @@ -26,7 +26,7 @@ endif
>   
>   ifneq ($(OUTPUT),)
>   # check that the output directory actually exists
> -OUTDIR := $(realpath $(OUTPUT))
> +OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
>   $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
>   endif
>   
> diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
> index 9dc8f07..1e8b611 100644
> --- a/tools/scripts/Makefile.include
> +++ b/tools/scripts/Makefile.include
> @@ -1,7 +1,7 @@
>   ifneq ($(O),)
>   ifeq ($(origin O), command line)
> -	ABSOLUTE_O := $(realpath $(O))
> -	dummy := $(if $(ABSOLUTE_O),,$(error O=$(O) does not exist))
> +	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
> +	ABSOLUTE_O := $(shell cd $(O) ; pwd)
>   	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
>   	COMMAND_O := O=$(ABSOLUTE_O)
>   ifeq ($(objtree),)
> @@ -12,7 +12,7 @@ endif
>   
>   # check that the output directory actually exists
>   ifneq ($(OUTPUT),)
> -OUTDIR := $(realpath $(OUTPUT))
> +OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
>   $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
>   endif
>   
> 

-- 
Julien Grall

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kbuild: revert $(realpath ...) to $(shell cd ... && /bin/pwd)
  2017-10-02 11:27 ` Julien Grall
@ 2017-10-05 20:17   ` Masahiro Yamada
  0 siblings, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2017-10-05 20:17 UTC (permalink / raw)
  To: Julien Grall
  Cc: Linux Kbuild mailing list, Linux PM mailing list, Michal Marek,
	David Carrillo-Cisneros, Linux Kernel Mailing List,
	Thomas Renninger, Josh Poimboeuf, Jiri Olsa,
	Arnaldo Carvalho de Melo

2017-10-02 20:27 GMT+09:00 Julien Grall <julien.grall@arm.com>:
> Hello,
>
> On 02/10/17 09:07, Masahiro Yamada wrote:
>>
>> I thought commit 8e9b46679923 ("kbuild: use $(abspath ...) instead of
>> $(shell cd ... && /bin/pwd)") was a safe conversion, but it changed
>> the behavior.
>>
>> $(abspath ...) / $(realpath ...) does not expand shell special
>> characters, such as '~'.
>>
>> Here is a simple Makefile example:
>>
>>    ---------------->8----------------
>>    $(info /bin/pwd: $(shell cd ~/; /bin/pwd))
>>    $(info abspath: $(abspath ~/))
>>    $(info realpath: $(realpath ~/))
>>    all:
>>            @:
>>    ---------------->8----------------
>>
>>    $ make
>>    /bin/pwd: /home/masahiro
>>    abspath: /home/masahiro/workspace/~
>>    realpath:
>>
>> This can be a real problem if 'make O=~/foo' is invoked from another
>> Makefile or primitive shell like dash.
>>
>> This commit partially reverts 8e9b46679923.
>>
>> Fixes: 8e9b46679923 ("kbuild: use $(abspath ...) instead of $(shell cd ...
>> && /bin/pwd)")
>> Reported-by: Julien Grall <julien.grall@arm.com>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>
>
> Tested-by: Julien Grall <julien.grall@arm.com>


Applied to linux-kbuild/fixes.


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-05 20:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-02  8:07 [PATCH] kbuild: revert $(realpath ...) to $(shell cd ... && /bin/pwd) Masahiro Yamada
2017-10-02 11:27 ` Julien Grall
2017-10-05 20:17   ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).