Home | History | Annotate | Download | only in mac
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 2013 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 the default STRIP_STYLEs match between different generators.
      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   CHDIR='strip'
     22   test.run_gyp('test-defaults.gyp', chdir=CHDIR)
     23 
     24   test.build('test-defaults.gyp', test.ALL, chdir=CHDIR)
     25 
     26   # Lightweight check if stripping was done.
     27   def OutPath(s):
     28     return test.built_file_path(s, chdir=CHDIR)
     29 
     30   def CheckNsyms(p, o_expected):
     31     proc = subprocess.Popen(['nm', '-aU', p], stdout=subprocess.PIPE)
     32     o = proc.communicate()[0]
     33 
     34     # Filter out mysterious "00 0000   OPT radr://5614542" symbol which
     35     # is apparently only printed on the bots (older toolchain?).
     36     # Yes, "radr", not "rdar".
     37     o = ''.join(filter(lambda s: 'radr://5614542' not in s, o.splitlines(True)))
     38 
     39     o = o.replace('A', 'T')
     40     o = re.sub(r'^[a-fA-F0-9]+', 'XXXXXXXX', o, flags=re.MULTILINE)
     41     assert not proc.returncode
     42     if o != o_expected:
     43       print 'Stripping: Expected symbols """\n%s""", got """\n%s"""' % (
     44           o_expected, o)
     45       test.fail_test()
     46 
     47   CheckNsyms(OutPath('libsingle_dylib.dylib'),
     48 """\
     49 XXXXXXXX S _ci
     50 XXXXXXXX S _i
     51 XXXXXXXX T _the_function
     52 XXXXXXXX t _the_hidden_function
     53 XXXXXXXX T _the_used_function
     54 XXXXXXXX T _the_visible_function
     55 """)
     56   CheckNsyms(OutPath('single_so.so'),
     57 """\
     58 XXXXXXXX S _ci
     59 XXXXXXXX S _i
     60 XXXXXXXX T _the_function
     61 XXXXXXXX t _the_hidden_function
     62 XXXXXXXX T _the_used_function
     63 XXXXXXXX T _the_visible_function
     64 """)
     65   CheckNsyms(OutPath('single_exe'),
     66 """\
     67 XXXXXXXX T __mh_execute_header
     68 """)
     69 
     70   CheckNsyms(test.built_file_path(
     71       'bundle_dylib.framework/Versions/A/bundle_dylib', chdir=CHDIR),
     72 """\
     73 XXXXXXXX S _ci
     74 XXXXXXXX S _i
     75 XXXXXXXX T _the_function
     76 XXXXXXXX t _the_hidden_function
     77 XXXXXXXX T _the_used_function
     78 XXXXXXXX T _the_visible_function
     79 """)
     80   CheckNsyms(test.built_file_path(
     81       'bundle_so.bundle/Contents/MacOS/bundle_so', chdir=CHDIR),
     82 """\
     83 XXXXXXXX S _ci
     84 XXXXXXXX S _i
     85 XXXXXXXX T _the_function
     86 XXXXXXXX T _the_used_function
     87 XXXXXXXX T _the_visible_function
     88 """)
     89   CheckNsyms(test.built_file_path(
     90       'bundle_exe.app/Contents/MacOS/bundle_exe', chdir=CHDIR),
     91 """\
     92 XXXXXXXX T __mh_execute_header
     93 """)
     94 
     95   test.pass_test()
     96