Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright (c) 2012 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 | """ |
| 8 | Verifies build of a static_library with the standalone_static_library flag set. |
| 9 | """ |
| 10 | |
| 11 | import os |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import TestGyp |
| 15 | |
| 16 | # standalone_static_library currently means two things: a specific output |
| 17 | # location for the built target and non-thin archive files. |
| 18 | test = TestGyp.TestGyp() |
| 19 | |
| 20 | # Verify that types other than static_library cause a failure. |
| 21 | test.run_gyp('invalid.gyp', status=1, stderr=None) |
| 22 | target_str = 'invalid.gyp:bad#target' |
| 23 | err = ['gyp: Target %s has type executable but standalone_static_library flag ' |
| 24 | 'is only valid for static_library type.' % target_str] |
| 25 | test.must_contain_all_lines(test.stderr(), err) |
| 26 | |
| 27 | # Build a valid standalone_static_library. |
| 28 | test.run_gyp('mylib.gyp') |
| 29 | test.build('mylib.gyp', target='prog') |
| 30 | |
| 31 | # Verify that the static library is copied to the correct location. |
| 32 | # We expect the library to be copied to $PRODUCT_DIR. |
| 33 | standalone_static_library_dir = test.EXECUTABLE |
| 34 | path_to_lib = os.path.split( |
| 35 | test.built_file_path('mylib', type=standalone_static_library_dir))[0] |
| 36 | lib_name = test.built_file_basename('mylib', type=test.STATIC_LIB) |
| 37 | path = os.path.join(path_to_lib, lib_name) |
| 38 | test.must_exist(path) |
| 39 | |
| 40 | # Verify that the program runs properly. |
| 41 | expect = 'hello from mylib.c\n' |
| 42 | test.run_built_executable('prog', stdout=expect) |
| 43 | |
| 44 | # Verify that libmylib.a contains symbols. "ar -x" fails on a 'thin' archive. |
| 45 | supports_thick = ('make', 'ninja', 'cmake') |
| 46 | if test.format in supports_thick and sys.platform.startswith('linux'): |
| 47 | retcode = subprocess.call(['ar', '-x', path]) |
| 48 | assert retcode == 0 |
| 49 | |
| 50 | test.pass_test() |