gyptest-standalone-static-library.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 build of a static_library with the standalone_static_library flag set.
  7. """
  8. import os
  9. import subprocess
  10. import sys
  11. import TestGyp
  12. # standalone_static_library currently means two things: a specific output
  13. # location for the built target and non-thin archive files. The Android gyp
  14. # generator leaves both decisions to the Android build system, so this test
  15. # doesn't work for that format.
  16. test = TestGyp.TestGyp(formats=['!android'])
  17. # Verify that types other than static_library cause a failure.
  18. test.run_gyp('invalid.gyp', status=1, stderr=None)
  19. target_str = 'invalid.gyp:bad#target'
  20. err = ['gyp: Target %s has type executable but standalone_static_library flag '
  21. 'is only valid for static_library type.' % target_str]
  22. test.must_contain_all_lines(test.stderr(), err)
  23. # Build a valid standalone_static_library.
  24. test.run_gyp('mylib.gyp')
  25. test.build('mylib.gyp', target='prog')
  26. # Verify that the static library is copied to the correct location.
  27. # We expect the library to be copied to $PRODUCT_DIR.
  28. standalone_static_library_dir = test.EXECUTABLE
  29. path_to_lib = os.path.split(
  30. test.built_file_path('mylib', type=standalone_static_library_dir))[0]
  31. lib_name = test.built_file_basename('mylib', type=test.STATIC_LIB)
  32. path = os.path.join(path_to_lib, lib_name)
  33. test.must_exist(path)
  34. # Verify that the program runs properly.
  35. expect = 'hello from mylib.c\n'
  36. test.run_built_executable('prog', stdout=expect)
  37. # Verify that libmylib.a contains symbols. "ar -x" fails on a 'thin' archive.
  38. supports_thick = ('make', 'ninja', 'cmake')
  39. if test.format in supports_thick and sys.platform.startswith('linux'):
  40. retcode = subprocess.call(['ar', '-x', path])
  41. assert retcode == 0
  42. test.pass_test()