Home | History | Annotate | Download | only in mac
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 2012 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 """
      8 Tests things related to ARCHS.
      9 """
     10 
     11 import TestGyp
     12 
     13 import re
     14 import subprocess
     15 import sys
     16 
     17 if sys.platform == 'darwin':
     18   test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
     19 
     20   def CheckFileType(file, expected):
     21     proc = subprocess.Popen(['file', '-b', file], stdout=subprocess.PIPE)
     22     o = proc.communicate()[0].strip()
     23     assert not proc.returncode
     24     if not re.match(expected, o, re.DOTALL):
     25       print 'File: Expected %s, got %s' % (expected, o)
     26       test.fail_test()
     27 
     28   test.run_gyp('test-no-archs.gyp', chdir='archs')
     29   test.build('test-no-archs.gyp', test.ALL, chdir='archs')
     30   result_file = test.built_file_path('Test', chdir='archs')
     31   test.must_exist(result_file)
     32   # FIXME: The default setting changed from i386 to x86_64 in Xcode 5.
     33   #CheckFileType(result_file, '^Mach-O executable i386')
     34 
     35   test.run_gyp('test-archs-x86_64.gyp', chdir='archs')
     36   test.build('test-archs-x86_64.gyp', test.ALL, chdir='archs')
     37   result_file = test.built_file_path('Test64', chdir='archs')
     38   test.must_exist(result_file)
     39   CheckFileType(result_file, '^Mach-O 64-bit executable x86_64$')
     40 
     41   if test.format != 'make':
     42     test.run_gyp('test-archs-multiarch.gyp', chdir='archs')
     43     test.build('test-archs-multiarch.gyp', test.ALL, chdir='archs')
     44 
     45     result_file = test.built_file_path(
     46         'static_32_64', chdir='archs', type=test.STATIC_LIB)
     47     test.must_exist(result_file)
     48     CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
     49                                '.*architecture i386.*architecture x86_64')
     50 
     51     result_file = test.built_file_path(
     52         'shared_32_64', chdir='archs', type=test.SHARED_LIB)
     53     test.must_exist(result_file)
     54     CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
     55                                '.*architecture i386.*architecture x86_64')
     56 
     57     result_file = test.built_file_path(
     58         'exe_32_64', chdir='archs', type=test.EXECUTABLE)
     59     test.must_exist(result_file)
     60     CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
     61                                '.*architecture i386.*architecture x86_64')
     62 
     63     result_file = test.built_file_path('Test App.app/Contents/MacOS/Test App',
     64                                        chdir='archs')
     65     test.must_exist(result_file)
     66     CheckFileType(result_file, 'Mach-O universal binary with 2 architectures'
     67                                '.*architecture i386.*architecture x86_64')
     68