Ticket #12076: trac_12076-2.patch

File trac_12076-2.patch, 3.1 KB (added by mhansen, 10 years ago)
  • sage-location

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1338165537 25200
    # Node ID 9cd01500e12ac60d5aee84024261b200d0fa7108
    # Parent  f4bd71653d744b4c50aaef23dac647088bc932d0
    #12076: detect the old Sage root before updating the pkgconfig files
    
    diff --git a/sage-location b/sage-location
    a b  
    171171    PKG = os.path.join(LIB, 'pkgconfig')   
    172172    for name in os.listdir(PKG):
    173173        filename = os.path.join(PKG, name)
    174         initialize_pkgconfig_file(filename)
     174        initialize_pkgconfig_file(filename, SAGE_ROOT_absolute)
    175175       
    176 def initialize_pkgconfig_file(filename):
     176def initialize_pkgconfig_file(filename, SAGE_ROOT_absolute=None,
     177                              OLD_SAGE_ROOT_absolute=None):
    177178    """
    178179    Insert a ``SAGE_ROOT`` variable into ``filename`` and replace
    179180    occurrences of its current value by references to it (``${SAGE_ROOT}``).
    180181    """
    181     SAGE_ROOT_absolute = os.path.abspath(SAGE_ROOT)
     182    if SAGE_ROOT_absolute is None:
     183        SAGE_ROOT_absolute = os.path.abspath(SAGE_ROOT)
     184    if OLD_SAGE_ROOT_absolute is None:
     185        OLD_SAGE_ROOT_absolute = SAGE_ROOT_absolute
    182186    import re
    183187    # Pattern matching a *definition* of SAGE_ROOT:
    184188    def_pat = re.compile(r"^SAGE_ROOT=.*\n", re.MULTILINE)
     
    212216
    213217        # Replace all occurrences of the (current) value of SAGE_ROOT
    214218        # by references to the pkg-config variable SAGE_ROOT:
    215         config = config.replace(SAGE_ROOT_absolute, "${SAGE_ROOT}")
     219        config = config.replace(OLD_SAGE_ROOT_absolute, "${SAGE_ROOT}")
    216220        # Alternate implementation, *may* be faster:
    217221        # config = use_pat.sub("${SAGE_ROOT}", config)
    218222
     
    236240    # Pattern matching a *definition* of SAGE_ROOT:
    237241    def_pat = re.compile(r"^SAGE_ROOT=.*\n", re.MULTILINE)
    238242
     243    #Find the old SAGE_ROOT to use for uninitialized pkgconfig files
     244    for name in os.listdir(PKG):
     245        matches = re.findall(r"^SAGE_ROOT=(.*)\n",
     246                             open(os.path.join(PKG, name)).read())
     247        if matches:
     248            OLD_SAGE_ROOT = matches[0]
     249            break
     250    else:
     251        OLD_SAGE_ROOT = None
     252
    239253    for name in os.listdir(PKG):
    240254        filename = os.path.join(PKG, name)
    241255        if os.path.splitext(filename)[1]==".pc":
     
    247261                # at all.  This should only happend if the user
    248262                # modified the file or installed the package after
    249263                # initialize_pkgconfig_files had been initially run.
    250                 initialize_pkgconfig_file(filename)
     264                if OLD_SAGE_ROOT is None:
     265                    sys.stderr.write("Cannot find to the previous Sage root to update %s"%filename)
     266                else:
     267                    initialize_pkgconfig_file(filename, OLD_SAGE_ROOT_absolute=OLD_SAGE_ROOT)
     268                    #Since we've changed filename, we have to reload
     269                    #the config to make sure it is up to date
     270                    with open(filename) as file:
     271                        config = file.read()
    251272
    252273            # Delete all previous definitions of SAGE_ROOT:
    253274            config = def_pat.sub("", config)