Home | History | Annotate | Download | only in mac
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 2012 Google Inc. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 """
      8 Verifies that stripping works.
      9 """
     10 
     11 import TestGyp
     12 
     13 import re
     14 import subprocess
     15 import sys
     16 import time
     17 
     18 if sys.platform == 'darwin':
     19   test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
     20 
     21   test.run_gyp('test.gyp', chdir='strip')
     22 
     23   test.build('test.gyp', test.ALL, chdir='strip')
     24 
     25   # Lightweight check if stripping was done.
     26   def OutPath(s):
     27     return test.built_file_path(s, type=test.SHARED_LIB, chdir='strip')
     28 
     29   def CheckNsyms(p, n_expected):
     30     r = re.compile(r'nsyms\s+(\d+)')
     31     proc = subprocess.Popen(['otool', '-l', p], stdout=subprocess.PIPE)
     32     o = proc.communicate()[0]
     33     assert not proc.returncode
     34     m = r.search(o)
     35     n = int(m.group(1))
     36     if n != n_expected:
     37       print 'Stripping: Expected %d symbols, got %d' % (n_expected, n)
     38       test.fail_test()
     39 
     40   # The actual numbers here are not interesting, they just need to be the same
     41   # in both the xcode and the make build.
     42   CheckNsyms(OutPath('no_postprocess'), 10)
     43   CheckNsyms(OutPath('no_strip'), 10)
     44   CheckNsyms(OutPath('strip_all'), 0)
     45   CheckNsyms(OutPath('strip_nonglobal'), 2)
     46   CheckNsyms(OutPath('strip_debugging'), 2)
     47   CheckNsyms(OutPath('strip_all_custom_flags'), 0)
     48   CheckNsyms(test.built_file_path(
     49       'strip_all_bundle.framework/Versions/A/strip_all_bundle', chdir='strip'),
     50       0)
     51   CheckNsyms(OutPath('strip_save'), 2)
     52 
     53   test.pass_test()
     54