Home | History | Annotate | Download | only in standalone-static-library
      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. The Android gyp
     18 # generator leaves both decisions to the Android build system, so this test
     19 # doesn't work for that format.
     20 test = TestGyp.TestGyp(formats=['!android'])
     21 
     22 # Verify that types other than static_library cause a failure.
     23 test.run_gyp('invalid.gyp', status=1, stderr=None)
     24 target_str = 'invalid.gyp:bad#target'
     25 err = ['gyp: Target %s has type executable but standalone_static_library flag '
     26        'is only valid for static_library type.' % target_str]
     27 test.must_contain_all_lines(test.stderr(), err)
     28 
     29 # Build a valid standalone_static_library.
     30 test.run_gyp('mylib.gyp')
     31 test.build('mylib.gyp', target='prog')
     32 
     33 # Verify that the static library is copied to the correct location.
     34 # We expect the library to be copied to $PRODUCT_DIR.
     35 standalone_static_library_dir = test.EXECUTABLE
     36 path_to_lib = os.path.split(
     37     test.built_file_path('mylib', type=standalone_static_library_dir))[0]
     38 lib_name = test.built_file_basename('mylib', type=test.STATIC_LIB)
     39 path = os.path.join(path_to_lib, lib_name)
     40 test.must_exist(path)
     41 
     42 # Verify that the program runs properly.
     43 expect = 'hello from mylib.c\n'
     44 test.run_built_executable('prog', stdout=expect)
     45 
     46 # Verify that libmylib.a contains symbols.  "ar -x" fails on a 'thin' archive.
     47 if test.format in ('make', 'ninja') and sys.platform.startswith('linux'):
     48   retcode = subprocess.call(['ar', '-x', path])
     49   assert retcode == 0
     50 
     51 test.pass_test()
     52