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 Verifies that app bundles are built correctly.
      9 """
     10 
     11 import TestGyp
     12 import TestMac
     13 
     14 import os
     15 import plistlib
     16 import subprocess
     17 import sys
     18 
     19 if sys.platform == 'darwin':
     20   print "This test is currently disabled: https://crbug.com/483696."
     21   sys.exit(0)
     22 
     23 def ExpectEq(expected, actual):
     24   if expected != actual:
     25     print >>sys.stderr, 'Expected "%s", got "%s"' % (expected, actual)
     26     test.fail_test()
     27 
     28 def ls(path):
     29   '''Returns a list of all files in a directory, relative to the directory.'''
     30   result = []
     31   for dirpath, _, files in os.walk(path):
     32     for f in files:
     33       result.append(os.path.join(dirpath, f)[len(path) + 1:])
     34   return result
     35 
     36 # Xcode supports for assets catalog was introduced in Xcode 6.0
     37 if sys.platform == 'darwin' and TestMac.Xcode.Version() >= '0600':
     38   test_gyp_path = 'test-assets-catalog.gyp'
     39   test_app_path = 'Test App Assets Catalog Gyp.app'
     40 
     41   test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
     42   test.run_gyp(test_gyp_path, chdir='app-bundle')
     43   test.build(test_gyp_path, test.ALL, chdir='app-bundle')
     44 
     45   # Binary
     46   test.built_file_must_exist(
     47       os.path.join(test_app_path, 'Contents/MacOS/Test App Assets Catalog Gyp'),
     48       chdir='app-bundle')
     49 
     50   # Info.plist
     51   info_plist = test.built_file_path(
     52       os.path.join(test_app_path, 'Contents/Info.plist'),
     53       chdir='app-bundle')
     54   test.must_exist(info_plist)
     55   test.must_contain(
     56       info_plist,
     57       'com.google.Test-App-Assets-Catalog-Gyp')  # Variable expansion
     58   test.must_not_contain(info_plist, '${MACOSX_DEPLOYMENT_TARGET}');
     59 
     60   if test.format != 'make':
     61     # TODO: Synthesized plist entries aren't hooked up in the make generator.
     62     machine = subprocess.check_output(['sw_vers', '-buildVersion']).rstrip('\n')
     63     plist = plistlib.readPlist(info_plist)
     64     ExpectEq(machine, plist['BuildMachineOSBuild'])
     65 
     66     expected = ''
     67     version = TestMac.Xcode.SDKVersion()
     68     expected = 'macosx' + version
     69     ExpectEq(expected, plist['DTSDKName'])
     70     sdkbuild = TestMac.Xcode.SDKBuild()
     71     if not sdkbuild:
     72       # Above command doesn't work in Xcode 4.2.
     73       sdkbuild = plist['BuildMachineOSBuild']
     74     ExpectEq(sdkbuild, plist['DTSDKBuild'])
     75     ExpectEq(TestMac.Xcode.Version(), plist['DTXcode'])
     76     ExpectEq(TestMac.Xcode.Build(), plist['DTXcodeBuild'])
     77 
     78   # Resources
     79   strings_files = ['InfoPlist.strings', 'utf-16be.strings', 'utf-16le.strings']
     80   for f in strings_files:
     81     strings = test.built_file_path(
     82         os.path.join(test_app_path, 'Contents/Resources/English.lproj', f),
     83         chdir='app-bundle')
     84     test.must_exist(strings)
     85     # Xcodes writes UTF-16LE with BOM.
     86     contents = open(strings, 'rb').read()
     87     if not contents.startswith('\xff\xfe' + '/* Localized'.encode('utf-16le')):
     88       test.fail_test()
     89 
     90   test.built_file_must_exist(
     91       os.path.join(
     92           test_app_path, 'Contents/Resources/English.lproj/MainMenu.nib'),
     93       chdir='app-bundle')
     94 
     95   # make does not supports .xcassets files
     96   extra_content_files = []
     97   if test.format != 'make':
     98     extra_content_files = ['Contents/Resources/Assets.car']
     99     for f in extra_content_files:
    100       test.built_file_must_exist(
    101           os.path.join(test_app_path, f),
    102           chdir='app-bundle')
    103 
    104   # Packaging
    105   test.built_file_must_exist(
    106       os.path.join(test_app_path, 'Contents/PkgInfo'),
    107       chdir='app-bundle')
    108   test.built_file_must_match(
    109       os.path.join(test_app_path, 'Contents/PkgInfo'), 'APPLause',
    110       chdir='app-bundle')
    111 
    112   # Check that no other files get added to the bundle.
    113   if set(ls(test.built_file_path(test_app_path, chdir='app-bundle'))) != \
    114      set(['Contents/MacOS/Test App Assets Catalog Gyp',
    115           'Contents/Info.plist',
    116           'Contents/Resources/English.lproj/MainMenu.nib',
    117           'Contents/PkgInfo',
    118           ] + extra_content_files +
    119          [os.path.join('Contents/Resources/English.lproj', f)
    120              for f in strings_files]):
    121     test.fail_test()
    122 
    123   test.pass_test()
    124