Ticket #10208 (closed defect: fixed)
Remove "warning: Replacing library search directory..." if caused by symbolic links
| Reported by: | jhpalmieri | Owned by: | GeorgSWeber |
|---|---|---|---|
| Priority: | minor | Milestone: | sage-4.6.1 |
| Component: | build | Keywords: | LDSHARED symlink linker path |
| Cc: | leif | Work issues: | |
| Report Upstream: | N/A | Reviewers: | Leif Leonhardy |
| Authors: | John Palmieri | Merged in: | sage-4.6.1.alpha1 |
| 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
Change History
comment:2 Changed 3 years ago by leif
Would perhaps look nicer (in the code) if you just replaced the two occurrences of os.path.normpath() by os.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 (because SAGE_ROOT is), so you could omit the change into os.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 own canonicalize_path() (or whatever it is called) for Darwin.
comment:3 follow-up: ↓ 4 Changed 3 years ago by jhpalmieri
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/sage-4.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 in reply to: ↑ 3 ; follow-up: ↓ 7 Changed 3 years ago by leif
Replying to jhpalmieri:
Regarding SAGE_ROOT: note that on my Mac, '/Applications/sage' is a link pointing to the real directory '/Applications/sage_builds/sage-4.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 3 years ago by leif
- Keywords LDSHARED symlink linker path added
- Reviewers set to Leif Leonhardy
- Status changed from needs_review to positive_review
Ok, works as advertised. (I've only tested it on Linux by setting LDSHARED.)
comment:6 Changed 3 years ago by leif
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 in reply to: ↑ 4 ; follow-up: ↓ 8 Changed 3 years ago by jhpalmieri
Replying to leif:
Ok, then (at least your) MacOS X lacks the readlink and realpath commands, or you've set SAGE_ROOT manually.
I think that SAGE_ROOT is set in the script sage-env, 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 sage-env:
-
sage-env
diff -r 4047e578febc sage-env
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 sage-env gives me "/mnt/usb1/scratch/palmieri/sage-4.6".)
comment:8 in reply to: ↑ 7 Changed 3 years ago by leif
Replying to jhpalmieri:
Replying to leif:
Ok, then (at least your) MacOS X lacks the readlink and realpath commands, or you've set SAGE_ROOT manually.
I think that SAGE_ROOT is set in the script sage-env, 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 sage-env...
I wonder what new strange side-effects 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 sage-env gives me "/mnt/usb1/scratch/palmieri/sage-4.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).

