gyptest-strip.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 TestMac
  10. import re
  11. import subprocess
  12. import sys
  13. import time
  14. if sys.platform == 'darwin':
  15. test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
  16. test.run_gyp('test.gyp', chdir='strip')
  17. test.build('test.gyp', test.ALL, chdir='strip')
  18. # Lightweight check if stripping was done.
  19. def OutPath(s):
  20. return test.built_file_path(s, type=test.SHARED_LIB, chdir='strip')
  21. def CheckNsyms(p, n_expected):
  22. r = re.compile(r'nsyms\s+(\d+)')
  23. o = subprocess.check_output(['otool', '-l', p])
  24. m = r.search(o)
  25. n = int(m.group(1))
  26. if n != n_expected:
  27. print 'Stripping: Expected %d symbols, got %d' % (n_expected, n)
  28. test.fail_test()
  29. # Starting with Xcode 5.0, clang adds an additional symbols to the compiled
  30. # file when using a relative path to the input file. So when using ninja
  31. # with Xcode 5.0 or higher, take this additional symbol into consideration
  32. # for unstripped builds (it is stripped by all strip commands).
  33. expected_extra_symbol_count = 0
  34. if test.format in ['ninja', 'xcode-ninja'] \
  35. and TestMac.Xcode.Version() >= '0500':
  36. expected_extra_symbol_count = 1
  37. # The actual numbers here are not interesting, they just need to be the same
  38. # in both the xcode and the make build.
  39. CheckNsyms(OutPath('no_postprocess'), 29 + expected_extra_symbol_count)
  40. CheckNsyms(OutPath('no_strip'), 29 + expected_extra_symbol_count)
  41. CheckNsyms(OutPath('strip_all'), 0)
  42. CheckNsyms(OutPath('strip_nonglobal'), 6)
  43. CheckNsyms(OutPath('strip_debugging'), 7)
  44. CheckNsyms(OutPath('strip_all_custom_flags'), 0)
  45. CheckNsyms(test.built_file_path(
  46. 'strip_all_bundle.framework/Versions/A/strip_all_bundle', chdir='strip'),
  47. 0)
  48. CheckNsyms(OutPath('strip_save'), 7)
  49. test.pass_test()