gyptest-lto.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. # Copyright (c) 2015 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 LTO flags work.
  7. """
  8. import TestGyp
  9. import os
  10. import re
  11. import subprocess
  12. import sys
  13. if sys.platform == 'darwin':
  14. test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
  15. CHDIR = 'lto'
  16. test.run_gyp('test.gyp', chdir=CHDIR)
  17. test.build('test.gyp', test.ALL, chdir=CHDIR)
  18. def ObjPath(srcpath, target):
  19. # TODO: Move this into TestGyp if it's needed elsewhere.
  20. if test.format == 'xcode':
  21. return os.path.join(CHDIR, 'build', 'test.build', 'Default',
  22. target + '.build', 'Objects-normal', 'x86_64',
  23. srcpath + '.o')
  24. elif 'ninja' in test.format: # ninja, xcode-ninja
  25. return os.path.join(CHDIR, 'out', 'Default', 'obj',
  26. target + '.' + srcpath + '.o')
  27. elif test.format == 'make':
  28. return os.path.join(CHDIR, 'out', 'Default', 'obj.target',
  29. target, srcpath + '.o')
  30. def ObjType(p, t_expected):
  31. r = re.compile(r'nsyms\s+(\d+)')
  32. o = subprocess.check_output(['file', p])
  33. objtype = 'unknown'
  34. if ': Mach-O ' in o:
  35. objtype = 'mach-o'
  36. elif ': LLVM bit-code ' in o:
  37. objtype = 'llvm'
  38. if objtype != t_expected:
  39. print 'Expected %s, got %s' % (t_expected, objtype)
  40. test.fail_test()
  41. ObjType(ObjPath('cfile', 'lto'), 'llvm')
  42. ObjType(ObjPath('ccfile', 'lto'), 'llvm')
  43. ObjType(ObjPath('mfile', 'lto'), 'llvm')
  44. ObjType(ObjPath('mmfile', 'lto'), 'llvm')
  45. ObjType(ObjPath('asmfile', 'lto'), 'mach-o')
  46. ObjType(ObjPath('cfile', 'lto_static'), 'llvm')
  47. ObjType(ObjPath('ccfile', 'lto_static'), 'llvm')
  48. ObjType(ObjPath('mfile', 'lto_static'), 'llvm')
  49. ObjType(ObjPath('mmfile', 'lto_static'), 'llvm')
  50. ObjType(ObjPath('asmfile', 'lto_static'), 'mach-o')
  51. test.pass_test()
  52. # TODO: Probably test for -object_path_lto too, else dsymutil won't be
  53. # useful maybe?