• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3# Copyright (c) 2014 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 a swift framework builds correctly.
9"""
10
11import TestGyp
12import TestMac
13
14import collections
15import sys
16import subprocess
17
18if sys.platform == 'darwin':
19  print "This test is currently disabled: https://crbug.com/483696."
20  sys.exit(0)
21
22  test = TestGyp.TestGyp(formats=['xcode'])
23
24  # Ensures that the given symbol is present in the given file, by running nm.
25  def CheckHasSymbolName(path, symbol):
26    output = subprocess.check_output(['nm', '-j', path])
27    idx = output.find(symbol)
28    if idx == -1:
29      print 'Swift: Could not find symobl: %s' % symbol
30      test.fail_test()
31
32  test_cases = []
33
34  # Run this for iOS on XCode 6.0 or greater
35  if TestMac.Xcode.Version() >= '0600':
36    test_cases.append(('Default', 'iphoneos'))
37    test_cases.append(('Default', 'iphonesimulator'))
38
39  # Run it for Mac on XCode 6.1 or greater
40  if TestMac.Xcode.Version() >= '0610':
41    test_cases.append(('Default', None))
42
43  # Generate the project.
44  test.run_gyp('test.gyp', chdir='swift-library')
45
46  # Build and verify for each configuration.
47  for configuration, sdk in test_cases:
48    kwds = collections.defaultdict(list)
49    if test.format == 'xcode':
50      if sdk is not None:
51        kwds['arguments'].extend(['-sdk', sdk])
52
53    test.set_configuration(configuration)
54    test.build('test.gyp', 'SwiftFramework', chdir='swift-library', **kwds)
55
56    filename = 'SwiftFramework.framework/SwiftFramework'
57    result_file = test.built_file_path(filename, chdir='swift-library')
58
59    test.must_exist(result_file)
60
61    # Check to make sure that our swift class (GypSwiftTest) is present in the
62    # built binary
63    CheckHasSymbolName(result_file, "C14SwiftFramework12GypSwiftTest")
64
65  test.pass_test()
66