| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2012 Google Inc. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """ | 7 """ |
| 8 Verifies build of a static_library with the standalone_static_library flag set. | 8 Verifies build of a static_library with the standalone_static_library flag set. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import os | 11 import os |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import TestGyp | 14 import TestGyp |
| 15 | 15 |
| 16 # standalone_static_library currently means two things: a specific output | 16 # standalone_static_library currently means two things: a specific output |
| 17 # location for the built target and non-thin archive files. The Android gyp | 17 # location for the built target and non-thin archive files. The Android gyp |
| 18 # generator leaves both decisions to the Android build system, so this test | 18 # generator leaves both decisions to the Android build system, so this test |
| 19 # doesn't work for that format. | 19 # doesn't work for that format. |
| 20 test = TestGyp.TestGyp(formats=['!android']) | 20 test = TestGyp.TestGyp(formats=['!android']) |
| 21 | 21 |
| 22 # Verify that types other than static_library cause a failure. | 22 # Verify that types other than static_library cause a failure. |
| 23 test.run_gyp('invalid.gyp', status=1, stderr=None) | 23 test.run_gyp('invalid.gyp', status=1, stderr=None) |
| 24 target_str = 'invalid.gyp:bad#target' | 24 target_str = 'invalid.gyp:bad#target' |
| 25 if test.format == 'scons': | |
| 26 target_str = os.path.join(os.path.realpath(os.curdir), target_str) | |
| 27 err = ['gyp: Target %s has type executable but standalone_static_library flag ' | 25 err = ['gyp: Target %s has type executable but standalone_static_library flag ' |
| 28 'is only valid for static_library type.' % target_str] | 26 'is only valid for static_library type.' % target_str] |
| 29 test.must_contain_all_lines(test.stderr(), err) | 27 test.must_contain_all_lines(test.stderr(), err) |
| 30 | 28 |
| 31 # Build a valid standalone_static_library. | 29 # Build a valid standalone_static_library. |
| 32 test.run_gyp('mylib.gyp') | 30 test.run_gyp('mylib.gyp') |
| 33 test.build('mylib.gyp', target='prog') | 31 test.build('mylib.gyp', target='prog') |
| 34 | 32 |
| 35 # Verify that the static library is copied to the correct location. | 33 # Verify that the static library is copied to the correct location. |
| 36 if test.format == 'scons': | 34 # We expect the library to be copied to $PRODUCT_DIR. |
| 37 # For scons, we expect the library to be copied to the shared lib dir. | 35 standalone_static_library_dir = test.EXECUTABLE |
| 38 standalone_static_library_dir = test.SHARED_LIB | |
| 39 else: | |
| 40 # Otherwise, we expect the library to be copied to $PRODUCT_DIR. | |
| 41 standalone_static_library_dir = test.EXECUTABLE | |
| 42 path_to_lib = os.path.split( | 36 path_to_lib = os.path.split( |
| 43 test.built_file_path('mylib', type=standalone_static_library_dir))[0] | 37 test.built_file_path('mylib', type=standalone_static_library_dir))[0] |
| 44 lib_name = test.built_file_basename('mylib', type=test.STATIC_LIB) | 38 lib_name = test.built_file_basename('mylib', type=test.STATIC_LIB) |
| 45 path = os.path.join(path_to_lib, lib_name) | 39 path = os.path.join(path_to_lib, lib_name) |
| 46 test.must_exist(path) | 40 test.must_exist(path) |
| 47 | 41 |
| 48 # Verify that the program runs properly. | 42 # Verify that the program runs properly. |
| 49 expect = 'hello from mylib.c\n' | 43 expect = 'hello from mylib.c\n' |
| 50 test.run_built_executable('prog', stdout=expect) | 44 test.run_built_executable('prog', stdout=expect) |
| 51 | 45 |
| 52 # Verify that libmylib.a contains symbols. "ar -x" fails on a 'thin' archive. | 46 # Verify that libmylib.a contains symbols. "ar -x" fails on a 'thin' archive. |
| 53 if test.format in ('make', 'ninja') and sys.platform.startswith('linux'): | 47 if test.format in ('make', 'ninja') and sys.platform.startswith('linux'): |
| 54 retcode = subprocess.call(['ar', '-x', path]) | 48 retcode = subprocess.call(['ar', '-x', path]) |
| 55 assert retcode == 0 | 49 assert retcode == 0 |
| 56 | 50 |
| 57 test.pass_test() | 51 test.pass_test() |
| OLD | NEW |