gyptest-swift-library.py 1.8 KB

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