gyptest-app.py 3.9 KB

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