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