zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _make: target: handle "make -C dir"
@ 2019-08-22  6:37 Daniel Hahler
  2019-08-23  4:48 ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Hahler @ 2019-08-22  6:37 UTC (permalink / raw)
  To: zsh-workers

From: Daniel Hahler <git@thequod.de>

_make-findBasedir handles any "-C" arguments to find the basedir, but
with `zstyle -t :completion::complete:make::targets call-command true`
it would then not use it.

This is necessary however to get the correct list of targets, which
might be generated based on files from there.

`$basedir` defaults to `$PWD`, so it is ok to pass it always (I assume).
---
 Completion/Unix/Command/_make | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
index e23906373..38d0b0e76 100644
--- a/Completion/Unix/Command/_make
+++ b/Completion/Unix/Command/_make
@@ -236,13 +236,13 @@ _make() {
 
     (target)
     file=${(v)opt_args[(I)(-f|--file|--makefile)]}
+    local basedir
+    basedir=${$(_make-findBasedir $words)}
     if [[ -n $file ]]
     then
-      [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file
+      [[ $file == [^/]* ]] && file=$basedir/$file
       [[ -r $file ]] || file=
     else
-      local basedir
-      basedir=${$(_make-findBasedir $words)}
       if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]]
       then
         file=$basedir/GNUmakefile
@@ -259,10 +259,10 @@ _make() {
 
     if [[ -n "$file" ]]
     then
-      if [[ $is_gnu == gnu ]] 
+      if [[ $is_gnu == gnu ]]
       then
         if zstyle -t ":completion:${curcontext}:targets" call-command; then
-          _make-parseMakefile < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)
+          _make-parseMakefile < <(_call_program targets "$words[1]" -C $basedir -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)
         else
           _make-parseMakefile < $file
         fi
-- 
2.23.0


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

* Re: [PATCH] _make: target: handle "make -C dir"
  2019-08-22  6:37 [PATCH] _make: target: handle "make -C dir" Daniel Hahler
@ 2019-08-23  4:48 ` Daniel Shahaf
  2019-08-23 10:40   ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2019-08-23  4:48 UTC (permalink / raw)
  To: Daniel Hahler; +Cc: zsh-workers

Daniel Hahler wrote on Thu, Aug 22, 2019 at 08:37:53 +0200:
> `$basedir` defaults to `$PWD`, so it is ok to pass it always (I assume).

If the current working directory has been deleted, «$PWD» and «./» may refer to
different directories.

> -          _make-parseMakefile < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)
> +          _make-parseMakefile < <(_call_program targets "$words[1]" -C $basedir -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)

Should be «${(q)basedir}», I presume?

Preexisting issue: the other two parameter expansions should probably
use the «${(q)}» syntax too.

Preexisting issue: the last line of _make-findBasedir should use «print
-r», or better yet, assign to REPLY.

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

* Re: [PATCH] _make: target: handle "make -C dir"
  2019-08-23  4:48 ` Daniel Shahaf
@ 2019-08-23 10:40   ` Mikael Magnusson
  2019-08-24 16:41     ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2019-08-23 10:40 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Daniel Hahler, zsh-workers

On 8/23/19, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Daniel Hahler wrote on Thu, Aug 22, 2019 at 08:37:53 +0200:
>> `$basedir` defaults to `$PWD`, so it is ok to pass it always (I assume).
>
> If the current working directory has been deleted, «$PWD» and «./» may refer
> to different directories.

I think you won't have much success running make in a deleted directory.

-- 
Mikael Magnusson

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

* Re: [PATCH] _make: target: handle "make -C dir"
  2019-08-23 10:40   ` Mikael Magnusson
@ 2019-08-24 16:41     ` Daniel Shahaf
  2019-08-24 18:49       ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2019-08-24 16:41 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Daniel Hahler, zsh-workers

Mikael Magnusson wrote on Fri, 23 Aug 2019 10:40 +00:00:
> On 8/23/19, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > Daniel Hahler wrote on Thu, Aug 22, 2019 at 08:37:53 +0200:
> >> `$basedir` defaults to `$PWD`, so it is ok to pass it always (I assume).
> >
> > If the current working directory has been deleted, «$PWD» and «./» may refer
> > to different directories.
> 
> I think you won't have much success running make in a deleted directory.

I would, if it's been recreated:

[[[
% cd "$(mktemp -d)"
% rm -rf $PWD
% mkdir $PWD
% printf 'all:\n\ttrue\n' > $PWD/Makefile
% make -C $PWD
make: getcwd: No such file or directory
make: Entering directory '/tmp/tmp.ko7oZrXDP2'
true
make: Leaving directory '/tmp/tmp.ko7oZrXDP2'
% echo $?
0
% 
]]]

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

* Re: [PATCH] _make: target: handle "make -C dir"
  2019-08-24 16:41     ` Daniel Shahaf
@ 2019-08-24 18:49       ` Mikael Magnusson
  0 siblings, 0 replies; 5+ messages in thread
From: Mikael Magnusson @ 2019-08-24 18:49 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Daniel Hahler, zsh-workers

On 8/24/19, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Mikael Magnusson wrote on Fri, 23 Aug 2019 10:40 +00:00:
>> On 8/23/19, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>> > Daniel Hahler wrote on Thu, Aug 22, 2019 at 08:37:53 +0200:
>> >> `$basedir` defaults to `$PWD`, so it is ok to pass it always (I
>> >> assume).
>> >
>> > If the current working directory has been deleted, «$PWD» and «./» may
>> > refer
>> > to different directories.
>>
>> I think you won't have much success running make in a deleted directory.
>
> I would, if it's been recreated:
>
> [[[
> % cd "$(mktemp -d)"
> % rm -rf $PWD
> % mkdir $PWD
> % printf 'all:\n\ttrue\n' > $PWD/Makefile
> % make -C $PWD
> make: getcwd: No such file or directory
> make: Entering directory '/tmp/tmp.ko7oZrXDP2'
> true
> make: Leaving directory '/tmp/tmp.ko7oZrXDP2'
> % echo $?
> 0
> %
> ]]]

I think we can safely ignore this workflow.

-- 
Mikael Magnusson

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

end of thread, other threads:[~2019-08-24 18:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22  6:37 [PATCH] _make: target: handle "make -C dir" Daniel Hahler
2019-08-23  4:48 ` Daniel Shahaf
2019-08-23 10:40   ` Mikael Magnusson
2019-08-24 16:41     ` Daniel Shahaf
2019-08-24 18:49       ` Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).