summaryrefslogtreecommitdiff
path: root/deps/gyp/test/mac/gyptest-app-assets-catalog.py
blob: ca76b513aa735e01c547b413007913e48fe536aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python

# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Verifies that app bundles are built correctly.
"""

import TestGyp
import TestMac

import os
import plistlib
import subprocess
import sys

if sys.platform == 'darwin':
  print "This test is currently disabled: https://crbug.com/483696."
  sys.exit(0)

def ExpectEq(expected, actual):
  if expected != actual:
    print >>sys.stderr, 'Expected "%s", got "%s"' % (expected, actual)
    test.fail_test()

def ls(path):
  '''Returns a list of all files in a directory, relative to the directory.'''
  result = []
  for dirpath, _, files in os.walk(path):
    for f in files:
      result.append(os.path.join(dirpath, f)[len(path) + 1:])
  return result

# Xcode supports for assets catalog was introduced in Xcode 6.0
if sys.platform == 'darwin' and TestMac.Xcode.Version() >= '0600':
  test_gyp_path = 'test-assets-catalog.gyp'
  test_app_path = 'Test App Assets Catalog Gyp.app'

  test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
  test.run_gyp(test_gyp_path, chdir='app-bundle')
  test.build(test_gyp_path, test.ALL, chdir='app-bundle')

  # Binary
  test.built_file_must_exist(
      os.path.join(test_app_path, 'Contents/MacOS/Test App Assets Catalog Gyp'),
      chdir='app-bundle')

  # Info.plist
  info_plist = test.built_file_path(
      os.path.join(test_app_path, 'Contents/Info.plist'),
      chdir='app-bundle')
  test.must_exist(info_plist)
  test.must_contain(
      info_plist,
      'com.google.Test-App-Assets-Catalog-Gyp')  # Variable expansion
  test.must_not_contain(info_plist, '${MACOSX_DEPLOYMENT_TARGET}');

  if test.format != 'make':
    # TODO: Synthesized plist entries aren't hooked up in the make generator.
    machine = subprocess.check_output(['sw_vers', '-buildVersion']).rstrip('\n')
    plist = plistlib.readPlist(info_plist)
    ExpectEq(machine, plist['BuildMachineOSBuild'])

    expected = ''
    version = TestMac.Xcode.SDKVersion()
    expected = 'macosx' + version
    ExpectEq(expected, plist['DTSDKName'])
    sdkbuild = TestMac.Xcode.SDKBuild()
    if not sdkbuild:
      # Above command doesn't work in Xcode 4.2.
      sdkbuild = plist['BuildMachineOSBuild']
    ExpectEq(sdkbuild, plist['DTSDKBuild'])
    ExpectEq(TestMac.Xcode.Version(), plist['DTXcode'])
    ExpectEq(TestMac.Xcode.Build(), plist['DTXcodeBuild'])

  # Resources
  strings_files = ['InfoPlist.strings', 'utf-16be.strings', 'utf-16le.strings']
  for f in strings_files:
    strings = test.built_file_path(
        os.path.join(test_app_path, 'Contents/Resources/English.lproj', f),
        chdir='app-bundle')
    test.must_exist(strings)
    # Xcodes writes UTF-16LE with BOM.
    contents = open(strings, 'rb').read()
    if not contents.startswith('\xff\xfe' + '/* Localized'.encode('utf-16le')):
      test.fail_test()

  test.built_file_must_exist(
      os.path.join(
          test_app_path, 'Contents/Resources/English.lproj/MainMenu.nib'),
      chdir='app-bundle')

  # make does not supports .xcassets files
  extra_content_files = []
  if test.format != 'make':
    extra_content_files = ['Contents/Resources/Assets.car']
    for f in extra_content_files:
      test.built_file_must_exist(
          os.path.join(test_app_path, f),
          chdir='app-bundle')

  # Packaging
  test.built_file_must_exist(
      os.path.join(test_app_path, 'Contents/PkgInfo'),
      chdir='app-bundle')
  test.built_file_must_match(
      os.path.join(test_app_path, 'Contents/PkgInfo'), 'APPLause',
      chdir='app-bundle')

  # Check that no other files get added to the bundle.
  if set(ls(test.built_file_path(test_app_path, chdir='app-bundle'))) != \
     set(['Contents/MacOS/Test App Assets Catalog Gyp',
          'Contents/Info.plist',
          'Contents/Resources/English.lproj/MainMenu.nib',
          'Contents/PkgInfo',
          ] + extra_content_files +
         [os.path.join('Contents/Resources/English.lproj', f)
             for f in strings_files]):
    test.fail_test()

  test.pass_test()