#5852: The detection of SAGE_ROOT in $SAGE_ROOT/sage script should expand 
symlinks
recursively
-----------------------------+----------------------------------------------
    Reporter:  tornaria      |         Owner:  tornaria  
        Type:  defect        |        Status:  needs_work
    Priority:  major         |     Milestone:  sage-4.7.2
   Component:  distribution  |    Resolution:            
    Keywords:                |   Work_issues:            
    Upstream:  N/A           |      Reviewer:            
      Author:                |        Merged:            
Dependencies:                |  
-----------------------------+----------------------------------------------
Description changed by jdemeyer:

Old description:

> Currently, {{{$SAGE_ROOT/sage}}} uses (first among other alternate
> methods) {{{readlink -n}}} to detect the directory where the script lives
> (that's $SAGE_ROOT), but it should use {{{readlink -nf}}} to expand
> symlinks recursively.
>
> Otherwise, the symlink expansion may not be completely done, and
> {{{$SAGE_ROOT}}} could end up with a non-canonical dirname, which leads
> to issues with testing.
>
> Here's a way to reproduce an issue with the current script. For the
> example, my sage-3.4 installation lives in {{{/home/sage/sage-3.4}}}, and
> here's what happened to me:
> {{{
> /home/sage$ md5sum sage-3.4/sage
> 4153919efe1edcd34ad7fa193122d679  sage-3.4/sage
> /home/sage$ ln -s sage-3.4 sage-3.4-symlink
> /home/sage$ ln -sf /home/sage/sage-3.4-symlink/sage
> /home/tornaria/bin/sage
> /home/sage$ type sage
> sage is hashed (/home/tornaria/bin/sage)
> /home/sage$ readlink `type -p sage`
> /home/sage/sage-3.4-symlink/sage
> /home/sage$ readlink -f `type -p sage`
> /home/sage/sage-3.4/sage
> }}}
>
> As you can see, {{{readlink -n}}} expands once but doesn't cannonicalize
> the path to the {{{sage}}} script. And here's the symptom:
> {{{
> /home/sage$ sage -t sage-3.4/devel/sage-main/sage/all.py
> sage -t  "sage-3.4/devel/sage-main/sage/all.py"
>   File "./all.py", line 18
>     from sage-3.4/devel/sage-main/sage/all import *
>              ^
> SyntaxError: invalid syntax
>
>          [0.3 s]
> exit code: 1024
>
> ----------------------------------------------------------------------
> The following tests failed:
>

>         sage -t  "sage-3.4/devel/sage-main/sage/all.py"
> Total time for all tests: 0.3 seconds
> }}}
>
> Note that we should do this in a portable way, without using `realpath`,
> `readlink -f` or the likes.  See either #6146 or #11707 for a script
> which could be used for this.

New description:

 Currently, {{{$SAGE_ROOT/sage}}} uses (first among other alternate
 methods) {{{readlink -n}}} to detect the directory where the script lives
 (that's $SAGE_ROOT), but that is broken because
  - It only works when `$0` (the sage executable itself) is a symbolic link
  - If the sage executable is a symbolic link, then `readlink -n` returns
 the link itself, not the canonicalized name.  Example: if
 `/usr/local/sage-4.7.1/sage` is a symbolic link to `sagefoo`, then
 `SAGE_ROOT` would become `sagefoo` when `'/usr/local/sage-4.7.1/sagefoo`
 is intended.
  - The symlink expansion may not be completely done, and {{{$SAGE_ROOT}}}
 could end up with a non-canonical dirname, which leads to issues with
 testing.

 Here's a way to reproduce an issue with the current script. For the
 example, my sage-3.4 installation lives in {{{/home/sage/sage-3.4}}}, and
 here's what happened to me:
 {{{
 /home/sage$ md5sum sage-3.4/sage
 4153919efe1edcd34ad7fa193122d679  sage-3.4/sage
 /home/sage$ ln -s sage-3.4 sage-3.4-symlink
 /home/sage$ ln -sf /home/sage/sage-3.4-symlink/sage
 /home/tornaria/bin/sage
 /home/sage$ type sage
 sage is hashed (/home/tornaria/bin/sage)
 /home/sage$ readlink `type -p sage`
 /home/sage/sage-3.4-symlink/sage
 /home/sage$ readlink -f `type -p sage`
 /home/sage/sage-3.4/sage
 }}}

 As you can see, {{{readlink -n}}} expands once but doesn't cannonicalize
 the path to the {{{sage}}} script. And here's the symptom:
 {{{
 /home/sage$ sage -t sage-3.4/devel/sage-main/sage/all.py
 sage -t  "sage-3.4/devel/sage-main/sage/all.py"
   File "./all.py", line 18
     from sage-3.4/devel/sage-main/sage/all import *
              ^
 SyntaxError: invalid syntax

          [0.3 s]
 exit code: 1024

 ----------------------------------------------------------------------
 The following tests failed:


         sage -t  "sage-3.4/devel/sage-main/sage/all.py"
 Total time for all tests: 0.3 seconds
 }}}

 Note that we should do this in a portable way, without using `realpath`,
 `readlink -f` or the likes.  See attachments for two bash scripts to solve
 this problem (either of them should suffice).

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5852#comment:17>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to