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