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"""
8Verifies that the default STRIP_STYLEs match between different generators.
9"""
10
11import TestGyp
12
13import re
14import subprocess
15import sys
16import time
17
18if 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"""\
49XXXXXXXX S _ci
50XXXXXXXX S _i
51XXXXXXXX T _the_function
52XXXXXXXX t _the_hidden_function
53XXXXXXXX T _the_used_function
54XXXXXXXX T _the_visible_function
55""")
56  CheckNsyms(OutPath('single_so.so'),
57"""\
58XXXXXXXX S _ci
59XXXXXXXX S _i
60XXXXXXXX T _the_function
61XXXXXXXX t _the_hidden_function
62XXXXXXXX T _the_used_function
63XXXXXXXX T _the_visible_function
64""")
65  CheckNsyms(OutPath('single_exe'),
66"""\
67XXXXXXXX T __mh_execute_header
68""")
69
70  CheckNsyms(test.built_file_path(
71      'bundle_dylib.framework/Versions/A/bundle_dylib', chdir=CHDIR),
72"""\
73XXXXXXXX S _ci
74XXXXXXXX S _i
75XXXXXXXX T _the_function
76XXXXXXXX t _the_hidden_function
77XXXXXXXX T _the_used_function
78XXXXXXXX T _the_visible_function
79""")
80  CheckNsyms(test.built_file_path(
81      'bundle_so.bundle/Contents/MacOS/bundle_so', chdir=CHDIR),
82"""\
83XXXXXXXX S _ci
84XXXXXXXX S _i
85XXXXXXXX T _the_function
86XXXXXXXX T _the_used_function
87XXXXXXXX T _the_visible_function
88""")
89  CheckNsyms(test.built_file_path(
90      'bundle_exe.app/Contents/MacOS/bundle_exe', chdir=CHDIR),
91"""\
92XXXXXXXX T __mh_execute_header
93""")
94
95  test.pass_test()
96