[bug #57914] abspath does resolve symlink

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #57914] abspath does resolve symlink

anonymous
Follow-up Comment #3, bug #57914 (project make):

Hi,

thanks so much for your quick reply and detailed explanation!

For my understanding I added:
  /tmp/57914/subdir -> .
and found correctly:
  make -f subdir/Makefile
  $(abspath subdir/Makefile) == /tmp/57914/subdir/Makefile
as well as my (non-)issue:
  make -C subdir
  make: Entering directory '/tmp/57914'
  $(abspath Makefile) == /tmp/57914/Makefile
  make: Leaving directory '/tmp/57914'

Did I understand correctly:
With saying after chdir its "physical" this means this is how the
OS/kernel/POSIX(?) sees it and thus make sees it, too?
So my shell has special features to "emulate" that it looks as if it would be
"logical"?

This confused me, because in cmake its exactly the other way around: it is not
possible (without recompilation of cmake) to use physical paths; they are
(almost) always logical. I now understand that cmake tries to mimic the shells
behavior (with more or less success). Probably this is required since cmake
does not support relative paths (like autoconf/automake do) but has everything
absolute, and to avoid breaking $HOME symlinking to "randomized" mountpoints.
What a pitty.

Could you please tell me if I understood correctly of, if possible, point me
to a place where I can read more, please?



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57914>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57914] abspath does resolve symlink

anonymous
Follow-up Comment #5, bug #57914 (project make):

I haven't seen half the mails relating to this bug, which might explain how it
lay unloved for so long.  I don't think I'm really adding anything to Boyski's
posts, which I hadn't seen (and they aren't in my "spam folder"), but here's a
demonstration that Make doesn't know what Bash thinks is the logical
directory:

{}
martind@paris:/tmp/rtc-400921-FILE-macro/logical$ strace -f make 2>&1 | grep
cwd
getcwd("/tmp/rtc-400921-FILE-macro/physical", 4096) = 36
getcwd("/tmp/rtc-400921-FILE-macro/physical", 4096) = 36
martind@paris:/tmp/rtc-400921-FILE-macro/logical$ strace /bin/pwd 2>&1 | grep
cwd
getcwd("/tmp/rtc-400921-FILE-macro/physical", 4096) = 36
martind@paris:/tmp/rtc-400921-FILE-macro/logical$
{}

Well, it could look at:

{}
martind@paris:/tmp/rtc-400921-FILE-macro/logical$ env | grep logical
PWD=/tmp/rtc-400921-FILE-macro/logical
martind@paris:/tmp/rtc-400921-FILE-macro/logical$
{}

... if it were willing to sacrifice potential portability or complexity.

Is bash doing the best thing it can?  Yes:

{}
martind@paris:/tmp/rtc-400921-FILE-macro$ strace -f bash -c 'cd logical' 2>&1
| grep chdir
chdir("/tmp/rtc-400921-FILE-macro/logical") = 0
martind@paris:/tmp/rtc-400921-FILE-macro$
{}

I didn't see the behavior mentioned in the Linux man page for chdir, though
there are mentions of ELOOP there, with extra detail at
https://pubs.opengroup.org/onlinepubs/009695399/functions/chdir.html, which
convinced me that it was chdir rather than getcwd that's following the link.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57914>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57914] abspath does resolve symlink

anonymous
Update of bug #57914 (project make):

                  Status:                    None => Not A Bug              
             Open/Closed:                    Open => Closed                

    _______________________________________________________

Follow-up Comment #6:

Just as another proof that it's a feature of the shell: if you don't use the
shell's built-in pwd command but instead use /bin/pwd, you'll see that just
like make (also not a built-in command in the shell :-)) it shows the physical
path:


$ mkdir /tmp/x1

$ ln -s /tmp/x1 foo

$ (cd foo && pwd)
/home/me/foo

$ (cd foo && /bin/pwd)
/tmp/x1


I don't know about cmake, but I can only assume that it's using the PWD
environment variable it inherited from the shell to determine the current
working directory, rather than asking the operating system like /bin/pwd (and
make) do.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57914>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57914] abspath does resolve symlink

anonymous
Follow-up Comment #7, bug #57914 (project make):

Thank you all for your explanations. I think I now understand it correctly :)


[comment #6 comment #6:]
> Just as another proof that it's a feature of the shell: if you don't use the
shell's built-in pwd command but instead use /bin/pwd, you'll see that just
like make (also not a built-in command in the shell :-)) it shows the physical
path:

This one I know (already met in practice).

According to the documentation, it is just a matter of defaults: "pwd" w/o
args defaults to "pwd -L", but "/bin/pwd" to "/bin/pwd -P", but that are just
defaults:


sdettmer@RefVm3:/tmp $ cd /tmp/
sdettmer@RefVm3:/tmp $ mkdir /tmp/x1
sdettmer@RefVm3:/tmp $ ln -s /tmp/x1 foo
sdettmer@RefVm3:/tmp $ (cd foo && pwd -L && pwd && pwd -P)
/tmp/foo
/tmp/foo
/tmp/x1
sdettmer@RefVm3:/tmp $ (cd foo && /bin/pwd -L && /bin/pwd && /bin/pwd -P)
/tmp/foo
/tmp/x1
/tmp/x1
sdettmer@RefVm3:/tmp $


At least my /bin/pwd (GNU coreutils 8.26) is using $PWD from environment:


sdettmer@RefVm3:/tmp $ man pwd|grep -1 -- -L

       -L, --logical
              use PWD from environment, even if it contains symlinks

sdettmer@RefVm3:/tmp $ (cd foo && /bin/pwd -L && PWD="" /bin/pwd -L )
/tmp/foo
/tmp/x1


I guess the different defaults are needed for complex compatibility issues.




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57914>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57914] abspath does resolve symlink

anonymous
Follow-up Comment #8, bug #57914 (project make):

Right... GNU make doesn't have any option to act like "pwd -L" does when it
manages paths.

The user could do that themselves in their makefile since they have access to
"$(PWD)".  Maybe not pretty, but something like this could work:


labspath = $(patsubst $(CURDIR)/%,$(PWD)/%,$(abspath $1))

$(info labspath = $(call labspath,$(dir)))


which puts back the "$(PWD)" prefix.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57914>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/