Ticket #10208 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

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

trac_10208-realpath.patch Download (1.1 KB) - added by jhpalmieri 3 years ago.
(sage library patch)

Change History

comment:1 Changed 3 years ago by jhpalmieri

  • Cc leif added
  • Status changed from new to needs_review

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.

Changed 3 years ago by jhpalmieri

(sage library patch)

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  
    2323########################################################################## 
    2424 
    2525# GUESS SAGE_ROOT from pwd 
    26 SAVEDIR="`pwd`" 
     26PWD="pwd -P" 
     27SAVEDIR="`$PWD`" 
    2728if [ -f sage -a -d spkg ]; then 
    28     GUESSED_SAGE_ROOT="`pwd`" 
     29    GUESSED_SAGE_ROOT="`$PWD`" 
    2930else  
    3031    if [ -f ../../sage -a -d ../../spkg ]; then 
    3132        cd ../../ 
    32         GUESSED_SAGE_ROOT="`pwd`" 
     33        GUESSED_SAGE_ROOT="`$PWD`" 
    3334    else 
    3435        GUESSED_SAGE_ROOT="" 
    3536    fi 
    3637fi 
    3738cd "$SAVEDIR" 
    3839 
    39  
    4040if [ "$SAGE_ROOT" = "" ]; then 
    4141    if [ "$GUESSED_SAGE_ROOT" = "" ]; then 
    4242        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).

comment:9 Changed 3 years ago by jdemeyer

  • Status changed from positive_review to closed
  • Resolution set to fixed
  • Merged in set to sage-4.6.1.alpha1
Note: See TracTickets for help on using tickets.