Ticket #13004: trac_x_fix_micro_release.patch

File trac_x_fix_micro_release.patch, 6.6 KB (added by vbraun, 10 years ago)

Initial patch

  • sage-micro_release

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1341317533 -3600
    # Node ID c2bbfb618e61fd4a5c57a337603ae02ba208b6d0
    # Parent  142179501ed7c2066ff09fcfc27e153e66f2050c
    Split sage-micro_release into a shell script that does the stripping
    and a python script that does all the rest.
    
    diff --git a/sage-micro_release b/sage-micro_release
    a b  
    1 #!/usr/bin/env python
     1#!/usr/bin/env bash
    22
    3 ########################################################################
    4 #       Copyright (C) 2011 William Stein <wstein@gmail.com>
     3# micro_release means delete everything that you only need to develop
     4#
     5# First, strip all binaries. Note that you must not strip Python libraries
     6# while Python is running! So the stripping is done in a shell script.
     7
     8
     9
     10#*****************************************************************************
     11#       Copyright (C) 2012 Volker Braun <vbraun.name@gmail.com>
    512#
    613#  Distributed under the terms of the GNU General Public License (GPL)
    714#
    815#                  http://www.gnu.org/licenses/
    9 ########################################################################
     16#*****************************************************************************
    1017
    11 """
    12 AUTHORS:
    13     - William Stein -- coding
    14     - Keshav Kini -- very significant design input
    15 """
     18# There is lots of cruft in $SAGE_LOCAL/lib since people think its a
     19# good idea to install html files there. Luckily strip will notice
     20# that and just thrown an error (which we ignore)
    1621
    17 DEBUG = False  # If True, prints everything that will happen, but does not actually do anything.
     22echo "Stripping all binaries, this might take a while..."
    1823
    19 import os, shutil, sys
     24find "$SAGE_LOCAL/bin" "$SAGE_LOCAL/lib" -type f -exec strip '{}' ';' |& grep -v "File format not recognized" | grep -v "File truncated" || true
    2025
    21 SAGE_ROOT = os.environ['SAGE_ROOT']
    2226
    23 def c(cmd, indent=0):
    24     print ' '*indent + cmd
    25     if DEBUG:
    26         return
    27     e = os.system(cmd)
    28     if e:
    29         print "Error executing command.  Failed with exit status %s."%e
    30         sys.exit(1)
    31 
    32 def strip_binaries():
    33     """
    34     Strip various binaries using the strip command to save some space.
    35     """
    36     print "Striping various binaries:"
    37     c('strip "%s"/local/bin/Singular-*'%SAGE_ROOT, 4)
    38     c('strip "%s"/local/bin/gfan'%SAGE_ROOT, 4)
    39 
    40 def strip_files_with_condition(path, condition, recursive=True):
    41     """
    42     Remove all files in the given path (and subdirectories if
    43     recursive is True) that satisfy the given condition.
    44     """
    45     for F in os.listdir(path):
    46         filename = os.path.join(path, F)
    47         if condition(F):
    48             c('strip "%s"'%filename)
    49         if recursive and os.path.isdir(filename):
    50             strip_files_with_condition(filename, condition, recursive=True)
    51 
    52 def strip_local_lib_so():
    53     print "Stripping .so files in local/lib"
    54     strip_files_with_condition('%s/local/lib/'%SAGE_ROOT, lambda F: F.endswith('.so'))
    55 
    56 def remove_paths_with_condition(path, ext, condition, recursive=True):
    57     """
    58     Remove all files in the given path (and subdirectories if
    59     recursive is True) that satisfy the given condition.
    60     """
    61     for F in os.listdir(path):
    62         filename = os.path.join(path, F)
    63         if condition(F):
    64             print "    removing %s"%filename
    65             if not DEBUG:
    66                 if os.path.isdir(filename):
    67                     shutil.rmtree(filename)
    68                 else:
    69                     os.unlink(filename)
    70         if recursive and os.path.isdir(filename):  # isdir checks that it still exists too
    71             remove_paths_with_condition(filename, ext, condition, recursive=True)
    72 
    73 def remove_paths_with_extension(path, ext, recursive=True):
    74     """
    75     Remove all files in the given path (and subdirectories if
    76     recursive is True) with the given extension.
    77     """
    78     if not ext.startswith('.'):
    79         ext = '.' + ext
    80     print "Removing %s files from %s%s:"%(ext, path, ' and all subdirectories' if recursive else '')
    81     remove_paths_with_condition(path, ext, lambda F: os.path.splitext(F)[1] == ext, recursive)
    82 
    83 def remove_paths_with_prefix(path, prefix, recursive=True):
    84     print "Removing files starting with %s from %s%s:"%(prefix, path, ' and all subdirectories' if recursive else '')
    85     remove_paths_with_condition(path, prefix, lambda F: F.startswith(prefix), recursive)
    86    
    87 def remove_dot_a_files():
    88     """
    89     Remove .a files from various places, since these are only needed
    90     for building, not for running Sage.
    91     """
    92     remove_paths_with_extension('%s/local/lib/'%SAGE_ROOT, 'a')
    93 
    94 def remove_sage_build_dir():
    95     build_dir = '%s/devel/sage/build/'%SAGE_ROOT
    96     remove_paths_with_prefix(build_dir, 'lib.', recursive=False)
    97     remove_paths_with_prefix(build_dir, 'temp.', recursive=False)
    98 
    99 def main():
    100     """
    101     Do all cleanups.
    102     """
    103     strip_local_lib_so()
    104     strip_binaries()
    105 
    106     # Removing .a files is potentially too intrusive, so we're turning
    107     # this off for now.  The problem is that it might break %cython
    108     # in the notebook, say.
    109     # remove_dot_a_files()
    110    
    111     remove_sage_build_dir()
    112    
    113 
    114 if __name__ == '__main__':
    115    main()
     27"$SAGE_LOCAL/bin/sage-micro_release.py"
  • (a) a/sage-micro_release vs. (b) b/sage-micro_release.py

    diff --git a/sage-micro_release b/sage-micro_release.py
    copy from sage-micro_release
    copy to sage-micro_release.py
    a b  
    2929        print "Error executing command.  Failed with exit status %s."%e
    3030        sys.exit(1)
    3131
    32 def strip_binaries():
    33     """
    34     Strip various binaries using the strip command to save some space.
    35     """
    36     print "Striping various binaries:"
    37     c('strip "%s"/local/bin/Singular-*'%SAGE_ROOT, 4)
    38     c('strip "%s"/local/bin/gfan'%SAGE_ROOT, 4)
    39 
    4032def strip_files_with_condition(path, condition, recursive=True):
    4133    """
    4234    Remove all files in the given path (and subdirectories if
     
    4941        if recursive and os.path.isdir(filename):
    5042            strip_files_with_condition(filename, condition, recursive=True)
    5143
    52 def strip_local_lib_so():
    53     print "Stripping .so files in local/lib"
    54     strip_files_with_condition('%s/local/lib/'%SAGE_ROOT, lambda F: F.endswith('.so'))
    55 
    5644def remove_paths_with_condition(path, ext, condition, recursive=True):
    5745    """
    5846    Remove all files in the given path (and subdirectories if
     
    10088    """
    10189    Do all cleanups.
    10290    """
    103     strip_local_lib_so()
    104     strip_binaries()
    105 
    10691    # Removing .a files is potentially too intrusive, so we're turning
    10792    # this off for now.  The problem is that it might break %cython
    10893    # in the notebook, say.