Opened 12 years ago
Closed 12 years ago
#10208 closed defect (fixed)
Remove "warning: Replacing library search directory..." if caused by symbolic links
Reported by:  John Palmieri  Owned by:  Georg S. Weber 

Priority:  minor  Milestone:  sage4.6.1 
Component:  build  Keywords:  LDSHARED symlink linker path 
Cc:  Leif Leonhardy  Merged in:  sage4.6.1.alpha1 
Authors:  John Palmieri  Reviewers:  Leif Leonhardy 
Report Upstream:  N/A  Work issues:  
Branch:  Commit:  
Dependencies:  Stopgaps: 
Description
This follows up on #9896.
If there are symbolic links pointing to SAGE_ROOT, then running "sage b" may cause a warning message like
warning: Replacing library search directory in linker command: "[actual SAGE_ROOT directory]/local/lib" > "[link]/local/lib"
It can be distracting having warning messages print when there is actually nothing wrong, so the attached patch removes this warning. The warning will of course still print if the Sage library has actually been moved.
Attachments (1)
Change History (10)
comment:1 Changed 12 years ago by
Cc:  Leif Leonhardy added 

Status:  new → needs_review 
comment:2 Changed 12 years ago by
comment:3 followup: 4 Changed 12 years ago by
Would perhaps look nicer ...
Okay, here's a new patch.
Regarding SAGE_ROOT: note that on my Mac, '/Applications/sage' is a link pointing to the real directory '/Applications/sage_builds/sage4.6/'.
sage: SAGE_ROOT '/Applications/sage'
From the command line:
$ sage sh Starting subshell with Sage environment variables set. Be sure to exit when you are done and do not do anything with other copies of Sage! Bypassing shell configuration files ... SAGE_ROOT=/Applications/sage
So SAGE_ROOT is not actually "fully dereferenced", if that means what I think it means. In case it doesn't mean what I think it means:
sage: os.path.realpath(SAGE_ROOT) == SAGE_ROOT False
So I think we need os.path.realpath in both places.
Unfortunately, on Darwin afaik os.path.realpath() does not necessarily return a unique name; perhaps this has meanwhile been fixed, but distutils still implement their own canonicalize_path() (or whatever it is called) for Darwin.
I don't know about this in general, but using os.path.realpath seems to fix this particular problem on my OS X machine.
comment:4 followup: 7 Changed 12 years ago by
Replying to jhpalmieri:
Regarding SAGE_ROOT: note that on my Mac, '/Applications/sage' is a link pointing to the real directory '/Applications/sage_builds/sage4.6/'. So SAGE_ROOT is not actually "fully dereferenced", if that means what I think it means.
sage: os.path.realpath(SAGE_ROOT) == SAGE_ROOT False
So I think we need os.path.realpath in both places.
Ok, then (at least your) MacOS X lacks the readlink
and realpath
commands, or you've set SAGE_ROOT
manually.
In general, I think it would be better to also assign os.path.realpath(...)
to the Python variables SAGE_ROOT
, SAGE_LOCAL
etc. at the top of setup.py
(line 32 ff.), which would also remove some redundant slashs.
Unfortunately, on Darwin afaik os.path.realpath() does not necessarily return a unique name; perhaps this has meanwhile been fixed, but distutils still implement their own canonicalize_path() (or whatever it is called) for Darwin.
I don't know about this in general, but using os.path.realpath seems to fix this particular problem on my OS X machine.
Me either. Perhaps just history (when distutils were not part of the Python distribution), otherwise wouldn't make much sense to have distutils use their own version, leaving the standard Python function limited.
comment:5 Changed 12 years ago by
Keywords:  LDSHARED symlink linker path added 

Reviewers:  → Leif Leonhardy 
Status:  needs_review → positive_review 
Ok, works as advertised. (I've only tested it on Linux by setting LDSHARED
.)
comment:6 Changed 12 years ago by
Hmmm, I just noticed if the paths are equivalent the "given" path doesn't get normalized, i.e. redundant slashs and ..././
etc. removed, so in the messages still the unnormalized rather than the effective path appears.
But that's an even minor issue.
comment:7 followup: 8 Changed 12 years ago by
Replying to leif:
Ok, then (at least your) MacOS X lacks the
readlink
andrealpath
commands, or you've setSAGE_ROOT
manually.
I think that SAGE_ROOT is set in the script sageenv, by running "pwd" in an appropriate directory. Perhaps with the GNU version of this, it resolves all links. On Darwin, and it seems perhaps also on Solaris, you need to run "pwd P" to do this. On sage.math, 'pwd P' also resolves links. So we might also consider something like this change to sageenv:

sageenv
diff r 4047e578febc sageenv
a b 23 23 ########################################################################## 24 24 25 25 # GUESS SAGE_ROOT from pwd 26 SAVEDIR="`pwd`" 26 PWD="pwd P" 27 SAVEDIR="`$PWD`" 27 28 if [ f sage a d spkg ]; then 28 GUESSED_SAGE_ROOT="` pwd`"29 GUESSED_SAGE_ROOT="`$PWD`" 29 30 else 30 31 if [ f ../../sage a d ../../spkg ]; then 31 32 cd ../../ 32 GUESSED_SAGE_ROOT="` pwd`"33 GUESSED_SAGE_ROOT="`$PWD`" 33 34 else 34 35 GUESSED_SAGE_ROOT="" 35 36 fi 36 37 fi 37 38 cd "$SAVEDIR" 38 39 39 40 40 if [ "$SAGE_ROOT" = "" ]; then 41 41 if [ "$GUESSED_SAGE_ROOT" = "" ]; then 42 42 echo "Error: You must set the SAGE_ROOT environment"
(On the other hand, I don't understand why on sage.math, running 'pwd' from the command line in /scratch/palmieri/sage gives me "/scratch/palmieri/sage", while running it from sageenv gives me "/mnt/usb1/scratch/palmieri/sage4.6".)
comment:8 Changed 12 years ago by
Replying to jhpalmieri:
Replying to leif:
Ok, then (at least your) MacOS X lacks the
readlink
andrealpath
commands, or you've setSAGE_ROOT
manually.I think that SAGE_ROOT is set in the script sageenv, by running "pwd" in an appropriate directory.
But only if SAGE_ROOT
is not already set, which isn't the case if you run some ./sage ...
command, so it's a bit inconsistent.
Oh, but I see: $SAGE_ROOT/sage
does not use readlink e
(which dereferences any symlink contained in its argument); without that, it returns an error if the last component is not a link. So if you have just links "in the middle", sage
uses the basename of itself.
Perhaps with the GNU version of this, it resolves all links. On Darwin, and it seems perhaps also on Solaris, you need to run "pwd P" to do this. On sage.math, 'pwd P' also resolves links. So we might also consider something like this change to sageenv...
I wonder what new strange sideeffects that would have... ;)
(On the other hand, I don't understand why on sage.math, running 'pwd' from the command line in /scratch/palmieri/sage gives me "/scratch/palmieri/sage", while running it from sageenv gives me "/mnt/usb1/scratch/palmieri/sage4.6".)
That depends on how you cd
to a directory, or how a script is called. Which directory do you have in your path?
$0
should be set according to that inside a script, i.e. its basename should be the one where it was (first) found in your $PATH
(i.e. even relative if you happen to have ".
" in your path and the script is in the current directory).
comment:9 Changed 12 years ago by
Merged in:  → sage4.6.1.alpha1 

Resolution:  → fixed 
Status:  positive_review → closed 
Would perhaps look nicer (in the code) if you just replaced the two occurrences of
os.path.normpath()
byos.path.realpath()
, but I'm ok with your solution, since it does preserve more of the "given" directory names.os.path.normpath(SAGE_LOCAL+"/lib")
should already be a fully dereferenced path (becauseSAGE_ROOT
is), so you could omit the change intoos.path.realpath(sage_libdir)
.The warning will only show up on MacOS X anyway.
Unfortunately, on Darwin afaik
os.path.realpath()
does not necessarily return a unique name; perhaps this has meanwhile been fixed, but distutils still implement their owncanonicalize_path()
(or whatever it is called) for Darwin.