gyptest-archs.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. Tests things related to ARCHS.
  7. """
  8. import TestGyp
  9. import re
  10. import subprocess
  11. import sys
  12. if sys.platform == 'darwin':
  13. test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
  14. def GetStdout(cmdlist):
  15. proc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE)
  16. o = proc.communicate()[0].strip()
  17. assert not proc.returncode
  18. return o
  19. def CheckFileType(file, expected):
  20. o = GetStdout(['file', '-b', file])
  21. if not re.match(expected, o, re.DOTALL):
  22. print 'File: Expected %s, got %s' % (expected, o)
  23. test.fail_test()
  24. def XcodeVersion():
  25. xcode, build = GetStdout(['xcodebuild', '-version']).splitlines()
  26. xcode = xcode.split()[-1].replace('.', '')
  27. xcode = (xcode + '0' * (3 - len(xcode))).zfill(4)
  28. return xcode
  29. test.run_gyp('test-no-archs.gyp', chdir='archs')
  30. test.build('test-no-archs.gyp', test.ALL, chdir='archs')
  31. result_file = test.built_file_path('Test', chdir='archs')
  32. test.must_exist(result_file)
  33. if XcodeVersion() >= '0500':
  34. expected_type = '^Mach-O 64-bit executable x86_64$'
  35. else:
  36. expected_type = '^Mach-O executable i386$'
  37. CheckFileType(result_file, expected_type)
  38. test.run_gyp('test-archs-x86_64.gyp', chdir='archs')
  39. test.build('test-archs-x86_64.gyp', test.ALL, chdir='archs')
  40. result_file = test.built_file_path('Test64', chdir='archs')
  41. test.must_exist(result_file)
  42. CheckFileType(result_file, '^Mach-O 64-bit executable x86_64$')
  43. if test.format != 'make':
  44. # Build all targets except 'exe_32_64_no_sources' that does build
  45. # but should not cause error when generating ninja files
  46. targets = [
  47. 'static_32_64', 'shared_32_64', 'module_32_64', 'exe_32_64',
  48. 'exe_32_64_bundle', 'precompiled_prefix_header_mm_32_64',
  49. ]
  50. test.run_gyp('test-archs-multiarch.gyp', chdir='archs')
  51. for target in targets:
  52. test.build('test-archs-multiarch.gyp', target=target, chdir='archs')
  53. result_file = test.built_file_path(
  54. 'static_32_64', chdir='archs', type=test.STATIC_LIB)
  55. test.must_exist(result_file)
  56. CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
  57. '.*architecture i386.*architecture x86_64')
  58. result_file = test.built_file_path(
  59. 'shared_32_64', chdir='archs', type=test.SHARED_LIB)
  60. test.must_exist(result_file)
  61. CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
  62. '.*architecture i386.*architecture x86_64')
  63. result_file = test.built_file_path(
  64. 'exe_32_64', chdir='archs', type=test.EXECUTABLE)
  65. test.must_exist(result_file)
  66. CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
  67. '.*architecture i386.*architecture x86_64')
  68. result_file = test.built_file_path('Test App.app/Contents/MacOS/Test App',
  69. chdir='archs')
  70. test.must_exist(result_file)
  71. CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
  72. '.*architecture i386.*architecture x86_64')