#11760: 'sage-location' shouldn't "initialize" .pc (pkg-config) files more than
once
-----------------------+----------------------------------------------------
   Reporter:  leif     |          Owner:                                        
         
       Type:  defect   |         Status:  needs_review                          
         
   Priority:  blocker  |      Milestone:  sage-4.7.2                            
         
  Component:  scripts  |       Keywords:  pkgconfig libpng Duplicate definition 
SAGE_ROOT
Work_issues:           |       Upstream:  N/A                                   
         
   Reviewer:           |         Author:  Leif Leonhardy                        
         
     Merged:           |   Dependencies:                                        
         
-----------------------+----------------------------------------------------

Comment(by leif):

 Replying to [comment:12 leif]:
 > P.S.: We could do similar in '''`update`'''`_pkgconfig_files()`.

 Like this, which IMHO is also somehow a bit cleaner:
 {{{
 #!diff

 diff --git a/sage-location b/sage-location
 --- a/sage-location
 +++ b/sage-location
 @@ -194,16 +207,17 @@
      ``initialize_pkgconfig_files()``, in particular, each of them
 contains a
      definition of the variable ``SAGE_ROOT``, since only that is updated
 here.
      """
 +    import re
 +    pat = re.compile(r"^SAGE_ROOT=.*\n", re.MULTILINE)
      LIB = os.path.join(os.path.abspath(SAGE_ROOT), 'local', 'lib')
      PKG = os.path.join(LIB, 'pkgconfig')
      for name in os.listdir(PKG):
 -        filename = os.path.join(PKG,name)
 +        filename = os.path.join(PKG, name)
          if os.path.splitext(filename)[1]==".pc":
              with open(filename) as file:
                  config = file.read()

 -            prefix_start = config.find('SAGE_ROOT=')
 -            if prefix_start==-1:
 +            if not pat.search(config):
                  # This should never happen, unless the user modified the
 file.
                  sys.stderr.write(
                      "Error: sage_location: update_pkgconfig_files():\n" +
 @@ -211,12 +225,16 @@
                      name + "  Skipping it...\n")
                  sys.stderr.flush()
                  continue
 +                # We could of course call
 initialize_pkgconfig_file(filename)
 +                # here instead to fix this issue, but unfortunately
 there's no
 +                # such function (for a single file) [yet].

 -            prefix_end = config.find('\n', prefix_start)
 -            new_prefix = 'SAGE_ROOT=%s' % os.path.abspath(SAGE_ROOT)
 -            new_config = config[:prefix_start] + new_prefix +
 config[prefix_end:]
 +            # Delete all previous definitions of SAGE_ROOT:
 +            config = pat.sub("", config)
 +
 +            definition = "SAGE_ROOT=%s\n" % os.path.abspath(SAGE_ROOT)
              with open(filename, 'w') as file:
 -                file.write(new_config)
 +                file.write(definition + config)


  def remove_files(path, remove_extensions):
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11760#comment:13>
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