gyptest-strip.py 1.5 KB

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